From eb9358f44057d912cbab4894196997d265ab5110 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 14 Apr 2020 21:38:15 -0400 Subject: [PATCH 1/5] Check GPRS status on SIM7000 Signed-off-by: Sara Damiano --- .github/ISSUE_TEMPLATE.md | 2 +- README.md | 2 +- library.json | 2 +- library.properties | 2 +- src/TinyGsmClientSIM7000.h | 10 +++++++++- src/TinyGsmClientSaraR4.h | 18 ++++-------------- src/TinyGsmCommon.h | 2 +- 7 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 8c31c06..98b342b 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -22,7 +22,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/README.md b/README.md index 50528a3..de71408 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Watch this repo for new updates! And of course, contributions are welcome ;) **Location** - GPS/GNSS - SIM808, SIM7000, SIM7500/7600/7800, BG96, u-blox - - NOTE: u-blox chips do NOT have embedded GPS - this function only works if a secondary GPS is connected to primary cellular chip over I2C + - NOTE: u-blox chips do _NOT_ have embedded GPS - this function only works if a secondary GPS is connected to primary cellular chip over I2C - GSM location service - SIM800, SIM7000, Quectel, u-blox diff --git a/library.json b/library.json index 825befa..d9f01fe 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.10.1", + "version": "0.10.2", "description": "A small Arduino library for GPRS modules, that just works. Includes examples for Blynk, MQTT, File Download, and Web Client. Supports many GSM, LTE, and WiFi modules with AT command interfaces.", "keywords": "GSM, AT commands, AT, SIM800, SIM900, A6, A7, M590, ESP8266, SIM7000, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900A, SIM900D, SIM908, SIM968, M95, MC60, MC60E, BG96, ublox, Quectel, SIMCOM, AI Thinker, LTE, LTE-M", "authors": diff --git a/library.properties b/library.properties index 3d0e6a5..8b1fd67 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.10.1 +version=0.10.2 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index 081eb93..a85ca48 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -239,7 +239,15 @@ class TinyGsmSim7000 : public TinyGsmModem, */ public: RegStatus getRegistrationStatus() { - return (RegStatus)getRegistrationStatusXREG("CEREG"); + RegStatus epsStatus = (RegStatus)getRegistrationStatusXREG("CEREG"); + // If we're connected on EPS, great! + if (epsStatus == REG_OK_HOME || epsStatus == REG_OK_ROAMING) { + return epsStatus; + } else { + // Otherwise, check GPRS network status + // We could be using GPRS fall-back or the board could be being moody + return (RegStatus)getRegistrationStatusXREG("CGREG"); + } } protected: diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 945968a..0ab9054 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -317,24 +317,14 @@ class TinyGsmSaraR4 : public TinyGsmModem, public: RegStatus getRegistrationStatus() { // Check first for EPS registration - sendAT(GF("+CEREG?")); - if (waitResponse(GF(GSM_NL "+CEREG:")) != 1) { return REG_UNKNOWN; } - streamSkipUntil(','); /* Skip format (0) */ - int status = streamGetIntBefore('\n'); - waitResponse(); + RegStatus epsStatus = (RegStatus)getRegistrationStatusXREG("CEREG"); // If we're connected on EPS, great! - if ((RegStatus)status == REG_OK_HOME || - (RegStatus)status == REG_OK_ROAMING) { - return (RegStatus)status; + if (epsStatus == REG_OK_HOME || epsStatus == REG_OK_ROAMING) { + return epsStatus; } else { // Otherwise, check generic network status - sendAT(GF("+CREG?")); - if (waitResponse(GF(GSM_NL "+CREG:")) != 1) { return REG_UNKNOWN; } - streamSkipUntil(','); /* Skip format (0) */ - status = streamGetIntBefore('\n'); - waitResponse(); - return (RegStatus)status; + return (RegStatus)getRegistrationStatusXREG("CREG"); } } diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 7249b01..00679f1 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -10,7 +10,7 @@ #define SRC_TINYGSMCOMMON_H_ // The current library version number -#define TINYGSM_VERSION "0.10.1" +#define TINYGSM_VERSION "0.10.2" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" From dbd677e6e76f10ebff38b9a1ca0188532f96fdc7 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 15 Apr 2020 08:34:44 -0400 Subject: [PATCH 2/5] Fix several potential null pointers Signed-off-by: Sara Damiano --- src/TinyGsmClientESP8266.h | 10 +++++++-- src/TinyGsmClientSIM5360.h | 15 +++++++++++-- src/TinyGsmClientSIM7600.h | 8 ++++++- src/TinyGsmClientSequansMonarch.h | 37 ++++++++++++++++++------------- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index c574028..3678a97 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -315,7 +315,10 @@ class TinyGsmESP8266 : public TinyGsmModem, // if the status is anything but 3, there are no connections open waitResponse(); // Returns an OK after the status for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) { - sockets[muxNo]->sock_connected = false; + GsmClientESP8266* sock = sockets[muxNo]; + if (sock) { + sock->sock_connected = false; + } } return false; } @@ -336,7 +339,10 @@ class TinyGsmESP8266 : public TinyGsmModem, if (has_status == 2) break; // once we get to the ok, stop } for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) { - sockets[muxNo]->sock_connected = verified_connections[muxNo]; + GsmClientESP8266* sock = sockets[muxNo]; + if (sock) { + sock->sock_connected = verified_connections[muxNo]; + } } return verified_connections[mux]; } diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index d282ae0..9192c1d 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -217,8 +217,13 @@ class TinyGsmSim5360 : public TinyGsmModem, bool restartImpl() { if (!testAT()) { return false; } sendAT(GF("+REBOOT")); + // Should return an 'OK' after reboot command is sent if (waitResponse(10000L) != 1) { return false; } - delay(3000L); // TODO(?): Test this delay! + // After booting, modem sends out messages as each of its + // internal modules loads. The final message is "PB DONE". + if (waitResponse(40000L, GF(GSM_NL "PB DONE")) != 1) { + return false; + } return init(); } @@ -574,7 +579,13 @@ class TinyGsmSim5360 : public TinyGsmModem, if (waitResponse(GF("+CIPCLOSE:")) != 1) { return false; } for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) { // +CIPCLOSE:,,..., - sockets[muxNo]->sock_connected = stream.parseInt(); + bool thisMuxState = stream.parseInt(); + // Need to make sure a socket instace for the socket number exists + // before setting its state + GsmClientSim5360* sock = sockets[muxNo]; + if (sock) { + sock->sock_connected = thisMuxState; + } } waitResponse(); // Should be an OK at the end return sockets[mux]->sock_connected; diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index 99138a0..e44106e 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -672,7 +672,13 @@ class TinyGsmSim7600 : public TinyGsmModem, } for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) { // +CIPCLOSE:,,..., - sockets[muxNo]->sock_connected = stream.parseInt(); + bool thisMuxState = stream.parseInt(); + // Need to make sure a socket instace for the socket number exists + // before setting its state + GsmClientSim7600* sock = sockets[muxNo]; + if (sock) { + sock->sock_connected = thisMuxState; + } } waitResponse(); // Should be an OK at the end return sockets[mux]->sock_connected; diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index d8790a7..f644c33 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -571,7 +571,9 @@ 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!"); @@ -588,28 +590,31 @@ class TinyGsmSequansMonarch // SOCK_LISTENING = 4, // SOCK_INCOMING = 5, // SOCK_OPENING = 6, - sockets[muxNo % TINY_GSM_MUX_COUNT]->sock_connected = - ((status != SOCK_CLOSED) && (status != SOCK_INCOMING) && - (status != SOCK_OPENING)); + GsmClientSequansMonarch* sock = sockets[mux % TINY_GSM_MUX_COUNT]; + if (sock) { + sock->sock_connected = + ((status != SOCK_CLOSED) && (status != SOCK_INCOMING) && + (status != SOCK_OPENING)); + } } waitResponse(); // Should be an OK at the end return sockets[mux % TINY_GSM_MUX_COUNT]->sock_connected; } - /* - * Utilities - */ - public: - // TODO(vshymanskyy): Optimize this! - int8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), + /* + * Utilities + */ + public: + // TODO(vshymanskyy): Optimize this! + int8_t waitResponse(uint32_t timeout_ms, String & data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), #if defined TINY_GSM_DEBUG - GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), #else - GsmConstStr r3 = NULL, + GsmConstStr r3 = NULL, #endif - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -705,6 +710,6 @@ class TinyGsmSequansMonarch Stream& stream; GsmClientSequansMonarch* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; -}; + }; #endif // SRC_TINYGSMCLIENTSEQUANSMONARCH_H_ From 9f2068cecb654dcd2f1d5a0a5717e50d17e23a13 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 15 Apr 2020 08:36:11 -0400 Subject: [PATCH 3/5] Fix QTEMP on M95, fixes #377 Signed-off-by: Sara Damiano --- src/TinyGsmClientM95.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 4646708..acf2424 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -387,7 +387,7 @@ class TinyGsmM95 : public TinyGsmModem, */ protected: float getTemperatureImpl() { - sendAT(GF("+QTEMP")); + sendAT(GF("+QTEMP?")); if (waitResponse(GF(GSM_NL "+QTEMP:")) != 1) { return static_cast(-9999); } From 5a6936b37aecec0dfc8378ffd770614d16109442 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 15 Apr 2020 08:41:33 -0400 Subject: [PATCH 4/5] Made internal stream public again, fixing #373 Signed-off-by: Sara Damiano --- src/TinyGsmClientA6.h | 3 ++- src/TinyGsmClientBG96.h | 3 ++- src/TinyGsmClientESP8266.h | 3 ++- src/TinyGsmClientM590.h | 3 ++- src/TinyGsmClientM95.h | 3 ++- src/TinyGsmClientMC60.h | 3 ++- src/TinyGsmClientSIM5360.h | 3 ++- src/TinyGsmClientSIM7000.h | 3 ++- src/TinyGsmClientSIM7600.h | 3 ++- src/TinyGsmClientSIM800.h | 3 ++- src/TinyGsmClientSaraR4.h | 3 ++- src/TinyGsmClientSequansMonarch.h | 3 ++- src/TinyGsmClientUBLOX.h | 3 ++- src/TinyGsmClientXBee.h | 3 ++- 14 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 8e57ed4..4693abb 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -560,8 +560,9 @@ class TinyGsmA6 : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientA6* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 5639a2b..9396d0a 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -673,8 +673,9 @@ class TinyGsmBG96 : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientBG96* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 3678a97..35c0f83 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -441,8 +441,9 @@ class TinyGsmESP8266 : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientESP8266* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index bf820cc..a11caba 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -452,8 +452,9 @@ class TinyGsmM590 : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientM590* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index acf2424..341ab01 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -616,8 +616,9 @@ class TinyGsmM95 : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientM95* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 2aba92b..b100baa 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -588,8 +588,9 @@ class TinyGsmMC60 : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5, r6); } - protected: + public: Stream& stream; + protected: GsmClientMC60* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index 9192c1d..b8e01a8 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -713,8 +713,9 @@ class TinyGsmSim5360 : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientSim5360* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index a85ca48..0f84725 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -754,8 +754,9 @@ class TinyGsmSim7000 : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientSim7000* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index e44106e..2f384de 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -806,8 +806,9 @@ class TinyGsmSim7600 : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientSim7600* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 8c85de1..4878afa 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -720,8 +720,9 @@ class TinyGsmSim800 : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientSim800* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 0ab9054..742e265 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -877,8 +877,9 @@ class TinyGsmSaraR4 : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientSaraR4* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; bool has2GFallback; diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index f644c33..d9bd918 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -706,8 +706,9 @@ class TinyGsmSequansMonarch return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientSequansMonarch* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index b01cdf8..1dd4eb6 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -810,8 +810,9 @@ class TinyGsmUBLOX : public TinyGsmModem, return waitResponse(1000, r1, r2, r3, r4, r5); } - protected: + public: Stream& stream; + protected: GsmClientUBLOX* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; }; diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 21c3154..e3b39a0 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -1440,8 +1440,9 @@ class TinyGsmXBee : public TinyGsmModem, return false; } - protected: + public: Stream& stream; + protected: GsmClientXBee* sockets[TINY_GSM_MUX_COUNT]; const char* gsmNL = GSM_NL; int16_t guardTime; From 90dde6861bb6923ef339ca303936dc61788a46fa Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 15 Apr 2020 08:48:31 -0400 Subject: [PATCH 5/5] Fix get battery voltage, fixes #369 Signed-off-by: Sara Damiano --- src/TinyGsmBattery.tpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TinyGsmBattery.tpp b/src/TinyGsmBattery.tpp index 36596e7..a662682 100644 --- a/src/TinyGsmBattery.tpp +++ b/src/TinyGsmBattery.tpp @@ -55,7 +55,7 @@ class TinyGsmBattery { thisModem().streamSkipUntil(','); // Skip battery charge status thisModem().streamSkipUntil(','); // Skip battery charge level // return voltage in mV - uint16_t res = thisModem().streamGetIntBefore(','); + uint16_t res = thisModem().streamGetIntBefore('\n'); // Wait for final OK thisModem().waitResponse(); return res;