From 69cbab842d85ecf166b9f852c1944d469175ca29 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 24 May 2019 21:26:22 -0400 Subject: [PATCH 1/6] Longer wait for power down --- src/TinyGsmClientSIM800.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index f2030dd..4391850 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -269,7 +269,7 @@ TINY_GSM_MODEM_GET_INFO_ATI() bool poweroff() { sendAT(GF("+CPOWD=1")); - return waitResponse(GF("NORMAL POWER DOWN")) == 1; + return waitResponse(10000L, GF("NORMAL POWER DOWN")) == 1; } bool radioOff() { From 9ce1a2d9982c71c1fa1705c7d6fcd79a541f5514 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 24 May 2019 22:35:29 -0400 Subject: [PATCH 2/6] Get name from modem --- library.json | 2 +- library.properties | 2 +- src/TinyGsmClientSIM7000.h | 22 +++++++++++++++++++++- src/TinyGsmClientSIM800.h | 30 +++++++++++++++++++++++++----- src/TinyGsmCommon.h | 2 +- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/library.json b/library.json index 6d859aa..2aaf99c 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.7.7", + "version": "0.7.8", "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 14c6576..423a068 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.7.7 +version=0.7.8 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 458a05b..7726a3b 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -181,7 +181,27 @@ public: } String getModemName() { - return "SIMCom SIM7000"; + String name = "SIMCom SIM7000"; + + sendAT(GF("+CGMI")); + String res1; + if (waitResponse(1000L, res1) != 1) { + return name; + } + res1.replace(GSM_NL "OK" GSM_NL, ""); + res1.trim(); + + sendAT(GF("+GMM")); + String res2; + if (waitResponse(1000L, res2) != 1) { + return name; + } + res2.replace(GSM_NL "OK" GSM_NL, ""); + res2.trim(); + + name = res1 + String(' ') + res2; + DBG("### Modem:", name); + return name; } TINY_GSM_MODEM_SET_BAUD_IPR() diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 4391850..0e1d569 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -184,16 +184,36 @@ public: } String getModemName() { + String name = ""; #if defined(TINY_GSM_MODEM_SIM800) - return "SIMCom SIM800"; + name = "SIMCom SIM800"; #elif defined(TINY_GSM_MODEM_SIM808) - return "SIMCom SIM808"; + name = "SIMCom SIM808"; #elif defined(TINY_GSM_MODEM_SIM868) - return "SIMCom SIM868"; + name = "SIMCom SIM868"; #elif defined(TINY_GSM_MODEM_SIM900) - return "SIMCom SIM900"; + name = "SIMCom SIM900"; #endif - return "SIMCom SIM800"; + + sendAT(GF("+CGMI")); + String res1; + if (waitResponse(1000L, res1) != 1) { + return name; + } + res1.replace(GSM_NL "OK" GSM_NL, ""); + res1.trim(); + + sendAT(GF("+GMM")); + String res2; + if (waitResponse(1000L, res2) != 1) { + return name; + } + res2.replace(GSM_NL "OK" GSM_NL, ""); + res2.trim(); + + name = res1 + String(' ') + res2; + DBG("### Modem:", name); + return name; } TINY_GSM_MODEM_SET_BAUD_IPR() diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 3c66d9c..0b0a347 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -10,7 +10,7 @@ #define TinyGsmCommon_h // The current library version number -#define TINYGSM_VERSION "0.7.7" +#define TINYGSM_VERSION "0.7.8" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" From 3d7829226147b7a54d237e00e01ca7f203bbc189 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 24 May 2019 23:24:32 -0400 Subject: [PATCH 3/6] modemRead MUST end with sock_available correct --- src/TinyGsmClientBG96.h | 1 + src/TinyGsmClientM95.h | 2 -- src/TinyGsmClientMC60.h | 2 -- src/TinyGsmClientSIM7000.h | 11 ++--------- src/TinyGsmClientSIM800.h | 11 ++--------- src/TinyGsmClientSaraR4.h | 7 +++++-- src/TinyGsmClientSequansMonarch.h | 2 +- src/TinyGsmClientUBLOX.h | 7 +++++-- 8 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 132b993..19d9976 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -552,6 +552,7 @@ protected: } waitResponse(); DBG("### READ:", len, "from", mux); + sockets[mux]->sock_available = modemGetAvailable(); return len; } diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 3921fa7..346d04d 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -621,8 +621,6 @@ protected: streamSkipUntil(','); // skip port streamSkipUntil(','); // skip connection type (TCP/UDP) size_t len = stream.readStringUntil('\n').toInt(); // read length - sockets[mux]->sock_available = len; - for (size_t i=0; isock_available--; diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 667d6eb..b327fd0 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -628,8 +628,6 @@ protected: streamSkipUntil(','); // skip port streamSkipUntil(','); // skip connection type (TCP/UDP) size_t len = stream.readStringUntil('\n').toInt(); // read length - sockets[mux]->sock_available = len; - for (size_t i=0; isock_available--; diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index 7726a3b..c8e04ef 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -183,23 +183,16 @@ public: String getModemName() { String name = "SIMCom SIM7000"; - sendAT(GF("+CGMI")); - String res1; - if (waitResponse(1000L, res1) != 1) { - return name; - } - res1.replace(GSM_NL "OK" GSM_NL, ""); - res1.trim(); - sendAT(GF("+GMM")); String res2; if (waitResponse(1000L, res2) != 1) { return name; } res2.replace(GSM_NL "OK" GSM_NL, ""); + res2.replace("_", " "); res2.trim(); - name = res1 + String(' ') + res2; + name = res2; DBG("### Modem:", name); return name; } diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 0e1d569..365f4ee 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -195,23 +195,16 @@ public: name = "SIMCom SIM900"; #endif - sendAT(GF("+CGMI")); - String res1; - if (waitResponse(1000L, res1) != 1) { - return name; - } - res1.replace(GSM_NL "OK" GSM_NL, ""); - res1.trim(); - sendAT(GF("+GMM")); String res2; if (waitResponse(1000L, res2) != 1) { return name; } res2.replace(GSM_NL "OK" GSM_NL, ""); + res2.replace("_", " "); res2.trim(); - name = res1 + String(' ') + res2; + name = res2; DBG("### Modem:", name); return name; } diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index a4763cd..a8aa3db 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -100,7 +100,7 @@ TINY_GSM_CLIENT_CONNECT_OVERLOADS() // that it wants from the socket even if it was closed externally. rx.clear(); at->maintain(); - while (sock_available > 0) { + while (sock_connected && sock_available > 0) { at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); rx.clear(); at->maintain(); @@ -613,6 +613,7 @@ protected: streamSkipUntil('\"'); waitResponse(); DBG("### READ:", len, "from", mux); + sockets[mux]->sock_available = modemGetAvailable(); return len; } @@ -628,8 +629,10 @@ protected: result = stream.readStringUntil('\n').toInt(); // if (result) DBG("### DATA AVAILABLE:", result, "on", mux); waitResponse(); + } else if (res == 3) { + streamSkipUntil('\n'); // Skip the error text } - if (!result && res != 2 && res != 3) { // Don't check modemGetConnected after an error + if (!result) sockets[mux]->sock_connected = modemGetConnected(mux); } return result; diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index 1c145e1..8599c5a 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -624,7 +624,7 @@ protected: } DBG("### Read:", len, "from", mux); waitResponse(); - // sockets[mux % TINY_GSM_MUX_COUNT]->sock_available = modemGetAvailable(mux); + sockets[mux % TINY_GSM_MUX_COUNT]->sock_available = modemGetAvailable(mux); return len; } diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index b232db3..d3fb6e3 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -100,7 +100,7 @@ TINY_GSM_CLIENT_CONNECT_OVERLOADS() // that it wants from the socket even if it was closed externally. rx.clear(); at->maintain(); - while (sock_available > 0) { + while (sock_connected && sock_available > 0) { at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); rx.clear(); at->maintain(); @@ -601,6 +601,7 @@ protected: streamSkipUntil('\"'); waitResponse(); DBG("### READ:", len, "from", mux); + sockets[mux]->sock_available = modemGetAvailable(); return len; } @@ -616,8 +617,10 @@ protected: result = stream.readStringUntil('\n').toInt(); // if (result) DBG("### DATA AVAILABLE:", result, "on", mux); waitResponse(); + } else if (res == 3) { + streamSkipUntil('\n'); // Skip the error text } - if (!result && res != 2 && res != 3) { // Don't check modemGetConnected after an error + if (!result) { sockets[mux]->sock_connected = modemGetConnected(mux); } return result; From 4debf545b186b045c9ab06f95071dd64dddd4e9a Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 24 May 2019 23:30:32 -0400 Subject: [PATCH 4/6] Add missing mux --- src/TinyGsmClientBG96.h | 2 +- src/TinyGsmClientSaraR4.h | 2 +- src/TinyGsmClientUBLOX.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 19d9976..e1eb09c 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -552,7 +552,7 @@ protected: } waitResponse(); DBG("### READ:", len, "from", mux); - sockets[mux]->sock_available = modemGetAvailable(); + sockets[mux]->sock_available = modemGetAvailable(mux); return len; } diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index a8aa3db..247b920 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -613,7 +613,7 @@ protected: streamSkipUntil('\"'); waitResponse(); DBG("### READ:", len, "from", mux); - sockets[mux]->sock_available = modemGetAvailable(); + sockets[mux]->sock_available = modemGetAvailable(mux); return len; } diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index d3fb6e3..08e3015 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -601,7 +601,7 @@ protected: streamSkipUntil('\"'); waitResponse(); DBG("### READ:", len, "from", mux); - sockets[mux]->sock_available = modemGetAvailable(); + sockets[mux]->sock_available = modemGetAvailable(mux); return len; } From 5f8c1c57848fd0e2d76571c0d026c419f0429887 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 24 May 2019 23:36:35 -0400 Subject: [PATCH 5/6] Missing brace --- src/TinyGsmClientSaraR4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 247b920..42bc8ea 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -632,7 +632,7 @@ protected: } else if (res == 3) { streamSkipUntil('\n'); // Skip the error text } - if (!result) + if (!result) { sockets[mux]->sock_connected = modemGetConnected(mux); } return result; From db6bb0e6c06f9b982bf838cde5eaa00a4e5e73be Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 24 May 2019 23:47:49 -0400 Subject: [PATCH 6/6] Fix ublox battery percent --- library.json | 2 +- library.properties | 2 +- src/TinyGsmClientUBLOX.h | 4 +++- src/TinyGsmCommon.h | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library.json b/library.json index 2aaf99c..fb2fa8c 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.7.8", + "version": "0.7.9", "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 423a068..df969ab 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.7.8 +version=0.7.9 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 08e3015..180615e 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -501,8 +501,10 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED() } int res = stream.readStringUntil(',').toInt(); + int8_t percent = res*20; // return is 0-5 + // Wait for final OK waitResponse(); - return res; + return percent; } uint8_t getBattChargeState() TINY_GSM_ATTR_NOT_AVAILABLE; diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 0b0a347..7b87633 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -10,7 +10,7 @@ #define TinyGsmCommon_h // The current library version number -#define TINYGSM_VERSION "0.7.8" +#define TINYGSM_VERSION "0.7.9" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h"