Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit dc7c2d8

Browse files
authored
Merge pull request #45 from ostaquet/feature/apn_user_pass
Add support for APN username & password during setup of GPRS
2 parents aafcb65 + dcfe7ee commit dc7c2d8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/SIM800L.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const char AT_CMD_CFUN4[] PROGMEM = "AT+CFUN=4"; //
4848
const char AT_CMD_CREG_TEST[] PROGMEM = "AT+CREG?"; // Check the network registration status
4949
const char AT_CMD_SAPBR_GPRS[] PROGMEM = "AT+SAPBR=3,1,\"Contype\",\"GPRS\""; // Configure the GPRS bearer
5050
const char AT_CMD_SAPBR_APN[] PROGMEM = "AT+SAPBR=3,1,\"APN\","; // Configure the APN for the GPRS
51+
const char AT_CMD_SAPBR_USER[] PROGMEM = "AT+SAPBR=3,1,\"USER\","; // Configure the USER for the GPRS (linked to APN)
52+
const char AT_CMD_SAPBR_PWD[] PROGMEM = "AT+SAPBR=3,1,\"PWD\","; // Configure the PWD for the GPRS (linked to APN)
5153
const char AT_CMD_SAPBR1[] PROGMEM = "AT+SAPBR=1,1"; // Connect GPRS
5254
const char AT_CMD_SAPBR0[] PROGMEM = "AT+SAPBR=0,1"; // Disconnect GPRS
5355

@@ -639,6 +641,34 @@ bool SIM800L::setupGPRS(const char* apn) {
639641
return readResponseCheckAnswer_P(20000, AT_RSP_OK);
640642
}
641643

644+
/**
645+
* Setup the GPRS connectivity with user and password
646+
* As input, give the APN string of the operator, the user and the password
647+
*/
648+
bool SIM800L::setupGPRS(const char* apn, const char* user, const char* password) {
649+
// Prepare the GPRS connection as the bearer
650+
sendCommand_P(AT_CMD_SAPBR_GPRS);
651+
if(!readResponseCheckAnswer_P(20000, AT_RSP_OK)) {
652+
return false;
653+
}
654+
655+
// Set the config of the bearer with the APN
656+
sendCommand_P(AT_CMD_SAPBR_APN, apn);
657+
if(!readResponseCheckAnswer_P(20000, AT_RSP_OK)) {
658+
return false;
659+
}
660+
661+
// Set the config of the bearer with the USER
662+
sendCommand_P(AT_CMD_SAPBR_USER, user);
663+
if(!readResponseCheckAnswer_P(20000, AT_RSP_OK)) {
664+
return false;
665+
}
666+
667+
// Set the config of the bearer with the PWD
668+
sendCommand_P(AT_CMD_SAPBR_PWD, password);
669+
return readResponseCheckAnswer_P(20000, AT_RSP_OK);
670+
}
671+
642672
/**
643673
* Open the GPRS connectivity
644674
*/

src/SIM800L.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class SIM800L {
6969

7070
// Enable/disable GPRS
7171
bool setupGPRS(const char *apn);
72+
bool setupGPRS(const char *apn, const char *user, const char *password);
7273
bool connectGPRS();
7374
bool disconnectGPRS();
7475

0 commit comments

Comments
 (0)