Skip to content

Commit 410c2ab

Browse files
committed
Reverted GPRS init to SAPBR as CSTT does not set bearer settings
Revert most of the changed done with c903441
1 parent 0745b29 commit 410c2ab

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/SIM808.Gprs.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
#include "SIM808.h"
22

3-
AT_COMMAND(SET_BEARER_SETTING_CONTYPE_GPRS, "+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
3+
AT_COMMAND(SET_BEARER_SETTING_PARAMETER, "+SAPBR=3,1,\"%S\",\"%s\"");
44
AT_COMMAND(SET_BEARER_SETTING, "+SAPBR=%d,%d");
5-
AT_COMMAND(GPRS_START_TASK, "+CSTT=\"%s\",\"%s\",\"%s\"");
65
AT_COMMAND(GPRS_ATTACH, "+CGATT=%d");
76

7+
AT_COMMAND_PARAMETER(BEARER, CONTYPE);
8+
AT_COMMAND_PARAMETER(BEARER, APN);
9+
AT_COMMAND_PARAMETER(BEARER, USER);
10+
AT_COMMAND_PARAMETER(BEARER, PWD);
11+
12+
TOKEN_TEXT(GPRS, "GPRS");
813
TOKEN_TEXT(CGATT, "+CGATT");
914
TOKEN_TEXT(CIPSHUT, "+CIPSHUT");
1015
TOKEN_TEXT(SHUT_OK, "SHUT OK");
1116
TOKEN_TEXT(CGREG, "+CGREG");
1217

18+
bool SIM808::setBearerSetting(ATConstStr parameter, const char* value)
19+
{
20+
sendFormatAT(TO_F(AT_COMMAND_SET_BEARER_SETTING_PARAMETER), parameter, value);
21+
return waitResponse() == 0;
22+
}
23+
1324
bool SIM808::getGprsPowerState(bool *state)
1425
{
1526
uint8_t result;
@@ -27,14 +38,19 @@ bool SIM808::getGprsPowerState(bool *state)
2738

2839
bool SIM808::enableGprs(const char *apn, const char* user = NULL, const char *password = NULL)
2940
{
41+
char gprsToken[5];
42+
strcpy_P(gprsToken, TOKEN_GPRS);
43+
3044
return
3145
(sendAT(TO_F(TOKEN_CIPSHUT)), waitResponse(65000L, TO_F(TOKEN_SHUT_OK)) == 0) && //AT+CIPSHUT
3246
(sendFormatAT(TO_F(AT_COMMAND_GPRS_ATTACH), 1), waitResponse(10000L) == 0) && //AT+CGATT=1
3347

34-
(sendFormatAT(TO_F(AT_COMMAND_SET_BEARER_SETTING), 0, 1), waitResponse(65000L) != -1) && //AT+SAPBR=0,1
35-
(sendAT(TO_F(AT_COMMAND_SET_BEARER_SETTING_CONTYPE_GPRS)), waitResponse() == 0) && //AT+SAPBR=3,1,"CONTYPE","GPRS"
48+
(setBearerSetting(TO_F(AT_COMMAND_PARAMETER_BEARER_CONTYPE), gprsToken)) && //AT+SAPBR=3,1,"CONTYPE","GPRS"
49+
50+
(setBearerSetting(TO_F(AT_COMMAND_PARAMETER_BEARER_APN), apn)) && //AT+SAPBR=3,1,"APN","xxx"
51+
(user == NULL || setBearerSetting(TO_F(AT_COMMAND_PARAMETER_BEARER_USER), user)) && //AT+SAPBR=3,1,"USER","xxx"
52+
(password == NULL || setBearerSetting(TO_F(AT_COMMAND_PARAMETER_BEARER_PWD), password)) && //AT+SAPBR=3,1,"PWD","xxx"
3653

37-
(sendFormatAT(TO_F(AT_COMMAND_GPRS_START_TASK), apn, user, password), waitResponse() == 0) && //AT+CSTT="apn","user","password"
3854
(sendFormatAT(TO_F(AT_COMMAND_SET_BEARER_SETTING), 1, 1), waitResponse(65000L) == 0); //AT+SAPBR=1,1
3955
}
4056

src/SIM808.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class SIM808 : public SIMComAT
4646
* Terminate the HTTP service.
4747
*/
4848
bool httpEnd();
49+
/**
50+
* Set one of the bearer settings for application based on IP.
51+
*/
52+
bool setBearerSetting(ATConstStr parameter, const char* value);
4953

5054
public:
5155
SIM808(uint8_t resetPin, uint8_t pwrKeyPin, uint8_t statusPin);

0 commit comments

Comments
 (0)