From e1c9c2517bf26389dda348c4eee4542f622f5a1f Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Thu, 23 Jul 2020 15:06:22 -0400 Subject: [PATCH] Deactivate contexts on Monarch Signed-off-by: Sara Damiano --- .gitignore | 1 + src/TinyGsmClientSIM800.h | 8 +++----- src/TinyGsmClientSequansMonarch.h | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index b5e30af..bfad8b1 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ extra_envs.ini lib/readme.txt include/readme.txt .atomrc.cson +.history # VSCode .vscode/* diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 2b4bd55..ebf6bc9 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -383,7 +383,7 @@ class TinyGsmSim800 : public TinyGsmModem, sendAT(GF("+CIPSHUT")); if (waitResponse(60000L) != 1) { return false; } - sendAT(GF("+CGATT=0")); // Deactivate the bearer context + sendAT(GF("+CGATT=0")); // Detach from GPRS if (waitResponse(60000L) != 1) { return false; } return true; @@ -396,9 +396,7 @@ class TinyGsmSim800 : public TinyGsmModem, // May not return the "+CCID" before the number String getSimCCIDImpl() { sendAT(GF("+CCID")); - if (waitResponse(GF(GSM_NL)) != 1) { - return ""; - } + if (waitResponse(GF(GSM_NL)) != 1) { return ""; } String res = stream.readStringUntil('\n'); waitResponse(); // Trim out the CCID header in case it is there @@ -739,7 +737,7 @@ class TinyGsmSim800 : public TinyGsmModem, } public: - Stream& stream; + Stream& stream; protected: GsmClientSim800* sockets[TINY_GSM_MUX_COUNT]; diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index d346343..0caff1c 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -367,8 +367,12 @@ class TinyGsmSequansMonarch } bool gprsDisconnectImpl() { + // Detach from PS network sendAT(GF("+CGATT=0")); if (waitResponse(60000L) != 1) { return false; } + // Dectivate all PDP contexts + sendAT(GF("+CGACT=0")); + if (waitResponse(60000L) != 1) { return false; } return true; } @@ -572,9 +576,7 @@ class TinyGsmSequansMonarch // six possible sockets. sendAT(GF("+SQNSS")); for (int muxNo = 1; muxNo <= TINY_GSM_MUX_COUNT; muxNo++) { - if (waitResponse(GFP(GSM_OK), GF(GSM_NL "+SQNSS: ")) != 2) { - break; - } + if (waitResponse(GFP(GSM_OK), GF(GSM_NL "+SQNSS: ")) != 2) { break; } uint8_t status = 0; // if (streamGetIntBefore(',') != muxNo) { // check the mux no // DBG("### Warning: misaligned mux numbers!"); @@ -593,9 +595,9 @@ class TinyGsmSequansMonarch // SOCK_OPENING = 6, GsmClientSequansMonarch* sock = sockets[mux % TINY_GSM_MUX_COUNT]; if (sock) { - sock->sock_connected = - ((status != SOCK_CLOSED) && (status != SOCK_INCOMING) && - (status != SOCK_OPENING)); + sock->sock_connected = ((status != SOCK_CLOSED) && + (status != SOCK_INCOMING) && + (status != SOCK_OPENING)); } } waitResponse(); // Should be an OK at the end @@ -624,7 +626,7 @@ class TinyGsmSequansMonarch String r5s(r5); r5s.trim(); DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/ data.reserve(64); - uint8_t index = 0; + uint8_t index = 0; uint32_t startMillis = millis(); do { TINY_GSM_YIELD(); @@ -654,11 +656,11 @@ class TinyGsmSequansMonarch index = 5; goto finish; } else if (data.endsWith(GF(GSM_NL "+SQNSRING:"))) { - int8_t mux = streamGetIntBefore(','); + int8_t mux = streamGetIntBefore(','); int16_t len = streamGetIntBefore('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux % TINY_GSM_MUX_COUNT]) { - sockets[mux % TINY_GSM_MUX_COUNT]->got_data = true; + sockets[mux % TINY_GSM_MUX_COUNT]->got_data = true; sockets[mux % TINY_GSM_MUX_COUNT]->sock_available = len; } data = ""; @@ -677,9 +679,7 @@ class TinyGsmSequansMonarch finish: if (!index) { data.trim(); - if (data.length()) { - DBG("### Unhandled:", data); - } + if (data.length()) { DBG("### Unhandled:", data); } data = ""; } // data.replace(GSM_NL, "/"); @@ -717,7 +717,7 @@ class TinyGsmSequansMonarch protected: GsmClientSequansMonarch* sockets[TINY_GSM_MUX_COUNT]; - const char* gsmNL = GSM_NL; + const char* gsmNL = GSM_NL; }; #endif // SRC_TINYGSMCLIENTSEQUANSMONARCH_H_