From 4f9d28403067a96741a0c32c0f6592610c2257a2 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 14 May 2021 14:17:37 -0400 Subject: [PATCH] remove sapbr commands from 7000SSL Signed-off-by: Sara Damiano --- src/TinyGsmClientSIM7000SSL.h | 68 +++++++++-------------------------- src/TinyGsmClientSIM7080.h | 38 ++++++++------------ 2 files changed, 32 insertions(+), 74 deletions(-) diff --git a/src/TinyGsmClientSIM7000SSL.h b/src/TinyGsmClientSIM7000SSL.h index 512dcb6..357a98e 100644 --- a/src/TinyGsmClientSIM7000SSL.h +++ b/src/TinyGsmClientSIM7000SSL.h @@ -93,7 +93,8 @@ class TinyGsmSim7000SSL public: GsmClientSecureSIM7000SSL() {} - GsmClientSecureSIM7000SSL(TinyGsmSim7000SSL& modem, uint8_t mux = 0) + explicit GsmClientSecureSIM7000SSL(TinyGsmSim7000SSL& modem, + uint8_t mux = 0) : GsmClientSim7000SSL(modem, mux) {} public: @@ -101,7 +102,8 @@ class TinyGsmSim7000SSL return at->setCertificate(certificateName, mux); } - int connect(const char* host, uint16_t port, int timeout_s) { + virtual int connect(const char* host, uint16_t port, + int timeout_s) override { stop(); TINY_GSM_YIELD(); rx.clear(); @@ -217,26 +219,6 @@ class TinyGsmSim7000SSL const char* pwd = NULL) { gprsDisconnect(); - // Bearer settings for applications based on IP - // Set the connection type to GPRS - sendAT(GF("+SAPBR=3,1,\"Contype\",\"GPRS\"")); - waitResponse(); - - // Set the APN - sendAT(GF("+SAPBR=3,1,\"APN\",\""), apn, '"'); - waitResponse(); - - // Set the user name - if (user && strlen(user) > 0) { - sendAT(GF("+SAPBR=3,1,\"USER\",\""), user, '"'); - waitResponse(); - } - // Set the password - if (pwd && strlen(pwd) > 0) { - sendAT(GF("+SAPBR=3,1,\"PWD\",\""), pwd, '"'); - waitResponse(); - } - // Define the PDP context sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); waitResponse(); @@ -249,13 +231,6 @@ class TinyGsmSim7000SSL // For who only knows what reason, doing so screws up the rest of the // process - // Open the definied GPRS bearer context - sendAT(GF("+SAPBR=1,1")); - waitResponse(85000L); - // Query the GPRS bearer context status - sendAT(GF("+SAPBR=2,1")); - if (waitResponse(30000L) != 1) { return false; } - // Bearer settings for applications based on IP // Set the user name and password // AT+CNCFG=[,[,,[,]]] @@ -286,17 +261,17 @@ class TinyGsmSim7000SSL // 0: Deactive // 1: Active // 2: Auto Active - int res = 0; - int ntries = 0; - while (res != 1 && ntries < 5) { + bool res = false; + int ntries = 0; + while (!res && ntries < 5) { sendAT(GF("+CNACT=1,\""), apn, GF("\"")); res = waitResponse(60000L, GF(GSM_NL "+APP PDP: ACTIVE"), - GF(GSM_NL "+APP PDP: DEACTIVE")); + GF(GSM_NL "+APP PDP: DEACTIVE")) == 1; waitResponse(); ntries++; } - return res == 1; + return res; } bool gprsDisconnectImpl() { @@ -527,8 +502,8 @@ class TinyGsmSim7000SSL // we need to fill in the missing muxes if (ret_mux > muxNo) { for (int extra_mux = muxNo; extra_mux < ret_mux; extra_mux++) { - GsmClientSim7000SSL* sock = sockets[extra_mux]; - if (sock) { sock->sock_available = 0; } + GsmClientSim7000SSL* isock = sockets[extra_mux]; + if (isock) { isock->sock_available = 0; } } muxNo = ret_mux; } @@ -537,8 +512,8 @@ class TinyGsmSim7000SSL // so we set any we haven't gotten to yet to 0 for (int extra_mux = muxNo; extra_mux < TINY_GSM_MUX_COUNT; extra_mux++) { - GsmClientSim7000SSL* sock = sockets[extra_mux]; - if (sock) { sock->sock_available = 0; } + GsmClientSim7000SSL* isock = sockets[extra_mux]; + if (isock) { isock->sock_available = 0; } } break; } else { @@ -577,8 +552,8 @@ class TinyGsmSim7000SSL // we need to fill in the missing muxes if (ret_mux > muxNo) { for (int extra_mux = muxNo; extra_mux < ret_mux; extra_mux++) { - GsmClientSim7000SSL* sock = sockets[extra_mux]; - if (sock) { sock->sock_connected = false; } + GsmClientSim7000SSL* isock = sockets[extra_mux]; + if (isock) { isock->sock_connected = false; } } muxNo = ret_mux; } @@ -587,8 +562,8 @@ class TinyGsmSim7000SSL // so we set any we haven't gotten to yet to 0 for (int extra_mux = muxNo; extra_mux < TINY_GSM_MUX_COUNT; extra_mux++) { - GsmClientSim7000SSL* sock = sockets[extra_mux]; - if (sock) { sock->sock_connected = false; } + GsmClientSim7000SSL* isock = sockets[extra_mux]; + if (isock) { isock->sock_connected = false; } } break; } else { @@ -680,15 +655,6 @@ class TinyGsmSim7000SSL } } data = ""; - } else if (data.endsWith(GF("CLOSED" GSM_NL))) { - int8_t nl = data.lastIndexOf(GSM_NL, data.length() - 8); - int8_t coma = data.indexOf(',', nl + 2); - int8_t mux = data.substring(nl + 2, coma).toInt(); - if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { - sockets[mux]->sock_connected = false; - } - data = ""; - DBG("### Closed: ", mux); } else if (data.endsWith(GF("*PSNWID:"))) { streamSkipUntil('\n'); // Refresh network name by network data = ""; diff --git a/src/TinyGsmClientSIM7080.h b/src/TinyGsmClientSIM7080.h index 394bddc..b54db22 100644 --- a/src/TinyGsmClientSIM7080.h +++ b/src/TinyGsmClientSIM7080.h @@ -92,7 +92,7 @@ class TinyGsmSim7080 : public TinyGsmSim70xx, public: GsmClientSecureSIM7080() {} - GsmClientSecureSIM7080(TinyGsmSim7080& modem, uint8_t mux = 0) + explicit GsmClientSecureSIM7080(TinyGsmSim7080& modem, uint8_t mux = 0) : GsmClientSim7080(modem, mux) {} public: @@ -100,7 +100,8 @@ class TinyGsmSim7080 : public TinyGsmSim70xx, return at->setCertificate(certificateName, mux); } - int connect(const char* host, uint16_t port, int timeout_s) { + virtual int connect(const char* host, uint16_t port, + int timeout_s) override { stop(); TINY_GSM_YIELD(); rx.clear(); @@ -265,9 +266,9 @@ class TinyGsmSim7080 : public TinyGsmSim70xx, // 0: Deactive // 1: Active // 2: Auto Active - int res = 0; - int ntries = 0; - while (res != 1 && ntries < 5) { + bool res = false; + int ntries = 0; + while (!res && ntries < 5) { sendAT(GF("+CNACT=0,1")); res = waitResponse(60000L, GF(GSM_NL "+APP PDP: 0,ACTIVE"), GF(GSM_NL "+APP PDP: 0,DEACTIVE")); @@ -275,7 +276,7 @@ class TinyGsmSim7080 : public TinyGsmSim70xx, ntries++; } - return res == 1; + return res; } bool gprsDisconnectImpl() { @@ -504,8 +505,8 @@ class TinyGsmSim7080 : public TinyGsmSim70xx, // we need to fill in the missing muxes if (ret_mux > muxNo) { for (int extra_mux = muxNo; extra_mux < ret_mux; extra_mux++) { - GsmClientSim7080* sock = sockets[extra_mux]; - if (sock) { sock->sock_available = 0; } + GsmClientSim7080* isock = sockets[extra_mux]; + if (isock) { isock->sock_available = 0; } } muxNo = ret_mux; } @@ -514,8 +515,8 @@ class TinyGsmSim7080 : public TinyGsmSim70xx, // so we set any we haven't gotten to yet to 0 for (int extra_mux = muxNo; extra_mux < TINY_GSM_MUX_COUNT; extra_mux++) { - GsmClientSim7080* sock = sockets[extra_mux]; - if (sock) { sock->sock_available = 0; } + GsmClientSim7080* isock = sockets[extra_mux]; + if (isock) { isock->sock_available = 0; } } break; } else { @@ -554,8 +555,8 @@ class TinyGsmSim7080 : public TinyGsmSim70xx, // we need to fill in the missing muxes if (ret_mux > muxNo) { for (int extra_mux = muxNo; extra_mux < ret_mux; extra_mux++) { - GsmClientSim7080* sock = sockets[extra_mux]; - if (sock) { sock->sock_connected = false; } + GsmClientSim7080* isock = sockets[extra_mux]; + if (isock) { isock->sock_connected = false; } } muxNo = ret_mux; } @@ -564,8 +565,8 @@ class TinyGsmSim7080 : public TinyGsmSim70xx, // so we set any we haven't gotten to yet to 0 for (int extra_mux = muxNo; extra_mux < TINY_GSM_MUX_COUNT; extra_mux++) { - GsmClientSim7080* sock = sockets[extra_mux]; - if (sock) { sock->sock_connected = false; } + GsmClientSim7080* isock = sockets[extra_mux]; + if (isock) { isock->sock_connected = false; } } break; } else { @@ -657,15 +658,6 @@ class TinyGsmSim7080 : public TinyGsmSim70xx, } } data = ""; - } else if (data.endsWith(GF("CLOSED" GSM_NL))) { - int8_t nl = data.lastIndexOf(GSM_NL, data.length() - 8); - int8_t coma = data.indexOf(',', nl + 2); - int8_t mux = data.substring(nl + 2, coma).toInt(); - if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { - sockets[mux]->sock_connected = false; - } - data = ""; - DBG("### Closed: ", mux); } else if (data.endsWith(GF("*PSNWID:"))) { streamSkipUntil('\n'); // Refresh network name by network data = "";