From d4d63dabe7b951d6459c28ed772218ac1a403b66 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 17 Jul 2019 13:56:45 -0400 Subject: [PATCH] Using PDP commands --- src/TinyGsmClientSIM5360.h | 57 ++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index 8a5f153..0f0a2e5 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -359,47 +359,56 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } - // Actually open the packet network - // NOTE: AT command manual hints this might be depricated or other options preferred - // but all application notes use it - sendAT(GF("+NETOPEN")); - if (waitResponse(60000L) != 1) { + sendAT(GF("+CGATT=1")); // attach to GPRS + if (waitResponse(360000L) != 1) { return false; } - /* - sendAT(GF("+CGATT=1")); // attach to GPRS - if (waitResponse(360000L) != 1) { - return false; - } + // Using CGDCONT sets up an "external" PCP context, i.e. a data connection + // using the external IP stack (e.g. Windows dial up) and PPP link over the + // serial interface. Is this preferred? - // Using CGDCONT sets up an "external" PCP context, i.e. a data connection - // using the external IP stack (e.g. Windows dial up) and PPP link over the - // serial interface. Is this preferred? + if (user && strlen(user) > 0) { + sendAT(GF("+CGAUTH=1,0,\""), user, GF("\",\""), pwd, '"'); // Set the authentication + waitResponse(); + } - if (user && strlen(user) > 0) { - sendAT(GF("+CGAUTH=1,0,\""), user, GF("\",\""), pwd, '"'); // Set the authentication - waitResponse(); - } + sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); // Define PDP context 1 + waitResponse(); - sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); // Define PDP context 1 - waitResponse(); + sendAT(GF("+CGACT=1,1")); // activate PDP profile/context 1 + if (waitResponse(75000L) != 1) { + return false; + } - sendAT(GF("+CGACT=1,1")); // activate PDP profile/context 1 - if (waitResponse(150000L) != 1) { - return false; - } - */ + // Actually open network socket + // NOTE: AT command manual hints this might be depricated or other options preferred + // but all application notes use it (and nothing states what *IS* preferred) + sendAT(GF("+NETOPEN")); + if (waitResponse(75000L) != 1) { + return false; + } return true; } bool gprsDisconnect() { + // Close the network (note, all sockets should be closed first) sendAT(GF("+NETCLOSE")); if (waitResponse(60000L) != 1) return false; + sendAT(GF("+CGACT=1,0")); // Deactivate PDP context 1 + if (waitResponse(40000L) != 1) { + return false; + } + + sendAT(GF("+CGATT=0")); // detach from GPRS + if (waitResponse(360000L) != 1) { + return false; + } + return true; }