From 3a8a2ada1a2134e7659d1750f909be17c8c06879 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 27 Aug 2019 16:15:43 -0400 Subject: [PATCH 01/37] Another update to examples --- examples/AllFunctions/AllFunctions.ino | 17 +++- examples/BlynkClient/BlynkClient.ino | 5 +- examples/FileDownload/FileDownload.ino | 45 ++++++++-- examples/HttpClient/HttpClient.ino | 39 ++++++-- examples/HttpsClient/HttpsClient.ino | 41 +++++++-- examples/MqttClient/MqttClient.ino | 118 +++++++++++++++---------- examples/WebClient/WebClient.ino | 33 +++++-- tools/Diagnostics/Diagnostics.ino | 33 +++++-- 8 files changed, 251 insertions(+), 80 deletions(-) diff --git a/examples/AllFunctions/AllFunctions.ino b/examples/AllFunctions/AllFunctions.ino index f6df8a6..d2a3565 100644 --- a/examples/AllFunctions/AllFunctions.ino +++ b/examples/AllFunctions/AllFunctions.ino @@ -70,16 +70,29 @@ //#define SMS_TARGET "+380xxxxxxxxx" //#define CALL_TARGET "+380xxxxxxxxx" -// Your GPRS credentials -// Leave empty, if missing user or pass +// Your GPRS credentials, if any const char apn[] = "YourAPN"; const char gprsUser[] = ""; const char gprsPass[] = ""; + +// Your WiFi connection credentials, if applicable const char wifiSSID[] = "YourSSID"; const char wifiPass[] = "YourWiFiPass"; #include +#if TINY_GSM_TEST_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS +#define TINY_GSM_TEST_GPRS false +#define TINY_GSM_TEST_CALL false +#define TINY_GSM_TEST_SMS false +#define TINY_GSM_TEST_USSD false +#define TINY_GSM_TEST_WIFI true +#endif +#if TINY_GSM_TEST_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false +#endif + #ifdef DUMP_AT_COMMANDS #include StreamDebugger debugger(SerialAT, SerialMon); diff --git a/examples/BlynkClient/BlynkClient.ino b/examples/BlynkClient/BlynkClient.ino index afaed31..0ae92ee 100644 --- a/examples/BlynkClient/BlynkClient.ino +++ b/examples/BlynkClient/BlynkClient.ino @@ -63,8 +63,7 @@ //SoftwareSerial SerialAT(2, 3); // RX, TX -// Your GPRS credentials -// Leave empty, if missing user or pass +// Your GPRS credentials, if any const char apn[] = "YourAPN"; const char user[] = ""; const char pass[] = ""; @@ -91,7 +90,7 @@ void setup() modem.restart(); String modemInfo = modem.getModemInfo(); - SerialMon.print("Modem: "); + SerialMon.print("Modem Info: "); SerialMon.println(modemInfo); // Unlock your SIM card with a PIN diff --git a/examples/FileDownload/FileDownload.ino b/examples/FileDownload/FileDownload.ino index 5d935bc..cfab6a7 100644 --- a/examples/FileDownload/FileDownload.ino +++ b/examples/FileDownload/FileDownload.ino @@ -61,17 +61,19 @@ // Add a reception delay - may be needed for a fast processor at a slow baud rate //#define TINY_GSM_YIELD() { delay(2); } +// Define how you're planning to connect to the internet #define TINY_GSM_USE_GPRS true #define TINY_GSM_USE_WIFI false // set GSM PIN, if any #define GSM_PIN "" -// Your GPRS credentials -// Leave empty, if missing user or pass +// Your GPRS credentials, if any const char apn[] = "YourAPN"; const char gprsUser[] = ""; const char gprsPass[] = ""; + +// Your WiFi connection credentials, if applicable const char wifiSSID[] = "YourSSID"; const char wifiPass[] = "YourWiFiPass"; @@ -82,6 +84,20 @@ const int port = 80; #include #include +// Just in case someone defined the wrong thing.. +#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS false +#define TINY_GSM_USE_WIFI true +#endif +#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false +#endif + const char resource[] = "/TinyGSM/test_1k.bin"; uint32_t knownCRC32 = 0x6f50d767; uint32_t knownFileSize = 1024; // In case server does not send it @@ -101,6 +117,12 @@ void setup() { SerialMon.begin(115200); delay(10); + // !!!!!!!!!!! + // Set your reset, enable, power pins here + // !!!!!!!!!!! + + SerialMon.println("Wait..."); + // Set GSM module baud rate SerialAT.begin(115200); delay(3000); @@ -109,9 +131,10 @@ void setup() { // To skip it, call init() instead of restart() SerialMon.println("Initializing modem..."); modem.restart(); + // modem.init(); String modemInfo = modem.getModemInfo(); - SerialMon.print("Modem: "); + SerialMon.print("Modem Info: "); SerialMon.println(modemInfo); #if TINY_GSM_USE_GPRS @@ -135,7 +158,8 @@ void printPercent(uint32_t readLength, uint32_t contentLength) { void loop() { -#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI +#if TINY_GSM_USE_WIFI + // Wifi connection parameters must be set before waiting for the network SerialMon.print(F("Setting SSID/password...")); if (!modem.networkConnect(wifiSSID, wifiPass)) { SerialMon.println(" fail"); @@ -162,7 +186,8 @@ void loop() { SerialMon.println("Network connected"); } -#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS +#if TINY_GSM_USE_GPRS + // GPRS connection parameters are usually set after network registration SerialMon.print(F("Connecting to ")); SerialMon.print(apn); if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { @@ -171,6 +196,10 @@ void loop() { return; } SerialMon.println(" success"); + + if (modem.isGprsConnected()) { + SerialMon.println("GPRS connected"); + } #endif SerialMon.print(F("Connecting to ")); @@ -292,8 +321,14 @@ void loop() { client.stop(); SerialMon.println(F("Server disconnected")); +#if TINY_GSM_USE_WIFI + modem.networkDisconnect(); + SerialMon.println(F("WiFi disconnected")); +#endif +#if TINY_GSM_USE_GPRS modem.gprsDisconnect(); SerialMon.println(F("GPRS disconnected")); +#endif float duration = float(timeElapsed) / 1000; diff --git a/examples/HttpClient/HttpClient.ino b/examples/HttpClient/HttpClient.ino index 37bd6f2..d77f1de 100644 --- a/examples/HttpClient/HttpClient.ino +++ b/examples/HttpClient/HttpClient.ino @@ -63,20 +63,26 @@ #define TINY_GSM_DEBUG SerialMon //#define LOGGING // <- Logging is for the HTTP library +// Range to attempt to autobaud +#define GSM_AUTOBAUD_MIN 9600 +#define GSM_AUTOBAUD_MAX 115200 + // Add a reception delay - may be needed for a fast processor at a slow baud rate //#define TINY_GSM_YIELD() { delay(2); } +// Define how you're planning to connect to the internet #define TINY_GSM_USE_GPRS true #define TINY_GSM_USE_WIFI false // set GSM PIN, if any #define GSM_PIN "" -// Your GPRS credentials -// Leave empty, if missing user or pass +// Your GPRS credentials, if any const char apn[] = "YourAPN"; const char gprsUser[] = ""; const char gprsPass[] = ""; + +// Your WiFi connection credentials, if applicable const char wifiSSID[] = "YourSSID"; const char wifiPass[] = "YourWiFiPass"; @@ -88,6 +94,20 @@ const int port = 80; #include #include +// Just in case someone defined the wrong thing.. +#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS false +#define TINY_GSM_USE_WIFI true +#endif +#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false +#endif + #ifdef DUMP_AT_COMMANDS #include StreamDebugger debugger(SerialAT, SerialMon); @@ -111,7 +131,8 @@ void setup() { SerialMon.println("Wait..."); // Set GSM module baud rate - SerialAT.begin(115200); + // TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX); + SerialAT.begin(9600); delay(3000); // Restart takes quite some time @@ -121,7 +142,7 @@ void setup() { // modem.init(); String modemInfo = modem.getModemInfo(); - SerialMon.print("Modem: "); + SerialMon.print("Modem Info: "); SerialMon.println(modemInfo); #if TINY_GSM_USE_GPRS @@ -134,7 +155,8 @@ void setup() { void loop() { -#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI +#if TINY_GSM_USE_WIFI + // Wifi connection parameters must be set before waiting for the network SerialMon.print(F("Setting SSID/password...")); if (!modem.networkConnect(wifiSSID, wifiPass)) { SerialMon.println(" fail"); @@ -161,7 +183,8 @@ void loop() { SerialMon.println("Network connected"); } -#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS +#if TINY_GSM_USE_GPRS + // GPRS connection parameters are usually set after network registration SerialMon.print(F("Connecting to ")); SerialMon.print(apn); if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { @@ -170,6 +193,10 @@ void loop() { return; } SerialMon.println(" success"); + + if (modem.isGprsConnected()) { + SerialMon.println("GPRS connected"); + } #endif SerialMon.print(F("Performing HTTP GET request... ")); diff --git a/examples/HttpsClient/HttpsClient.ino b/examples/HttpsClient/HttpsClient.ino index 04874dd..6330ea9 100644 --- a/examples/HttpsClient/HttpsClient.ino +++ b/examples/HttpsClient/HttpsClient.ino @@ -55,20 +55,26 @@ #define TINY_GSM_DEBUG SerialMon //#define LOGGING // <- Logging is for the HTTP library +// Range to attempt to autobaud +#define GSM_AUTOBAUD_MIN 9600 +#define GSM_AUTOBAUD_MAX 115200 + // Add a reception delay - may be needed for a fast processor at a slow baud rate //#define TINY_GSM_YIELD() { delay(2); } +// Define how you're planning to connect to the internet #define TINY_GSM_USE_GPRS true #define TINY_GSM_USE_WIFI false // set GSM PIN, if any #define GSM_PIN "" -// Your GPRS credentials -// Leave empty, if missing user or pass +// Your GPRS credentials, if any const char apn[] = "YourAPN"; const char gprsUser[] = ""; const char gprsPass[] = ""; + +// Your WiFi connection credentials, if applicable const char wifiSSID[] = "YourSSID"; const char wifiPass[] = "YourWiFiPass"; @@ -80,6 +86,20 @@ const int port = 443; #include #include +// Just in case someone defined the wrong thing.. +#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS false +#define TINY_GSM_USE_WIFI true +#endif +#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false +#endif + #ifdef DUMP_AT_COMMANDS #include StreamDebugger debugger(SerialAT, SerialMon); @@ -103,7 +123,8 @@ void setup() { SerialMon.println("Wait..."); // Set GSM module baud rate - SerialAT.begin(115200); + // TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX); + SerialAT.begin(9600); delay(3000); // Restart takes quite some time @@ -113,7 +134,7 @@ void setup() { // modem.init(); String modemInfo = modem.getModemInfo(); - SerialMon.print("Modem: "); + SerialMon.print("Modem Info: "); SerialMon.println(modemInfo); #if TINY_GSM_USE_GPRS @@ -131,7 +152,8 @@ void setup() { void loop() { -#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI +#if TINY_GSM_USE_WIFI + // Wifi connection parameters must be set before waiting for the network SerialMon.print(F("Setting SSID/password...")); if (!modem.networkConnect(wifiSSID, wifiPass)) { SerialMon.println(" fail"); @@ -158,7 +180,8 @@ void loop() { SerialMon.println("Network connected"); } -#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS +#if TINY_GSM_USE_GPRS + // GPRS connection parameters are usually set after network registration SerialMon.print(F("Connecting to ")); SerialMon.print(apn); if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { @@ -167,10 +190,14 @@ void loop() { return; } SerialMon.println(" success"); + + if (modem.isGprsConnected()) { + SerialMon.println("GPRS connected"); + } #endif SerialMon.print(F("Performing HTTPS GET request... ")); - http.connectionKeepAlive(); // Currently, this is needed for HTTPS + http.connectionKeepAlive(); // Currently, this is needed for HTTPS int err = http.get(resource); if (err != 0) { SerialMon.println(F("failed to connect")); diff --git a/examples/MqttClient/MqttClient.ino b/examples/MqttClient/MqttClient.ino index 4b3878b..12649b7 100644 --- a/examples/MqttClient/MqttClient.ino +++ b/examples/MqttClient/MqttClient.ino @@ -67,27 +67,29 @@ // Range to attempt to autobaud #define GSM_AUTOBAUD_MIN 9600 -#define GSM_AUTOBAUD_MAX 38400 +#define GSM_AUTOBAUD_MAX 115200 // Add a reception delay - may be needed for a fast processor at a slow baud rate //#define TINY_GSM_YIELD() { delay(2); } -#define TINY_GSM_USE_GPRS true -#define TINY_GSM_USE_WIFI false +// Define how you're planning to connect to the internet +#define TINY_GSM_USE_GPRS false +#define TINY_GSM_USE_WIFI true // set GSM PIN, if any #define GSM_PIN "" -// Your GPRS credentials -// Leave empty, if missing user or pass -const char apn[] = "YourAPN"; +// Your GPRS credentials, if any +const char apn[] = "YourAPN"; const char gprsUser[] = ""; const char gprsPass[] = ""; -const char wifiSSID[] = "YourSSID"; + +// Your WiFi connection credentials, if applicable +const char wifiSSID[] = "YourSSID"; const char wifiPass[] = "YourWiFiPass"; // MQTT details -const char* broker = "test.mosquitto.org"; +const char* broker = "broker.hivemq.com"; const char* topicLed = "GsmClientTest/led"; const char* topicInit = "GsmClientTest/init"; @@ -96,6 +98,20 @@ const char* topicLedStatus = "GsmClientTest/ledStatus"; #include #include +// Just in case someone defined the wrong thing.. +#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS false +#define TINY_GSM_USE_WIFI true +#endif +#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false +#endif + #ifdef DUMP_AT_COMMANDS #include StreamDebugger debugger(SerialAT, SerialMon); @@ -111,6 +127,42 @@ int ledStatus = LOW; long lastReconnectAttempt = 0; +void mqttCallback(char* topic, byte* payload, unsigned int len) { + SerialMon.print("Message arrived ["); + SerialMon.print(topic); + SerialMon.print("]: "); + SerialMon.write(payload, len); + SerialMon.println(); + + // Only proceed if incoming message's topic matches + if (String(topic) == topicLed) { + ledStatus = !ledStatus; + digitalWrite(LED_PIN, ledStatus); + mqtt.publish(topicLedStatus, ledStatus ? "1" : "0"); + } +} + +boolean mqttConnect() { + SerialMon.print("Connecting to "); + SerialMon.print(broker); + + // Connect to MQTT Broker + boolean status = mqtt.connect("GsmClientTest"); + + // Or, if you want to authenticate MQTT: + //boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass"); + + if (status == false) { + SerialMon.println(" fail"); + return false; + } + SerialMon.println(" success"); + mqtt.publish(topicInit, "GsmClientTest started"); + mqtt.subscribe(topicLed); + return mqtt.connected(); +} + + void setup() { // Set console baud rate SerialMon.begin(115200); @@ -125,7 +177,8 @@ void setup() { SerialMon.println("Wait..."); // Set GSM module baud rate - SerialAT.begin(115200); + // TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX); + SerialAT.begin(9600); delay(3000); // Restart takes quite some time @@ -135,7 +188,7 @@ void setup() { // modem.init(); String modemInfo = modem.getModemInfo(); - SerialMon.print("Modem: "); + SerialMon.print("Modem Info: "); SerialMon.println(modemInfo); #if TINY_GSM_USE_GPRS @@ -145,7 +198,8 @@ void setup() { } #endif -#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI +#if TINY_GSM_USE_WIFI + // Wifi connection parameters must be set before waiting for the network SerialMon.print(F("Setting SSID/password...")); if (!modem.networkConnect(wifiSSID, wifiPass)) { SerialMon.println(" fail"); @@ -172,7 +226,8 @@ void setup() { SerialMon.println("Network connected"); } -#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS +#if TINY_GSM_USE_GPRS + // GPRS connection parameters are usually set after network registration SerialMon.print(F("Connecting to ")); SerialMon.print(apn); if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { @@ -181,6 +236,10 @@ void setup() { return; } SerialMon.println(" success"); + + if (modem.isGprsConnected()) { + SerialMon.println("GPRS connected"); + } #endif // MQTT Broker setup @@ -188,26 +247,6 @@ void setup() { mqtt.setCallback(mqttCallback); } -boolean mqttConnect() { - SerialMon.print("Connecting to "); - SerialMon.print(broker); - - // Connect to MQTT Broker - boolean status = mqtt.connect("GsmClientTest"); - - // Or, if you want to authenticate MQTT: - //boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass"); - - if (status == false) { - SerialMon.println(" fail"); - return false; - } - SerialMon.println(" success"); - mqtt.publish(topicInit, "GsmClientTest started"); - mqtt.subscribe(topicLed); - return mqtt.connected(); -} - void loop() { if (!mqtt.connected()) { @@ -226,18 +265,3 @@ void loop() { mqtt.loop(); } - -void mqttCallback(char* topic, byte* payload, unsigned int len) { - SerialMon.print("Message arrived ["); - SerialMon.print(topic); - SerialMon.print("]: "); - SerialMon.write(payload, len); - SerialMon.println(); - - // Only proceed if incoming message's topic matches - if (String(topic) == topicLed) { - ledStatus = !ledStatus; - digitalWrite(LED_PIN, ledStatus); - mqtt.publish(topicLedStatus, ledStatus ? "1" : "0"); - } -} diff --git a/examples/WebClient/WebClient.ino b/examples/WebClient/WebClient.ino index 9c63c62..8207c06 100644 --- a/examples/WebClient/WebClient.ino +++ b/examples/WebClient/WebClient.ino @@ -62,17 +62,20 @@ // Uncomment this if you want to use SSL //#define USE_SSL +// Define how you're planning to connect to the internet #define TINY_GSM_USE_GPRS true #define TINY_GSM_USE_WIFI false // set GSM PIN, if any #define GSM_PIN "" -// Your GPRS credentials -// Leave empty, if missing user or pass +// Your GPRS credentials, if any const char apn[] = "YourAPN"; const char gprsUser[] = ""; const char gprsPass[] = ""; + +// Your WiFi connection credentials, if applicable +const char wifiSSID[] = "YourSSID"; const char wifiPass[] = "YourWiFiPass"; // Server details @@ -81,6 +84,20 @@ const char resource[] = "/TinyGSM/logo.txt"; #include +// Just in case someone defined the wrong thing.. +#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS false +#define TINY_GSM_USE_WIFI true +#endif +#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false +#endif + #ifdef DUMP_AT_COMMANDS #include StreamDebugger debugger(SerialAT, SerialMon); @@ -120,7 +137,7 @@ void setup() { // modem.init(); String modemInfo = modem.getModemInfo(); - SerialMon.print("Modem: "); + SerialMon.print("Modem Info: "); SerialMon.println(modemInfo); #if TINY_GSM_USE_GPRS @@ -133,7 +150,8 @@ void setup() { void loop() { -#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI +#if TINY_GSM_USE_WIFI + // Wifi connection parameters must be set before waiting for the network SerialMon.print(F("Setting SSID/password...")); if (!modem.networkConnect(wifiSSID, wifiPass)) { SerialMon.println(" fail"); @@ -160,7 +178,8 @@ void loop() { SerialMon.println("Network connected"); } -#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS +#if TINY_GSM_USE_GPRS + // GPRS connection parameters are usually set after network registration SerialMon.print(F("Connecting to ")); SerialMon.print(apn); if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { @@ -169,6 +188,10 @@ void loop() { return; } SerialMon.println(" success"); + + if (modem.isGprsConnected()) { + SerialMon.println("GPRS connected"); + } #endif SerialMon.print("Connecting to "); diff --git a/tools/Diagnostics/Diagnostics.ino b/tools/Diagnostics/Diagnostics.ino index b66e1b4..962043c 100644 --- a/tools/Diagnostics/Diagnostics.ino +++ b/tools/Diagnostics/Diagnostics.ino @@ -69,11 +69,12 @@ // set GSM PIN, if any #define GSM_PIN "" -// Your GPRS credentials -// Leave empty, if missing user or pass +// Your GPRS credentials, if any const char apn[] = "YourAPN"; const char gprsUser[] = ""; const char gprsPass[] = ""; + +// Your WiFi connection credentials, if applicable const char wifiSSID[] = "YourSSID"; const char wifiPass[] = "YourWiFiPass"; @@ -83,6 +84,20 @@ const char resource[] = "/TinyGSM/logo.txt"; #include +// Just in case someone defined the wrong thing.. +#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS false +#define TINY_GSM_USE_WIFI true +#endif +#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false +#endif + #ifdef DUMP_AT_COMMANDS #include StreamDebugger debugger(SerialAT, SerialMon); @@ -111,8 +126,8 @@ void setup() { SerialMon.println("Wait..."); // Set GSM module baud rate - TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX); - // SerialAT.begin(115200); + // TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX); + SerialAT.begin(115200); delay(3000); } @@ -147,6 +162,7 @@ void loop() { #endif #if TINY_GSM_USE_WIFI + // Wifi connection parameters must be set before waiting for the network SerialMon.print(F("Setting SSID/password...")); if (!modem.networkConnect(wifiSSID, wifiPass)) { SerialMon.println(" fail"); @@ -175,7 +191,8 @@ void loop() { } SerialMon.println(F(" [OK]")); -#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS +#if TINY_GSM_USE_GPRS + // GPRS connection parameters are usually set after network registration SerialMon.print("Connecting to "); SerialMon.print(apn); if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { @@ -233,8 +250,14 @@ void loop() { client.stop(); SerialMon.println(F("Server disconnected")); +#if TINY_GSM_USE_WIFI + modem.networkDisconnect(); + SerialMon.println(F("WiFi disconnected")); +#endif +#if TINY_GSM_USE_GPRS modem.gprsDisconnect(); SerialMon.println(F("GPRS disconnected")); +#endif SerialMon.println(); SerialMon.println(F("************************")); From dac86a22cd1b149ab32c2e0f28d39d7bcb1d0336 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 27 Aug 2019 16:39:29 -0400 Subject: [PATCH 02/37] Fix all Wextra warnings --- src/TinyGsmClientA6.h | 27 ++++++++-- src/TinyGsmClientBG96.h | 23 +++++++-- src/TinyGsmClientESP8266.h | 17 ++++--- src/TinyGsmClientM590.h | 24 +++++++-- src/TinyGsmClientM95.h | 30 ++++++++--- src/TinyGsmClientMC60.h | 24 +++++++-- src/TinyGsmClientSIM5360.h | 24 +++++++-- src/TinyGsmClientSIM7000.h | 22 ++++++-- src/TinyGsmClientSIM7600.h | 84 +++++++++++++++++-------------- src/TinyGsmClientSIM800.h | 15 +++++- src/TinyGsmClientSaraR4.h | 8 ++- src/TinyGsmClientSequansMonarch.h | 18 ++++++- src/TinyGsmClientUBLOX.h | 4 ++ src/TinyGsmClientXBee.h | 19 ++++++- 14 files changed, 253 insertions(+), 86 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index e20c973..fa22c5e 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -122,7 +122,7 @@ public: { memset(sockets, 0, sizeof(sockets)); } - + virtual ~TinyGsmA6() {} /* @@ -135,20 +135,38 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } + sendAT(GF("&FZE0")); // Factory + Reset + Echo Off if (waitResponse() != 1) { return false; } - sendAT(GF("+CMEE=0")); // Turn off verbose errors + +#ifdef TINY_GSM_DEBUG + sendAT(GF("+CMEE=2")); // turn on verbose error codes +#else + sendAT(GF("+CMEE=0")); // turn off error codes +#endif waitResponse(); sendAT(GF("+CMER=3,0,0,2")); // Set unsolicited result code output destination waitResponse(); + DBG(GF("### Modem:"), getModemName()); - getSimStatus(); - return true; + + int ret = getSimStatus(); + // if the sim isn't ready and a pin has been provided, try to unlock the sim + if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) { + simUnlock(pin); + return (getSimStatus() == SIM_READY); + } + // if the sim is ready, or it's locked but no pin has been provided, return + // true + else { + return (ret == SIM_READY || ret == SIM_LOCKED); + } } String getModemName() { @@ -525,6 +543,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() } chargeState = stream.readStringUntil(',').toInt(); percent = stream.readStringUntil('\n').toInt(); + milliVolts = 0; // Wait for final OK waitResponse(); return true; diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index c54ec08..5964e64 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -158,16 +158,29 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } + sendAT(GF("&FZE0")); // Factory + Reset + Echo Off if (waitResponse() != 1) { return false; } + DBG(GF("### Modem:"), getModemName()); - getSimStatus(); - return true; + + int ret = getSimStatus(); + // if the sim isn't ready and a pin has been provided, try to unlock the sim + if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) { + simUnlock(pin); + return (getSimStatus() == SIM_READY); + } + // if the sim is ready, or it's locked but no pin has been provided, return + // true + else { + return (ret == SIM_READY || ret == SIM_LOCKED); + } } String getModemName() { @@ -497,10 +510,10 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED() protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, - bool ssl = false, int timeout_s = 20) - { + bool ssl = false, int timeout_s = 20) { + if (ssl) DBG("SSL not yet supported on this module!"); int rsp; - uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; // (1-16), (0-11),"TCP/UDP/TCP LISTENER/UDP SERVICE", // "/",,,(0-2 0=buffer) diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index c14ec8b..2e567e3 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -31,15 +31,14 @@ static unsigned TINY_GSM_TCP_KEEP_ALIVE = 120; // 4 : the TCP or UDP transmission of ESP8266 station disconnected // 5 : ESP8266 station did NOT connect to an AP enum RegStatus { - REG_OK_IP = 2, - REG_OK_TCP = 3, - REG_UNREGISTERED = 4, - REG_DENIED = 5, - REG_UNKNOWN = 6, + REG_OK_IP = 2, + REG_OK_TCP = 3, + REG_OK_NO_TCP = 4, + REG_DENIED = 5, + REG_UNKNOWN = 6, }; - class TinyGsmESP8266 { @@ -157,6 +156,9 @@ public: if (!testAT()) { return false; } + if (pin != NULL) { + DBG("ESP8266 modules do not use an unlock pin!"); + } sendAT(GF("E0")); // Echo Off if (waitResponse() != 1) { return false; @@ -249,7 +251,8 @@ TINY_GSM_MODEM_MAINTAIN_LISTEN() RegStatus getRegistrationStatus() { sendAT(GF("+CIPSTATUS")); if (waitResponse(3000, GF("STATUS:")) != 1) return REG_UNKNOWN; - int status = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), GF("5")); + int status = + waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), GF("5")); waitResponse(); // Returns an OK after the status return (RegStatus)status; } diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index 42e6ca0..91d0bde 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -133,20 +133,36 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } + sendAT(GF("&FZE0")); // Factory + Reset + Echo Off if (waitResponse() != 1) { return false; } + #ifdef TINY_GSM_DEBUG - sendAT(GF("+CMEE=2")); - waitResponse(); + sendAT(GF("+CMEE=2")); // turn on verbose error codes +#else + sendAT(GF("+CMEE=0")); // turn off error codes #endif + waitResponse(); + DBG(GF("### Modem:"), getModemName()); - getSimStatus(); - return true; + + int ret = getSimStatus(); + // if the sim isn't ready and a pin has been provided, try to unlock the sim + if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) { + simUnlock(pin); + return (getSimStatus() == SIM_READY); + } + // if the sim is ready, or it's locked but no pin has been provided, return + // true + else { + return (ret == SIM_READY || ret == SIM_LOCKED); + } } String getModemName() { diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 2f52589..7e9bf93 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -157,20 +157,36 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } + sendAT(GF("&FZE0")); // Factory + Reset + Echo Off if (waitResponse() != 1) { return false; } + #ifdef TINY_GSM_DEBUG - sendAT(GF("+CMEE=2")); - waitResponse(); + sendAT(GF("+CMEE=2")); // turn on verbose error codes +#else + sendAT(GF("+CMEE=0")); // turn off error codes #endif + waitResponse(); + DBG(GF("### Modem:"), getModemName()); - getSimStatus(); - return true; + + int ret = getSimStatus(); + // if the sim isn't ready and a pin has been provided, try to unlock the sim + if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) { + simUnlock(pin); + return (getSimStatus() == SIM_READY); + } + // if the sim is ready, or it's locked but no pin has been provided, return + // true + else { + return (ret == SIM_READY || ret == SIM_LOCKED); + } } String getModemName() { @@ -557,9 +573,9 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED() protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, - bool ssl = false, int timeout_s = 75) - { - uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; + bool ssl = false, int timeout_s = 75) { + if (ssl) DBG("SSL not yet supported on this module!"); + uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port); int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index adac7e9..c0c13cf 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -161,18 +161,32 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } + sendAT(GF("&FZ")); // Factory + Reset waitResponse(); + sendAT(GF("E0")); // Echo Off if (waitResponse() != 1) { return false; } + DBG(GF("### Modem:"), getModemName()); - getSimStatus(); - return true; + + int ret = getSimStatus(); + // if the sim isn't ready and a pin has been provided, try to unlock the sim + if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) { + simUnlock(pin); + return (getSimStatus() == SIM_READY); + } + // if the sim is ready, or it's locked but no pin has been provided, return + // true + else { + return (ret == SIM_READY || ret == SIM_LOCKED); + } } String getModemName() { @@ -563,9 +577,9 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED() protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, - bool ssl = false, int timeout_s = 75) - { - uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; + bool ssl = false, int timeout_s = 75) { + if (ssl) DBG("SSL not yet supported on this module!"); + uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port); int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index a19b83a..e97df2c 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -142,16 +142,29 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } + sendAT(GF("E0")); // Echo Off if (waitResponse() != 1) { return false; } + DBG(GF("### Modem:"), getModemName()); - getSimStatus(); - return true; + + int ret = getSimStatus(); + // if the sim isn't ready and a pin has been provided, try to unlock the sim + if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) { + simUnlock(pin); + return (getSimStatus() == SIM_READY); + } + // if the sim is ready, or it's locked but no pin has been provided, return + // true + else { + return (ret == SIM_READY || ret == SIM_LOCKED); + } } String getModemName() { @@ -640,17 +653,20 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, - bool ssl = false, int timeout_s = 75) { + bool ssl = false, int timeout_s = 15) { // Make sure we'll be getting data manually on this connection sendAT(GF("+CIPRXGET=1")); if (waitResponse() != 1) { return false; } + if (ssl) DBG("SSL not yet supported on this module!"); + // Establish a connection in multi-socket mode + uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; sendAT(GF("+CIPOPEN="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port); // The reply is +CIPOPEN: ## of socket created - if (waitResponse(15000L, GF(GSM_NL "+CIPOPEN:")) != 1) { + if (waitResponse(timeout_ms, GF(GSM_NL "+CIPOPEN:")) != 1) { return false; } return true; diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index d6339af..90602db 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -166,16 +166,29 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } + sendAT(GF("E0")); // Echo Off if (waitResponse() != 1) { return false; } + DBG(GF("### Modem:"), getModemName()); - getSimStatus(); - return true; + + int ret = getSimStatus(); + // if the sim isn't ready and a pin has been provided, try to unlock the sim + if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) { + simUnlock(pin); + return (getSimStatus() == SIM_READY); + } + // if the sim is ready, or it's locked but no pin has been provided, return + // true + else { + return (ret == SIM_READY || ret == SIM_LOCKED); + } } String getModemName() { @@ -801,8 +814,9 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, - bool ssl = false, int timeout_s = 75) - { + bool ssl = false, int timeout_s = 75) { + if (ssl) DBG("SSL not yet supported on this module!"); + int rsp; uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port); diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index 94026ee..0a344ed 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -142,16 +142,29 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } + sendAT(GF("E0")); // Echo Off if (waitResponse() != 1) { return false; } + DBG(GF("### Modem:"), getModemName()); - getSimStatus(); - return true; + + int ret = getSimStatus(); + // if the sim isn't ready and a pin has been provided, try to unlock the sim + if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) { + simUnlock(pin); + return (getSimStatus() == SIM_READY); + } + // if the sim is ready, or it's locked but no pin has been provided, return + // true + else { + return (ret == SIM_READY || ret == SIM_LOCKED); + } } String getModemName() { @@ -555,7 +568,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() } // get GPS informations - bool getGPS(float *lat, float *lon, float *speed=0, int *alt=0, int *vsat=0, int *usat=0) { + bool getGPS(float *lat, float *lon, float *speed=0, int *alt=0) { //String buffer = ""; bool fix = false; @@ -567,14 +580,14 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() //stream.readStringUntil(','); // mode if ( stream.readStringUntil(',').toInt() == 1 ) fix = true; stream.readStringUntil(','); //gps - stream.readStringUntil(','); // glonass - stream.readStringUntil(','); // beidu + stream.readStringUntil(','); // glonass + stream.readStringUntil(','); // beidu *lat = stream.readStringUntil(',').toFloat(); //lat - stream.readStringUntil(','); // N/S + stream.readStringUntil(','); // N/S *lon = stream.readStringUntil(',').toFloat(); //lon - stream.readStringUntil(','); // E/W - stream.readStringUntil(','); // date - stream.readStringUntil(','); // UTC time + stream.readStringUntil(','); // E/W + stream.readStringUntil(','); // date + stream.readStringUntil(','); // UTC time if (alt != NULL) *alt = stream.readStringUntil(',').toFloat(); //alt if (speed != NULL) *speed = stream.readStringUntil(',').toFloat(); //speed stream.readStringUntil(','); //course @@ -582,8 +595,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() stream.readStringUntil(',');//PDOP stream.readStringUntil(',');//HDOP stream.readStringUntil(',');//VDOP - //if (vsat != NULL) *vsat = stream.readStringUntil(',').toInt(); //viewed satelites - //if (usat != NULL) *usat = stream.readStringUntil(',').toInt(); //used satelites stream.readStringUntil('\n'); waitResponse(); @@ -610,7 +621,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() // Wait for final OK waitResponse(); // Return millivolts - uint16_t res = voltage*1000; + uint16_t res = voltage*1000; return res; } @@ -618,16 +629,11 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() uint8_t getBattChargeState() TINY_GSM_ATTR_NOT_AVAILABLE; - bool getBattStats(uint8_t &chargeState, int8_t &percent, uint16_t &milliVolts) { - sendAT(GF("+CBC?")); - if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { - return false; - } - // get voltage in VOLTS - float voltage = stream.readStringUntil('\n').toFloat(); - milliVolts = voltage*1000; - // Wait for final OK - waitResponse(); + bool getBattStats(uint8_t& chargeState, int8_t& percent, + uint16_t& milliVolts) { + chargeState = 0; + percent = 0; + milliVolts = getBattVoltage(); return true; } @@ -649,22 +655,24 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() */ protected: - - bool modemConnect(const char* host, uint16_t port, uint8_t mux, - bool ssl = false, int timeout_s = 75) { - // Make sure we'll be getting data manually on this connection - sendAT(GF("+CIPRXGET=1")); - if (waitResponse() != 1) { - return false; - } - - // Establish a connection in multi-socket mode - sendAT(GF("+CIPOPEN="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port); - // The reply is +CIPOPEN: ## of socket created - if (waitResponse(15000L, GF(GSM_NL "+CIPOPEN:")) != 1) { - return false; - } - return true; + bool modemConnect(const char* host, uint16_t port, uint8_t mux, + bool ssl = false, int timeout_s = 15) { + if (ssl) DBG("SSL not yet supported on this module!"); + // Make sure we'll be getting data manually on this connection + sendAT(GF("+CIPRXGET=1")); + if (waitResponse() != 1) { + return false; + } + + // Establish a connection in multi-socket mode + uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; + sendAT(GF("+CIPOPEN="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), + port); + // The reply is +CIPOPEN: ## of socket created + if (waitResponse(timeout_ms, GF(GSM_NL "+CIPOPEN:")) != 1) { + return false; + } + return true; } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index b5f2b6f..5bef12e 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -165,6 +165,7 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } @@ -174,9 +175,19 @@ public: if (waitResponse() != 1) { return false; } + DBG(GF("### Modem:"), getModemName()); - getSimStatus(); - return true; + + int ret = getSimStatus(); + // if the sim isn't ready and a pin has been provided, try to unlock the sim + if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) { + simUnlock(pin); + return (getSimStatus() == SIM_READY); + } + // if the sim is ready, or it's locked but no pin has been provided, return true + else { + return (ret == SIM_READY || ret == SIM_LOCKED); + } } String getModemName() { diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index dec40b1..84b00a9 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -176,9 +176,11 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } + sendAT(GF("E0")); // Echo Off if (waitResponse() != 1) { return false; @@ -191,7 +193,7 @@ public: #endif waitResponse(); - getModemName(); + DBG(GF("### Modem:"), getModemName()); int ret = getSimStatus(); // if the sim isn't ready and a pin has been provided, try to unlock the sim @@ -509,6 +511,8 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED() bool getBattStats(uint8_t &chargeState, int8_t &percent, uint16_t &milliVolts) { percent = getBattPercent(); + chargeState = 0; + milliVolts = 0; return true; } @@ -525,7 +529,7 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED() streamSkipUntil(','); // Skip units (C/F) int16_t res = stream.readStringUntil('\n').toInt(); float temp = -9999; - if (res != 65535) { + if (res != -1) { temp = ((float)res)/10; } return temp; diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index 7810193..efc6c27 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -195,15 +195,29 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } + sendAT(GF("E0")); // Echo Off if (waitResponse() != 1) { return false; } - getSimStatus(); - return true; + + DBG(GF("### Modem:"), getModemName()); + + int ret = getSimStatus(); + // if the sim isn't ready and a pin has been provided, try to unlock the sim + if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) { + simUnlock(pin); + return (getSimStatus() == SIM_READY); + } + // if the sim is ready, or it's locked but no pin has been provided, return + // true + else { + return (ret == SIM_READY || ret == SIM_LOCKED); + } } String getModemName() { diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 3fa2f25..df49ffe 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -176,9 +176,11 @@ public: bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); + if (!testAT()) { return false; } + sendAT(GF("E0")); // Echo Off if (waitResponse() != 1) { return false; @@ -535,7 +537,9 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED() uint8_t getBattChargeState() TINY_GSM_ATTR_NOT_AVAILABLE; bool getBattStats(uint8_t &chargeState, int8_t &percent, uint16_t &milliVolts) { + chargeState = 0; percent = getBattPercent(); + milliVolts = 0; return true; } diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 02d723f..519c04f 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -305,6 +305,10 @@ public: digitalWrite(resetPin, HIGH); } + if (pin != NULL) { + DBG("XBee's do not support SIMs that require an unlock pin!"); + } + XBEE_COMMAND_START_DECORATOR(10, false) sendAT(GF("AP0")); // Put in transparent mode @@ -524,6 +528,9 @@ public: */ bool simUnlock(const char *pin) { // Not supported + if (pin != NULL) { + DBG("XBee's do not support SIMs that require an unlock pin!"); + } return false; } @@ -535,7 +542,7 @@ public: return sendATGetString(GF("IM")); } - SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { + SimStatus getSimStatus() { return SIM_READY; // unsupported } @@ -734,7 +741,14 @@ public: * GPRS functions */ - bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) { + bool gprsConnect(const char* apn, const char* user = NULL, + const char* pwd = NULL) { + if (user != NULL) { + DBG("XBee's do not support SIMs that a user name/password!"); + } + if (pwd != NULL) { + DBG("XBee's do not support SIMs that a user name/password!"); + } XBEE_COMMAND_START_DECORATOR(5, false) sendAT(GF("AN"), apn); // Set the APN bool success = waitResponse() == 1; @@ -922,6 +936,7 @@ protected: } int16_t modemSend(const void* buff, size_t len, uint8_t mux = 0) { + if (mux != 0) DBG("XBee only supports 1 IP channel in transparent mode!"); stream.write((uint8_t*)buff, len); stream.flush(); return len; From be6304d83011c76fa04719a7bda2d22f72218a15 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 27 Aug 2019 16:39:58 -0400 Subject: [PATCH 03/37] Fixed ESP socket status --- src/TinyGsmClientESP8266.h | 66 +++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 2e567e3..c44c221 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -278,25 +278,26 @@ TINY_GSM_MODEM_MAINTAIN_LISTEN() bool isNetworkConnected() { RegStatus s = getRegistrationStatus(); - return (s == REG_OK_IP || s == REG_OK_TCP); - } - - bool waitForNetwork(unsigned long timeout_ms = 60000L) { - for (unsigned long start = millis(); millis() - start < timeout_ms; ) { - sendAT(GF("+CIPSTATUS")); - int res1 = waitResponse(3000, GF("busy p..."), GF("STATUS:")); - if (res1 == 2) { - int res2 = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), GF("5")); - if (res2 == 2 || res2 == 3) { - waitResponse(); - return true; - } - } - delay(250); + if (s == REG_OK_IP || s == REG_OK_TCP) { + // with these, we're definitely connected + return true; + } + else if (s == REG_OK_NO_TCP) { + // with this, we may or may not be connected + if (getLocalIP() == "") { + return false; + } + else { + return true; + } + } + else { + return false; } - return false; } + TINY_GSM_MODEM_WAIT_FOR_NETWORK() + /* * WiFi functions */ @@ -386,8 +387,37 @@ protected: } bool modemGetConnected(uint8_t mux) { - RegStatus s = getRegistrationStatus(); - return (s == REG_OK_IP || s == REG_OK_TCP); + sendAT(GF("+CIPSTATUS")); + if (waitResponse(3000, GF("STATUS:")) != 1) return REG_UNKNOWN; + int status = + waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), GF("5")); + if (status != 3) { + // 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; + } + return false; + } + bool verified_connections[TINY_GSM_MUX_COUNT] = {0, 0, 0, 0, 0}; + for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) { + uint8_t has_status = waitResponse(GF("+CIPSTATUS:"), GFP(GSM_OK), GFP(GSM_ERROR)); + if (has_status == 1) { + size_t returned_mux = stream.readStringUntil(',').toInt(); + streamSkipUntil(','); // Skip mux + streamSkipUntil(','); // Skip type + streamSkipUntil(','); // Skip remote IP + streamSkipUntil(','); // Skip remote port + streamSkipUntil(','); // Skip local port + streamSkipUntil('\n'); // Skip client/server type + verified_connections[returned_mux] = 1; + } + 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]; + } + return verified_connections[mux]; } public: From 1fe811dac6168dfb8c97fd896e7d4c65cd7cf493 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 27 Aug 2019 17:18:04 -0400 Subject: [PATCH 04/37] filters? --- .gitattributes | 2 ++ .gitignore | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/.gitattributes b/.gitattributes index af7e5e0..7a76c7a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,5 @@ /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore + +*.ino filter=updateUsersAndPasses \ No newline at end of file diff --git a/.gitignore b/.gitignore index 11753c7..62a8eed 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,7 @@ extras/Module Datasheets/* extras/Older Command Manuals/* extras/Older Command Manuals/* extras/At Command Manuals - Unsupported/* + +# Filters +.gitconfig +filters/* From b2cfdb9f480288ed5d4d0ec666b86c3cc895599f Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 27 Aug 2019 19:41:17 -0400 Subject: [PATCH 05/37] Fix all functions --- examples/AllFunctions/AllFunctions.ino | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/AllFunctions/AllFunctions.ino b/examples/AllFunctions/AllFunctions.ino index d2a3565..7a8fb99 100644 --- a/examples/AllFunctions/AllFunctions.ino +++ b/examples/AllFunctions/AllFunctions.ino @@ -60,6 +60,7 @@ #define TINY_GSM_TEST_SMS true #define TINY_GSM_TEST_USSD true #define TINY_GSM_TEST_BATTERY true +#define TINY_GSM_TEST_GPS false // powerdown modem after tests #define TINY_GSM_POWERDOWN false @@ -82,6 +83,11 @@ const char wifiPass[] = "YourWiFiPass"; #include #if TINY_GSM_TEST_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS +#undef TINY_GSM_TEST_GPRS +#undef TINY_GSM_TEST_CALL +#undef TINY_GSM_TEST_SMS +#undef TINY_GSM_TEST_USSD +#undef TINY_GSM_TEST_WIFI #define TINY_GSM_TEST_GPRS false #define TINY_GSM_TEST_CALL false #define TINY_GSM_TEST_SMS false @@ -89,9 +95,15 @@ const char wifiPass[] = "YourWiFiPass"; #define TINY_GSM_TEST_WIFI true #endif #if TINY_GSM_TEST_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI +#undef TINY_GSM_USE_GPRS +#undef TINY_GSM_USE_WIFI #define TINY_GSM_USE_GPRS true #define TINY_GSM_USE_WIFI false #endif +#if TINY_GSM_TEST_GPS && not defined TINY_GSM_MODEM_HAS_GPS +#undef TINY_GSM_TEST_GPS +#define TINY_GSM_TEST_GPS false +#endif #ifdef DUMP_AT_COMMANDS #include @@ -215,7 +227,7 @@ void loop() { DBG("Phone number (USSD):", ussd_phone_num); #endif -#if defined(TINY_GSM_MODEM_HAS_GPS) +#if TINY_GSM_TEST_GPS modem.enableGPS(); String gps_raw = modem.getGPSraw(); modem.disableGPS(); From 3bf857e7580a0bf42585062a2abb416cdc7a4a21 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 27 Aug 2019 19:56:53 -0400 Subject: [PATCH 06/37] version bump --- .github/ISSUE_TEMPLATE.md | 2 +- library.json | 2 +- library.properties | 2 +- src/TinyGsmCommon.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index ce46eb8..91ebdf2 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,7 +23,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/library.json b/library.json index a01c544..8b88bea 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.7", + "version": "0.9.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 46aa51e..705768f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.7 +version=0.9.8 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 658bc68..44c506e 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.9.7" +#define TINYGSM_VERSION "0.9.8" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" From 958c303840923d745495b6e724ed32322184b13b Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 28 Aug 2019 12:41:51 -0400 Subject: [PATCH 07/37] Use async connection with sara r4 - fewer freezes --- src/TinyGsmClientSaraR4.h | 55 +++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 84b00a9..485fb62 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -54,9 +54,7 @@ class GsmClient : public Client public: GsmClient() {} - GsmClient(TinyGsmSaraR4& modem, uint8_t mux = 0) { - init(&modem, mux); - } + GsmClient(TinyGsmSaraR4& modem, uint8_t mux = 0) { init(&modem, mux); } virtual ~GsmClient(){} @@ -170,9 +168,7 @@ public: * Basic functions */ - bool begin(const char* pin = NULL) { - return init(pin); - } + bool begin(const char* pin = NULL) { return init(pin); } bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); @@ -181,7 +177,7 @@ public: return false; } - sendAT(GF("E0")); // Echo Off + sendAT(GF("E0")); // Echo Off if (waitResponse() != 1) { return false; } @@ -226,7 +222,8 @@ public: String name = res1 + String(' ') + res2; DBG("### Modem:", name); - if (!name.startsWith("u-blox SARA-R4") && !name.startsWith("u-blox SARA-N4")) { + if (!name.startsWith("u-blox SARA-R4") && + !name.startsWith("u-blox SARA-N4")) { DBG("### WARNING: You are using the wrong TinyGSM modem!"); } @@ -310,13 +307,14 @@ TINY_GSM_MODEM_GET_SIMCCID_CCID() } SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { - for (unsigned long start = millis(); millis() - start < timeout_ms; ) { + for (unsigned long start = millis(); millis() - start < timeout_ms;) { sendAT(GF("+CPIN?")); if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { delay(1000); continue; } - int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), GF("NOT INSERTED")); + int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), + GF("NOT INSERTED")); waitResponse(); switch (status) { case 2: @@ -349,10 +347,10 @@ TINY_GSM_MODEM_GET_CSQ() TINY_GSM_MODEM_WAIT_FOR_NETWORK() - bool setURAT( uint8_t urat ) { + bool setURAT(uint8_t urat) { // AT+URAT=[,[,<2ndPreferredAct>]] - sendAT(GF("+COPS=2")); // Deregister from network + sendAT(GF("+COPS=2")); // Deregister from network if (waitResponse() != 1) { return false; } @@ -360,7 +358,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() if (waitResponse() != 1) { return false; } - sendAT(GF("+COPS=0")); // Auto-register to the network + sendAT(GF("+COPS=0")); // Auto-register to the network if (waitResponse() != 1) { return false; } @@ -542,11 +540,12 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED() protected: bool modemConnect(const char* host, uint16_t port, uint8_t* mux, - bool ssl = false, int timeout_s = 120) - { + bool ssl = false, int timeout_s = 120) { uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; - sendAT(GF("+USOCR=6")); // create a socket - if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { // reply is +USOCR: ## of socket created + // create a socket + sendAT(GF("+USOCR=6")); + // reply is +USOCR: ## of socket created + if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { return false; } *mux = stream.readStringUntil('\n').toInt(); @@ -566,9 +565,22 @@ protected: //waitResponse(); // connect on the allocated socket - sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port); - int rsp = waitResponse(timeout_ms); - return (1 == rsp); + + // Use an asynchronous open to reduce the number of terminal freeze-ups + // This is still blocking until the URC arrives + // The SARA-R410M-02B with firmware revisions prior to L0.0.00.00.05.08 + // has a nasty habit of locking up when opening a socket, especially if + // the cellular service is poor. + sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port, ",1"); + waitResponse(timeout_ms, GF(GSM_NL "+UUSOCO: ")); + stream.readStringUntil(',').toInt(); // skip repeated mux + int connection_status = stream.readStringUntil('\n').toInt(); + return (0 == connection_status); + + // use synchronous open + // sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port, ",0"); + // int rsp = waitResponse(timeout_ms); + // return (1 == rsp); } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { @@ -632,8 +644,7 @@ protected: // NOTE: Querying a closed socket gives an error "operation not allowed" sendAT(GF("+USOCTL="), mux, ",10"); uint8_t res = waitResponse(GF(GSM_NL "+USOCTL:")); - if (res != 1) - return false; + if (res != 1) return false; streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip type From 2092163a36947618cdfcaa2a3fb8a6a02d4a1d1e Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 28 Aug 2019 13:04:44 -0400 Subject: [PATCH 08/37] Check for non-empty pin --- examples/MqttClient/MqttClient.ino | 4 ++-- src/TinyGsmClientESP8266.h | 2 +- src/TinyGsmClientXBee.h | 10 +++++----- src/TinyGsmCommon.h | 9 ++++++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/MqttClient/MqttClient.ino b/examples/MqttClient/MqttClient.ino index 12649b7..1e269d8 100644 --- a/examples/MqttClient/MqttClient.ino +++ b/examples/MqttClient/MqttClient.ino @@ -73,8 +73,8 @@ //#define TINY_GSM_YIELD() { delay(2); } // Define how you're planning to connect to the internet -#define TINY_GSM_USE_GPRS false -#define TINY_GSM_USE_WIFI true +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false // set GSM PIN, if any #define GSM_PIN "" diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index c44c221..f701e8d 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -156,7 +156,7 @@ public: if (!testAT()) { return false; } - if (pin != NULL) { + if (pin && strlen(pin) > 0) { DBG("ESP8266 modules do not use an unlock pin!"); } sendAT(GF("E0")); // Echo Off diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 519c04f..4d4eaa9 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -305,7 +305,7 @@ public: digitalWrite(resetPin, HIGH); } - if (pin != NULL) { + if (pin && strlen(pin) > 0) { DBG("XBee's do not support SIMs that require an unlock pin!"); } @@ -528,7 +528,7 @@ public: */ bool simUnlock(const char *pin) { // Not supported - if (pin != NULL) { + if (pin && strlen(pin) > 0) { DBG("XBee's do not support SIMs that require an unlock pin!"); } return false; @@ -687,7 +687,7 @@ public: //nh For no pwd don't set setscurity or pwd if (ssid == NULL) retVal = false;; - if (pwd != NULL) + if (pwd && strlen(pwd) > 0) { sendAT(GF("EE"), 2); // Set security to WPA2 if (waitResponse() != 1) retVal = false; @@ -743,10 +743,10 @@ public: bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) { - if (user != NULL) { + if (user && strlen(user) > 0) { DBG("XBee's do not support SIMs that a user name/password!"); } - if (pwd != NULL) { + if (pwd && strlen(pwd) > 0) { DBG("XBee's do not support SIMs that a user name/password!"); } XBEE_COMMAND_START_DECORATOR(5, false) diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 44c506e..ba3b43e 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -490,9 +490,12 @@ String TinyGsmDecodeHex16bit(String &instr) { // Unlocks a sim via the 3GPP TS command AT+CPIN #define TINY_GSM_MODEM_SIM_UNLOCK_CPIN() \ - bool simUnlock(const char *pin) { \ - sendAT(GF("+CPIN=\""), pin, GF("\"")); \ - return waitResponse() == 1; \ + bool simUnlock(const char *pin) { \ + if (pin && strlen(pin) > 0) { \ + sendAT(GF("+CPIN=\""), pin, GF("\"")); \ + return waitResponse() == 1; \ + } \ + return true; \ } From 9ea8fd358c0055dbf1e77e41d812a08309ce4896 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 28 Aug 2019 16:15:09 -0400 Subject: [PATCH 09/37] Not always resetting socket timeout on XBee --- README.md | 4 ++-- src/TinyGsmClientXBee.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 867fdf8..5739b95 100644 --- a/README.md +++ b/README.md @@ -79,9 +79,9 @@ Watch this repo for new updates! And of course, contributions are welcome ;) - UDP - Not yet supported on any module, though it may be some day - SSL/TLS (HTTPS) - - Supported on¹: + - Supported on: - SIM800, u-Blox, XBee _cellular_, ESP8266, and Sequans Monarch - ¹ - only some device models or firmware revisions have this feature (SIM8xx R14.18, A7, etc.) + - Note: only some device models or firmware revisions have this feature (SIM8xx R14.18, A7, etc.) - Not yet supported on: - Quectel modems, SIM7000, SIM5360/5320/7100/7500/7600 - Not possible on: diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 4d4eaa9..3e767b9 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -131,7 +131,9 @@ public: // For cellular models, per documentation: If you change the TM (socket // timeout) value while in Transparent Mode, the current connection is // immediately closed. - at->sendAT(GF("TM64")); // Set socket timeout (using Digi default of 10 seconds) + at->sendAT(GF("TM")); // Get socket timeout + String timeoutUsed = at->readResponseString(5000L); + at->sendAT(GF("TM"), timeoutUsed); // Re-set socket timeout at->waitResponse(maxWaitMs); // This response can be slow at->writeChanges(); at->exitCommand(); From c4b67643ffb94125b4f711e193c8989701c1cf82 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 28 Aug 2019 16:16:28 -0400 Subject: [PATCH 10/37] renamed getHostIP to lookupHostIP --- src/TinyGsmClientXBee.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 3e767b9..f18a66f 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -834,8 +834,9 @@ public: protected: - IPAddress getHostIP(const char* host, int timeout_s = 45) { - String strIP; strIP.reserve(16); + IPAddress lookupHostIP(const char* host, int timeout_s = 45) { + String strIP; + strIP.reserve(16); unsigned long startMillis = millis(); uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; bool gotIP = false; @@ -879,7 +880,7 @@ protected: // If we don't have a good IP for the host, we need to do a DNS search if (savedHostIP == IPAddress(0,0,0,0)) { - savedHostIP = getHostIP(host, timeout_s); // This will return 0.0.0.0 if lookup fails + savedHostIP = lookupHostIP(host, timeout_s); // This will return 0.0.0.0 if lookup fails } // If we now have a valid IP address, use it to connect From bd14270277badc0f4d503a6be470fc3c98d4b81f Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 28 Aug 2019 16:29:08 -0400 Subject: [PATCH 11/37] Doing a better job of detecting XBee socket state --- src/TinyGsmClientXBee.h | 200 +++++++++++++++++++++++++++++++++------- 1 file changed, 165 insertions(+), 35 deletions(-) diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index f18a66f..5d14c96 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -120,6 +120,8 @@ public: virtual void stop(uint32_t maxWaitMs) { at->streamClear(); // Empty anything in the buffer + // empty the saved currently-in-use destination address + at->savedOperatingIP = IPAddress(0, 0, 0, 0); at->commandMode(); // For WiFi models, there's no direct way to close the socket. This is a // hack to shut the socket by setting the timeout to zero. @@ -216,6 +218,10 @@ public: return true; } return sock_connected; + // NOTE: We dont't check or return + // modemGetConnected() because we don't + // want to go into command mode. + // return at->modemGetConnected(); } virtual operator bool() { return connected(); } @@ -832,7 +838,31 @@ public: * Client related functions */ -protected: + protected: + + int16_t getConnectionIndicator() { + XBEE_COMMAND_START_DECORATOR(5, false) + sendAT(GF("CI")); + int16_t intRes = readResponseInt(); + XBEE_COMMAND_END_DECORATOR + return intRes; + } + + IPAddress getOperatingIP() { + String strIP; + strIP.reserve(16); + + XBEE_COMMAND_START_DECORATOR(5, IPAddress(0, 0, 0, 0)) + sendAT(GF("OD")); + strIP = stream.readStringUntil('\r'); // read result + strIP.trim(); + XBEE_COMMAND_END_DECORATOR + + if (strIP != "" && strIP != GF("ERROR")) { + return TinyGsmIpFromString(strIP); + } else + return IPAddress(0, 0, 0, 0); + } IPAddress lookupHostIP(const char* host, int timeout_s = 45) { String strIP; @@ -867,8 +897,6 @@ protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux = 0, bool ssl = false, int timeout_s = 75) { - unsigned long startMillis = millis(); - uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; bool retVal = false; XBEE_COMMAND_START_DECORATOR(5, false) @@ -885,7 +913,7 @@ protected: // If we now have a valid IP address, use it to connect if (savedHostIP != IPAddress(0,0,0,0)) { // Only re-set connection information if we have an IP address - retVal = modemConnect(savedHostIP, port, mux, ssl, timeout_ms - (millis() - startMillis)); + retVal = modemConnect(savedHostIP, port, mux, ssl); } XBEE_COMMAND_END_DECORATOR @@ -893,13 +921,19 @@ protected: return retVal; } - bool modemConnect(IPAddress ip, uint16_t port, uint8_t mux = 0, bool ssl = false, int timeout_s = 75) { - + bool modemConnect(IPAddress ip, uint16_t port, uint8_t mux = 0, + bool ssl = false, int timeout_s = 75) { bool success = true; - uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; + + if (timeout_s != 75) DBG("Timeout doesn't apply here."); + + // empty the saved currelty-in-use destination address + savedOperatingIP = IPAddress(0, 0, 0, 0); + XBEE_COMMAND_START_DECORATOR(5, false) - if (ip != savedIP) { // Can skip almost everything if there's no change in the IP address + if (ip != savedIP) { // Can skip almost everything if there's no + // change in the IP address savedIP = ip; // Set the newly requested IP address String host; host.reserve(16); host += ip[0]; @@ -926,11 +960,12 @@ protected: success &= writeChanges(); } - for (unsigned long start = millis(); millis() - start < timeout_ms; ) { - if (modemGetConnected()) { - sockets[mux]->sock_connected = true; - break; - } + // we'll accept either unknown or connected + uint16_t ci = getConnectionIndicator(); + success &= (ci == 0x00 || ci == 0xFF || ci == 0x28); + + if (success) { + sockets[mux]->sock_connected = true; } XBEE_COMMAND_END_DECORATOR @@ -942,6 +977,17 @@ protected: if (mux != 0) DBG("XBee only supports 1 IP channel in transparent mode!"); stream.write((uint8_t*)buff, len); stream.flush(); + + // After a send, verify the outgoing ip if it isn't set + if (savedOperatingIP == IPAddress(0, 0, 0, 0)) { + modemGetConnected(); + } + // After sending several characters, also re-check + // NOTE: I'm intentionally not checking after every single character! + else if (len > 5) { + modemGetConnected(); + } + return len; } @@ -955,17 +1001,11 @@ protected: XBEE_COMMAND_START_DECORATOR(5, false) - // Verify that we're connected to the *right* IP address - // We might be connected - but to the wrong thing - // NOTE: In transparent mode, there is only one connection possible - no multiplex - // String strIP; strIP.reserve(16); - // sendAT(GF("DL")); - // strIP = stream.readStringUntil('\r'); // read result - // if (TinyGsmIpFromString(strIP) != savedIP) return exitAndFail(); - if (beeType == XBEE_UNKNOWN) getSeries(); // Need to know the bee type to interpret response - switch (beeType){ // The wifi be can only say if it's connected to the netowrk + switch (beeType){ + + // The wifi be can only say if it's connected to the netowrk case XBEE_S6B_WIFI: { RegStatus s = getRegistrationStatus(); XBEE_COMMAND_END_DECORATOR @@ -974,22 +1014,111 @@ protected: } return (s == REG_OK); // if it's connected, we hope the sockets are too } - default: { // Cellular XBee's - sendAT(GF("CI")); - int16_t intRes = readResponseInt(); + + // Cellular XBee's + default: { + int16_t ci = getConnectionIndicator(); + // Get the operating destination address + IPAddress od = getOperatingIP(); XBEE_COMMAND_END_DECORATOR - switch(intRes) { - case 0x00: // 0x00 = The socket is definitely open - case 0x28: // 0x28 = "Unknown." - case 0xFF: // 0xFF = No known status - this is always returned prior to sending data + + switch(ci) { + + // 0x00 = The socket is definitely open + case 0x00: { + savedOperatingIP = od; + // but it's possible the socket is set to the wrong place + if (od != IPAddress(0, 0, 0, 0) && od != savedIP) { + sockets[0]->stop(); + return false; + } return true; - case 0x02: // 0x02 = Invalid parameters (bad IP/host) - case 0x12: // 0x12 = DNS query lookup failure - case 0x25: // 0x25 = Unknown server - DNS lookup failed (0x22 for UDP socket!) - savedIP = IPAddress(0,0,0,0); // force a lookup next time! - default: // If it's anything else (inc 0x02, 0x12, and 0x25)... - sockets[0]->sock_connected = false; // ...it's definitely NOT connected + } + + // 0x28 = "Unknown." + // 0xFF = No known status - always returned prior to sending data + case 0x28: + case 0xFF: { + // If we previously had an operating destination and we no longer do, + // the socket must have closed + if (od == IPAddress(0, 0, 0, 0) && savedOperatingIP != IPAddress(0, 0, 0, 0)) { + savedOperatingIP = od; + sockets[0]->sock_connected = false; + return false; + } + // else if the operating destination exists, but is wrong + // we need to close and re-open + else if (od != IPAddress(0, 0, 0, 0) && od != savedIP) { + sockets[0]->stop(); + return false; + } + // else if the operating destination exists and matches, we're + // good to go + else if (od != IPAddress(0, 0, 0, 0) && od == savedIP) { + savedOperatingIP = od; + return true; + } + // If we never had an operating destination, then sock may be open + // but data never sent - this is the dreaded "we don't know" + else { + savedOperatingIP = od; + return true; + } + + // // Ask for information about any open sockets + // sendAT(GF("SI")); + // String open_socks = stream.readStringUntil('\r'); + // open_socks.replace(GSM_NL, ""); + // open_socks.trim(); + // if (open_socks != "") { + // // In transparent mode, only socket 0 should be possible + // sendAT(GF("SI0")); + // // read socket it + // String sock_id = stream.readStringUntil('\r'); + // // read socket state + // String sock_state = stream.readStringUntil('\r'); + // // read socket protocol (TCP/UDP) + // String sock_protocol = stream.readStringUntil('\r'); + // // read local port number + // String local_port = stream.readStringUntil('\r'); + // // read remote port number + // String remote_port = stream.readStringUntil('\r'); + // // read remote ip address + // String remoted_address = + // stream.readStringUntil('\r'); // read result + // stream.readStringUntil('\r'); // final carriage return + // } + } + + // 0x21 = User closed + // 0x27 = Connection lost + // If the connection is lost or timed out on our side, + // we force close so it can reopen + case 0x21 : + case 0x27 : { + Serial.println("Here!"); + sendAT(GF("TM")); // Get socket timeout + String timeoutUsed = readResponseString(5000L); + sendAT(GF("TM"), timeoutUsed); // Re-set socket timeout + waitResponse(5000L); // This response can be slow + } + + // 0x02 = Invalid parameters (bad IP/host) + // 0x12 = DNS query lookup failure + // 0x25 = Unknown server - DNS lookup failed (0x22 for UDP socket!) + case 0x02: + case 0x12: + case 0x25: { + savedIP = IPAddress(0, 0, 0, 0); // force a lookup next time! + } + + // If it's anything else (inc 0x02, 0x12, and 0x25)... + // it's definitely NOT connected + default: { + sockets[0]->sock_connected = false; + savedOperatingIP = od; return false; + } } } } @@ -1193,6 +1322,7 @@ protected: IPAddress savedIP; String savedHost; IPAddress savedHostIP; + IPAddress savedOperatingIP; bool inCommandMode; uint32_t lastCommandModeMillis; GsmClient* sockets[TINY_GSM_MUX_COUNT]; From bf9bd360808015fb7b35421eae45526f2635700b Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 28 Aug 2019 16:59:35 -0400 Subject: [PATCH 12/37] version bump --- .github/ISSUE_TEMPLATE.md | 2 +- library.json | 2 +- library.properties | 2 +- src/TinyGsmCommon.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 91ebdf2..043bce1 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,7 +23,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/library.json b/library.json index 8b88bea..5424ecd 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.8", + "version": "0.9.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 705768f..ad6e03e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.8 +version=0.9.9 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index ba3b43e..f2cbba8 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.9.8" +#define TINYGSM_VERSION "0.9.9" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" From a55dbaa7dbedba28aa51d48dd43e2c96ed420ed8 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 28 Aug 2019 19:36:53 -0400 Subject: [PATCH 13/37] Extra braces --- src/TinyGsmClientBG96.h | 12 ++++++++---- src/TinyGsmClientM95.h | 6 ++++-- src/TinyGsmClientSIM7000.h | 31 ++++++++++++++++--------------- src/TinyGsmClientSIM7600.h | 5 ++++- src/TinyGsmClientXBee.h | 8 ++++++-- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 5964e64..521e5db 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -509,10 +509,12 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED() protected: - bool modemConnect(const char* host, uint16_t port, uint8_t mux, + bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false, int timeout_s = 20) { - if (ssl) DBG("SSL not yet supported on this module!"); - int rsp; + if (ssl) { + DBG("SSL not yet supported on this module!"); + } + int rsp; uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; // (1-16), (0-11),"TCP/UDP/TCP LISTENER/UDP SERVICE", @@ -570,7 +572,9 @@ protected: streamSkipUntil(','); // Skip total received streamSkipUntil(','); // Skip have read result = stream.readStringUntil('\n').toInt(); - if (result) DBG("### DATA AVAILABLE:", result, "on", mux); + if (result) { + DBG("### DATA AVAILABLE:", result, "on", mux); + } waitResponse(); } if (!result) { diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 7e9bf93..4d47b8d 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -572,9 +572,11 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED() protected: - bool modemConnect(const char* host, uint16_t port, uint8_t mux, + bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false, int timeout_s = 75) { - if (ssl) DBG("SSL not yet supported on this module!"); + if (ssl) { + DBG("SSL not yet supported on this module!"); + } uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port); int rsp = waitResponse(timeout_ms, diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index 90602db..ac4bc29 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -813,21 +813,22 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() protected: - bool modemConnect(const char* host, uint16_t port, uint8_t mux, - bool ssl = false, int timeout_s = 75) { - if (ssl) DBG("SSL not yet supported on this module!"); - - int rsp; - uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; - sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port); - rsp = waitResponse(timeout_ms, - GF("CONNECT OK" GSM_NL), - GF("CONNECT FAIL" GSM_NL), - GF("ALREADY CONNECT" GSM_NL), - GF("ERROR" GSM_NL), - GF("CLOSE OK" GSM_NL) // Happens when HTTPS handshake fails - ); - return (1 == rsp); + bool modemConnect(const char* host, uint16_t port, uint8_t mux, + bool ssl = false, int timeout_s = 75) { + if (ssl) { + DBG("SSL not yet supported on this module!"); + } + + int rsp; + uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; + sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), + port); + rsp = waitResponse( + timeout_ms, GF("CONNECT OK" GSM_NL), GF("CONNECT FAIL" GSM_NL), + GF("ALREADY CONNECT" GSM_NL), GF("ERROR" GSM_NL), + GF("CLOSE OK" GSM_NL) // Happens when HTTPS handshake fails + ); + return (1 == rsp); } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index 0a344ed..649c6dc 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -655,9 +655,12 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() */ protected: + bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false, int timeout_s = 15) { - if (ssl) DBG("SSL not yet supported on this module!"); + if (ssl) { + DBG("SSL not yet supported on this module!"); + } // Make sure we'll be getting data manually on this connection sendAT(GF("+CIPRXGET=1")); if (waitResponse() != 1) { diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 5d14c96..ed9a8f2 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -925,7 +925,9 @@ public: bool ssl = false, int timeout_s = 75) { bool success = true; - if (timeout_s != 75) DBG("Timeout doesn't apply here."); + if (timeout_s != 75) { + DBG("Timeout doesn't apply here."); + } // empty the saved currelty-in-use destination address savedOperatingIP = IPAddress(0, 0, 0, 0); @@ -974,7 +976,9 @@ public: } int16_t modemSend(const void* buff, size_t len, uint8_t mux = 0) { - if (mux != 0) DBG("XBee only supports 1 IP channel in transparent mode!"); + if (mux != 0) { + DBG("XBee only supports 1 IP channel in transparent mode!"); + } stream.write((uint8_t*)buff, len); stream.flush(); From 1ddbfb99dd29b1018a945aba769326ea4874c924 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Thu, 29 Aug 2019 13:36:32 -0400 Subject: [PATCH 14/37] Add QIMODE to M95 --- .github/ISSUE_TEMPLATE.md | 2 +- library.json | 2 +- library.properties | 2 +- src/TinyGsmClientM95.h | 6 ++++++ src/TinyGsmCommon.h | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 043bce1..029f5b9 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,7 +23,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/library.json b/library.json index 5424ecd..e6ba9c8 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.9", + "version": "0.9.10", "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 ad6e03e..d0f9f29 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.9 +version=0.9.10 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 4d47b8d..b4c1aeb 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -352,6 +352,12 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } + // Select TCP/IP transfer mode + sendAT(GF("+QIMODE=0")); + if (waitResponse() != 1) { + return false; + } + //Enable multiple TCP/IP connections sendAT(GF("+QIMUX=1")); if (waitResponse() != 1) { diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index f2cbba8..cc19e84 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.9.9" +#define TINYGSM_VERSION "0.9.10" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" From 286df108ac026895aa54d4d32a4dd0e4f497f176 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 30 Aug 2019 14:53:54 -0400 Subject: [PATCH 15/37] Minor changes to Quectel ordering --- .github/ISSUE_TEMPLATE.md | 2 +- .gitignore | 3 +++ library.json | 2 +- library.properties | 2 +- src/TinyGsmClientM95.h | 21 +++++++++++++-------- src/TinyGsmClientMC60.h | 22 ++++++++++++++-------- src/TinyGsmCommon.h | 2 +- 7 files changed, 34 insertions(+), 20 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 029f5b9..a4b65d6 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,7 +23,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/.gitignore b/.gitignore index 62a8eed..051117d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ platformio.ini lib/readme.txt include/readme.txt +.atomrc.cson + +# VSCode .vscode/* .vscode/.browse.c_cpp.db* .vscode/c_cpp_properties.json diff --git a/library.json b/library.json index e6ba9c8..b14e6bf 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.10", + "version": "0.9.11", "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 d0f9f29..ecdd25b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.10 +version=0.9.11 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index b4c1aeb..73bccd1 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -348,18 +348,17 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() //Activate GPRS/CSD Context sendAT(GF("+QIACT")); - if (waitResponse(10000) != 1) { + if (waitResponse(60000L) != 1) { return false; } - // Select TCP/IP transfer mode - sendAT(GF("+QIMODE=0")); - if (waitResponse() != 1) { + // Check that we have a local IP address + if (localIP() == IPAddress(0,0,0,0)) { return false; } - //Enable multiple TCP/IP connections - sendAT(GF("+QIMUX=1")); + //Set Method to Handle Received TCP/IP Data - Retrieve Data by Command + sendAT(GF("+QINDI=1")); if (waitResponse() != 1) { return false; } @@ -370,8 +369,14 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } - //Set Method to Handle Received TCP/IP Data - Retrieve Data by Command - sendAT(GF("+QINDI=1")); + // Select TCP/IP transfer mode - NOT transparent mode + sendAT(GF("+QIMODE=0")); + if (waitResponse() != 1) { + return false; + } + + //Enable multiple TCP/IP connections + sendAT(GF("+QIMUX=1")); if (waitResponse() != 1) { return false; } diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index c0c13cf..b0261c7 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -364,8 +364,13 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } - //Enable multiple TCP/IP connections - sendAT(GF("+QIMUX=1")); + // Check that we have a local IP address + if (localIP() == IPAddress(0,0,0,0)) { + return false; + } + + //Set Method to Handle Received TCP/IP Data - Retrieve Data by Command + sendAT(GF("+QINDI=1")); if (waitResponse() != 1) { return false; } @@ -376,18 +381,19 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } - //Set Method to Handle Received TCP/IP Data - Retrieve Data by Command - sendAT(GF("+QINDI=1")); + // Select TCP/IP transfer mode - NOT transparent mode + sendAT(GF("+QIMODE=0")); if (waitResponse() != 1) { return false; } - // Check that we have a local IP address - if (localIP() != IPAddress(0,0,0,0)) { - return true; + //Enable multiple TCP/IP connections + sendAT(GF("+QIMUX=1")); + if (waitResponse() != 1) { + return false; } - return false; + return true; } bool gprsDisconnect() { diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index cc19e84..443abcb 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.9.10" +#define TINYGSM_VERSION "0.9.11" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" From 1651e9f0bc387b163616337812c68a8f90280bef Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 3 Sep 2019 13:17:59 -0400 Subject: [PATCH 16/37] M95 missing comma --- .github/ISSUE_TEMPLATE.md | 2 +- library.json | 2 +- library.properties | 2 +- src/TinyGsmClientM95.h | 5 +++-- src/TinyGsmClientMC60.h | 7 +++++-- src/TinyGsmCommon.h | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index a4b65d6..03e87da 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,7 +23,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/library.json b/library.json index b14e6bf..dce8d6d 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.11", + "version": "0.9.12", "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 ecdd25b..7d55d26 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.11 +version=0.9.12 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 73bccd1..b0564ca 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -589,12 +589,13 @@ protected: DBG("SSL not yet supported on this module!"); } uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; - sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port); + sendAT(GF("+QIOPEN="), mux, GF(",\""), , GF("TCP"), GF("\",\""), host, + GF("\","), port); int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), GF("CONNECT FAIL" GSM_NL), GF("ALREADY CONNECT" GSM_NL)); - return (1 == rsp); + return (1 == rsp); } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index b0261c7..0b8bf9a 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -584,9 +584,12 @@ protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false, int timeout_s = 75) { - if (ssl) DBG("SSL not yet supported on this module!"); + if (ssl) { + DBG("SSL not yet supported on this module!"); + } uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; - sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port); + sendAT(GF("+QIOPEN="), mux, GF(",\""), , GF("TCP"), GF("\",\""), host, + GF("\","), port); int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), GF("CONNECT FAIL" GSM_NL), diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 443abcb..81962c3 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.9.11" +#define TINYGSM_VERSION "0.9.12" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" From 58ff6b42dddb450890bb48e6383000106d7ed4ea Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 3 Sep 2019 13:24:52 -0400 Subject: [PATCH 17/37] Move up QIMODE and QIMUX --- src/TinyGsmClientM95.h | 24 ++++++++++++------------ src/TinyGsmClientMC60.h | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index b0564ca..6ab855b 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -346,6 +346,18 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } + // Select TCP/IP transfer mode - NOT transparent mode + sendAT(GF("+QIMODE=0")); + if (waitResponse() != 1) { + return false; + } + + // Enable multiple TCP/IP connections + sendAT(GF("+QIMUX=1")); + if (waitResponse() != 1) { + return false; + } + //Activate GPRS/CSD Context sendAT(GF("+QIACT")); if (waitResponse(60000L) != 1) { @@ -369,18 +381,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } - // Select TCP/IP transfer mode - NOT transparent mode - sendAT(GF("+QIMODE=0")); - if (waitResponse() != 1) { - return false; - } - - //Enable multiple TCP/IP connections - sendAT(GF("+QIMUX=1")); - if (waitResponse() != 1) { - return false; - } - return true; } diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 0b8bf9a..c474b91 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -358,6 +358,18 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } + // Select TCP/IP transfer mode - NOT transparent mode + sendAT(GF("+QIMODE=0")); + if (waitResponse() != 1) { + return false; + } + + // Enable multiple TCP/IP connections + sendAT(GF("+QIMUX=1")); + if (waitResponse() != 1) { + return false; + } + //Activate GPRS/CSD Context sendAT(GF("+QIACT")); if (waitResponse(60000L) != 1) { @@ -381,18 +393,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } - // Select TCP/IP transfer mode - NOT transparent mode - sendAT(GF("+QIMODE=0")); - if (waitResponse() != 1) { - return false; - } - - //Enable multiple TCP/IP connections - sendAT(GF("+QIMUX=1")); - if (waitResponse() != 1) { - return false; - } - return true; } From 070d6123dadf35b62702d8d1bea78ceefc2392d1 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 4 Sep 2019 11:22:12 -0400 Subject: [PATCH 18/37] Don't check QISACK --- .github/ISSUE_TEMPLATE.md | 2 +- library.json | 2 +- library.properties | 2 +- src/TinyGsmClientM95.h | 43 +++++++++++++++++++-------------------- src/TinyGsmCommon.h | 2 +- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 03e87da..5c6066b 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,7 +23,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/library.json b/library.json index dce8d6d..fecff3d 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.12", + "version": "0.9.13", "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 7d55d26..386f113 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.12 +version=0.9.13 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 6ab855b..af3e78c 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -609,34 +609,33 @@ protected: return 0; } - bool allAcknowledged = false; - // bool failed = false; - while ( !allAcknowledged ) { - sendAT( GF("+QISACK")); - if (waitResponse(5000L, GF(GSM_NL "+QISACK:")) != 1) { - return -1; - } else { - streamSkipUntil(','); /** Skip total */ - streamSkipUntil(','); /** Skip acknowledged data size */ - if ( stream.readStringUntil('\n').toInt() == 0 ) { - allAcknowledged = true; - } - } - } - waitResponse(5000L); + // bool allAcknowledged = false; + // // bool failed = false; + // while ( !allAcknowledged ) { + // sendAT( GF("+QISACK")); + // if (waitResponse(5000L, GF(GSM_NL "+QISACK:")) != 1) { + // return -1; + // } else { + // streamSkipUntil(','); // Skip total length sent on connection + // streamSkipUntil(','); // Skip length already acknowledged by remote + // // Make sure the total length un-acknowledged is 0 + // if ( stream.readStringUntil('\n').toInt() == 0 ) { + // allAcknowledged = true; + // } + // } + // } + // waitResponse(5000L); - // streamSkipUntil(','); // Skip mux - // return stream.readStringUntil('\n').toInt(); return len; // TODO } size_t modemRead(size_t size, uint8_t mux) { // TODO: Does this work???? // AT+QIRD=,,, - // id = GPRS context number - 0, set in GPRS connect - // sc = roll in connection - 1, client of connection - // sid = index of connection - mux - // len = maximum length of data to send + // id = GPRS context number = 0, set in GPRS connect + // sc = role in connection = 1, client of connection + // sid = index of connection = mux + // len = maximum length of data to retrieve sendAT(GF("+QIRD=0,1,"), mux, ',', size); // sendAT(GF("+QIRD="), mux, ',', size); if (waitResponse(GF("+QIRD:")) != 1) { @@ -720,7 +719,7 @@ TINY_GSM_MODEM_STREAM_UTILITIES() } else if (r5 && data.endsWith(r5)) { index = 5; goto finish; - } else if (data.endsWith(GF(GSM_NL "+QIRD:"))) { // TODO: QIRD? or QIRDI? + } else if (data.endsWith(GF(GSM_NL "+QIRDI:"))) { streamSkipUntil(','); // Skip the context streamSkipUntil(','); // Skip the role int mux = stream.readStringUntil('\n').toInt(); diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 81962c3..789eeae 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.9.12" +#define TINYGSM_VERSION "0.9.13" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" From a5b1681304f9a4d26370a581c6207d396608f1df Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 4 Sep 2019 13:19:53 -0400 Subject: [PATCH 19/37] Woops, extra comma --- src/TinyGsmClientM95.h | 2 +- src/TinyGsmClientMC60.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index af3e78c..05367ac 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -589,7 +589,7 @@ protected: DBG("SSL not yet supported on this module!"); } uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; - sendAT(GF("+QIOPEN="), mux, GF(",\""), , GF("TCP"), GF("\",\""), host, + sendAT(GF("+QIOPEN="), mux, GF(",\""), GF("TCP"), GF("\",\""), host, GF("\","), port); int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index c474b91..c294d20 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -588,7 +588,7 @@ protected: DBG("SSL not yet supported on this module!"); } uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; - sendAT(GF("+QIOPEN="), mux, GF(",\""), , GF("TCP"), GF("\",\""), host, + sendAT(GF("+QIOPEN="), mux, GF(",\""), GF("TCP"), GF("\",\""), host, GF("\","), port); int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), From 712d85e7f31d551773c80a503b1b535efcd4109e Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 4 Sep 2019 13:25:07 -0400 Subject: [PATCH 20/37] Fix SARA R4 temp --- src/TinyGsmClientSaraR4.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 485fb62..9117704 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -524,7 +524,6 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED() if (waitResponse(GF(GSM_NL "+UTEMP:")) != 1) { return (float)-9999; } - streamSkipUntil(','); // Skip units (C/F) int16_t res = stream.readStringUntil('\n').toInt(); float temp = -9999; if (res != -1) { @@ -545,7 +544,7 @@ protected: // create a socket sendAT(GF("+USOCR=6")); // reply is +USOCR: ## of socket created - if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { + if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { return false; } *mux = stream.readStringUntil('\n').toInt(); From d44e6b3b98644fdb17946141fdaa5ee303cde113 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Thu, 5 Sep 2019 11:59:32 -0400 Subject: [PATCH 21/37] Async close on R4 --- src/TinyGsmClientSaraR4.h | 72 ++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 9117704..eaf1606 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -93,8 +93,18 @@ TINY_GSM_CLIENT_CONNECT_OVERLOADS() virtual void stop(uint32_t maxWaitMs) { TINY_GSM_CLIENT_DUMP_MODEM_BUFFER() - at->sendAT(GF("+USOCL="), mux); - at->waitResponse((maxWaitMs - (millis() - startMillis))); // NOTE: can take up to 120s to get a response + + // // synchronous close + // at->sendAT(GF("+USOCL="), mux); + // // NOTE: can take up to 120s to get a response + // at->waitResponse((maxWaitMs - (millis() - startMillis))); + // sock_connected = false; + + // faster asynchronous close + // NOT supported on SARA-R404M / SARA-R410M-01B + at->sendAT(GF("+USOCL="), mux, GF(",1")); + // NOTE: can take up to 120s to get a response + at->waitResponse((maxWaitMs - (millis() - startMillis))); sock_connected = false; } @@ -197,7 +207,8 @@ public: simUnlock(pin); return (getSimStatus() == SIM_READY); } - // if the sim is ready, or it's locked but no pin has been provided, return true + // if the sim is ready, or it's locked but no pin has been provided,return + // return true else { return (ret == SIM_READY || ret == SIM_LOCKED); } @@ -382,8 +393,9 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() // serial interface. This is the only command set supported by the LTE-M // and LTE NB-IoT modules (SARA-R4xx, SARA-N4xx) + // Set the authentication if (user && strlen(user) > 0) { - sendAT(GF("+CGAUTH=1,0,\""), user, GF("\",\""), pwd, '"'); // Set the authentication + sendAT(GF("+CGAUTH=1,0,\""), user, GF("\",\""), pwd, '"'); waitResponse(); } @@ -560,8 +572,8 @@ protected: waitResponse(); // Enable KEEPALIVE, 30 sec - //sendAT(GF("+USOSO="), *mux, GF(",6,2,30000")); - //waitResponse(); + // sendAT(GF("+USOSO="), *mux, GF(",6,2,30000")); + // waitResponse(); // connect on the allocated socket @@ -570,6 +582,7 @@ protected: // The SARA-R410M-02B with firmware revisions prior to L0.0.00.00.05.08 // has a nasty habit of locking up when opening a socket, especially if // the cellular service is poor. + // NOT supported on SARA-R404M / SARA-R410M-01B sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port, ",1"); waitResponse(timeout_ms, GF(GSM_NL "+UUSOCO: ")); stream.readStringUntil(',').toInt(); // skip repeated mux @@ -583,7 +596,7 @@ protected: } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { - sendAT(GF("+USOWR="), mux, ',', len); + sendAT(GF("+USOWR="), mux, ',', (uint16_t)len); if (waitResponse(GF("@")) != 1) { return 0; } @@ -594,19 +607,19 @@ protected: if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; } - streamSkipUntil(','); // Skip mux + streamSkipUntil(','); // Skip mux int sent = stream.readStringUntil('\n').toInt(); waitResponse(); // sends back OK after the confirmation of number sent return sent; } size_t modemRead(size_t size, uint8_t mux) { - sendAT(GF("+USORD="), mux, ',', size); + sendAT(GF("+USORD="), mux, ',', (uint16_t)size); if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; } - streamSkipUntil(','); // Skip mux - size_t len = stream.readStringUntil(',').toInt(); + streamSkipUntil(','); // Skip mux + int len = stream.readStringUntil(',').toInt(); streamSkipUntil('\"'); for (size_t i=0; i 0) { TINY_GSM_YIELD(); int a = stream.read(); - if (a <= 0) continue; // Skip 0x00 bytes, just in case + if (a <= 0) continue; // Skip 0x00 bytes, just in case data += (char)a; if (r1 && data.endsWith(r1)) { index = 1; @@ -738,30 +752,32 @@ finish: } data = ""; } - //data.replace(GSM_NL, "/"); - //DBG('<', index, '>', data); + // data.replace(GSM_NL, "/"); + // DBG('<', index, '>', data); return index; } uint8_t waitResponse(uint32_t timeout_ms, - GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), - GsmConstStr r3=GFP(GSM_CME_ERROR), GsmConstStr r4=NULL, GsmConstStr r5=NULL) - { + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), - GsmConstStr r3=GFP(GSM_CME_ERROR), GsmConstStr r4=NULL, GsmConstStr r5=NULL) - { + uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } public: - Stream& stream; + Stream& stream; protected: - GsmClient* sockets[TINY_GSM_MUX_COUNT]; + GsmClient* sockets[TINY_GSM_MUX_COUNT]; }; #endif From 05bee3294a43d9980ac5cdd28c1bd7652b686440 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Thu, 5 Sep 2019 12:03:00 -0400 Subject: [PATCH 22/37] some extra casting around size_t --- src/TinyGsmClientA6.h | 2 +- src/TinyGsmClientBG96.h | 6 +++--- src/TinyGsmClientESP8266.h | 4 ++-- src/TinyGsmClientM590.h | 2 +- src/TinyGsmClientM95.h | 8 ++++---- src/TinyGsmClientMC60.h | 8 ++++---- src/TinyGsmClientSIM5360.h | 10 +++++----- src/TinyGsmClientSIM7000.h | 10 +++++----- src/TinyGsmClientSIM7600.h | 10 +++++----- src/TinyGsmClientSIM800.h | 10 +++++----- src/TinyGsmClientSequansMonarch.h | 6 +++--- src/TinyGsmClientUBLOX.h | 6 +++--- 12 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index fa22c5e..449d330 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -581,7 +581,7 @@ protected: } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { - sendAT(GF("+CIPSEND="), mux, ',', len); + sendAT(GF("+CIPSEND="), mux, ',', (uint16_t)len); if (waitResponse(2000L, GF(GSM_NL ">")) != 1) { return 0; } diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 521e5db..1335667 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -536,7 +536,7 @@ protected: } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { - sendAT(GF("+QISEND="), mux, ',', len); + sendAT(GF("+QISEND="), mux, ',', (uint16_t)len); if (waitResponse(GF(">")) != 1) { return 0; } @@ -550,11 +550,11 @@ protected: } size_t modemRead(size_t size, uint8_t mux) { - sendAT(GF("+QIRD="), mux, ',', size); + sendAT(GF("+QIRD="), mux, ',', (uint16_t)size); if (waitResponse(GF("+QIRD:")) != 1) { return 0; } - size_t len = stream.readStringUntil('\n').toInt(); + int len = stream.readStringUntil('\n').toInt(); for (size_t i=0; i")) != 1) { return 0; } @@ -403,7 +403,7 @@ protected: for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) { uint8_t has_status = waitResponse(GF("+CIPSTATUS:"), GFP(GSM_OK), GFP(GSM_ERROR)); if (has_status == 1) { - size_t returned_mux = stream.readStringUntil(',').toInt(); + int returned_mux = stream.readStringUntil(',').toInt(); streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip type streamSkipUntil(','); // Skip remote IP diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index 91d0bde..f312e59 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -459,7 +459,7 @@ protected: } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { - sendAT(GF("+TCPSEND="), mux, ',', len); + sendAT(GF("+TCPSEND="), mux, ',', (uint16_t)len); if (waitResponse(GF(">")) != 1) { return 0; } diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 05367ac..faa9747 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -599,7 +599,7 @@ protected: } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { - sendAT(GF("+QISEND="), mux, ',', len); + sendAT(GF("+QISEND="), mux, ',', (uint16_t)len); if (waitResponse(GF(">")) != 1) { return 0; } @@ -636,15 +636,15 @@ protected: // sc = role in connection = 1, client of connection // sid = index of connection = mux // len = maximum length of data to retrieve - sendAT(GF("+QIRD=0,1,"), mux, ',', size); - // sendAT(GF("+QIRD="), mux, ',', size); + sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size); + // sendAT(GF("+QIRD="), mux, ',', (uint16_t)size); if (waitResponse(GF("+QIRD:")) != 1) { return 0; } streamSkipUntil(':'); // skip IP address streamSkipUntil(','); // skip port streamSkipUntil(','); // skip connection type (TCP/UDP) - size_t len = stream.readStringUntil('\n').toInt(); // read length + int len = stream.readStringUntil('\n').toInt(); // read length for (size_t i=0; isock_available--; diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index c294d20..ce23b76 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -598,7 +598,7 @@ protected: } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { - sendAT(GF("+QISEND="), mux, ',', len); + sendAT(GF("+QISEND="), mux, ',', (uint16_t)len); if (waitResponse(GF(">")) != 1) { return 0; } @@ -637,15 +637,15 @@ protected: // sc = roll in connection - 1, client of connection // sid = index of connection - mux // len = maximum length of data to send - sendAT(GF("+QIRD=0,1,"), mux, ',', size); - // sendAT(GF("+QIRD="), mux, ',', size); + sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size); + // sendAT(GF("+QIRD="), mux, ',', (uint16_t)size); if (waitResponse(GF("+QIRD:")) != 1) { return 0; } streamSkipUntil(':'); // skip IP address streamSkipUntil(','); // skip port streamSkipUntil(','); // skip connection type (TCP/UDP) - size_t len = stream.readStringUntil('\n').toInt(); // read length + int len = stream.readStringUntil('\n').toInt(); // read length for (size_t i=0; isock_available--; diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index e97df2c..8d27f75 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -673,7 +673,7 @@ protected: } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { - sendAT(GF("+CIPSEND="), mux, ',', len); + sendAT(GF("+CIPSEND="), mux, ',', (uint16_t)len); if (waitResponse(GF(">")) != 1) { return 0; } @@ -690,21 +690,21 @@ protected: size_t modemRead(size_t size, uint8_t mux) { #ifdef TINY_GSM_USE_HEX - sendAT(GF("+CIPRXGET=3,"), mux, ',', size); + sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size); if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; } #else - sendAT(GF("+CIPRXGET=2,"), mux, ',', size); + sendAT(GF("+CIPRXGET=2,"), mux, ',', (uint16_t)size); if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; } #endif streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip mux/cid (connecion id) - size_t len_requested = stream.readStringUntil(',').toInt(); + int len_requested = stream.readStringUntil(',').toInt(); // ^^ Requested number of data bytes (1-1460 bytes)to be read - size_t len_confirmed = stream.readStringUntil('\n').toInt(); + int len_confirmed = stream.readStringUntil('\n').toInt(); // ^^ The data length which not read in the buffer for (size_t i=0; i")) != 1) { return 0; } @@ -847,21 +847,21 @@ protected: size_t modemRead(size_t size, uint8_t mux) { #ifdef TINY_GSM_USE_HEX - sendAT(GF("+CIPRXGET=3,"), mux, ',', size); + sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size); if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; } #else - sendAT(GF("+CIPRXGET=2,"), mux, ',', size); + sendAT(GF("+CIPRXGET=2,"), mux, ',', (uint16_t)size); if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; } #endif streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip mux - size_t len_requested = stream.readStringUntil(',').toInt(); + int len_requested = stream.readStringUntil(',').toInt(); // ^^ Requested number of data bytes (1-1460 bytes)to be read - size_t len_confirmed = stream.readStringUntil('\n').toInt(); + int len_confirmed = stream.readStringUntil('\n').toInt(); // ^^ Confirmed number of data bytes to be read, which may be less than requested. // 0 indicates that no data can be read. // This is actually be the number of bytes that will be remaining after the read diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index 649c6dc..00f6d04 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -679,7 +679,7 @@ protected: } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { - sendAT(GF("+CIPSEND="), mux, ',', len); + sendAT(GF("+CIPSEND="), mux, ',', (uint16_t)len); if (waitResponse(GF(">")) != 1) { return 0; } @@ -696,21 +696,21 @@ protected: size_t modemRead(size_t size, uint8_t mux) { #ifdef TINY_GSM_USE_HEX - sendAT(GF("+CIPRXGET=3,"), mux, ',', size); + sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size); if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; } #else - sendAT(GF("+CIPRXGET=2,"), mux, ',', size); + sendAT(GF("+CIPRXGET=2,"), mux, ',', (uint16_t)size); if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; } #endif streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip mux/cid (connecion id) - size_t len_requested = stream.readStringUntil(',').toInt(); + int len_requested = stream.readStringUntil(',').toInt(); // ^^ Requested number of data bytes (1-1460 bytes)to be read - size_t len_confirmed = stream.readStringUntil('\n').toInt(); + int len_confirmed = stream.readStringUntil('\n').toInt(); // ^^ The data length which not read in the buffer for (size_t i=0; i")) != 1) { return 0; } @@ -827,21 +827,21 @@ protected: size_t modemRead(size_t size, uint8_t mux) { #ifdef TINY_GSM_USE_HEX - sendAT(GF("+CIPRXGET=3,"), mux, ',', size); + sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size); if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; } #else - sendAT(GF("+CIPRXGET=2,"), mux, ',', size); + sendAT(GF("+CIPRXGET=2,"), mux, ',', (uint16_t)size); if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; } #endif streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip mux - size_t len_requested = stream.readStringUntil(',').toInt(); + int len_requested = stream.readStringUntil(',').toInt(); // ^^ Requested number of data bytes (1-1460 bytes)to be read - size_t len_confirmed = stream.readStringUntil('\n').toInt(); + int len_confirmed = stream.readStringUntil('\n').toInt(); // ^^ Confirmed number of data bytes to be read, which may be less than requested. // 0 indicates that no data can be read. // This is actually be the number of bytes that will be remaining after the read diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index efc6c27..433a6a2 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -584,7 +584,7 @@ protected: return 0; } - sendAT(GF("+SQNSSENDEXT="), mux, ',', len); + sendAT(GF("+SQNSSENDEXT="), mux, ',', (uint16_t)len); waitResponse(10000L, GF(GSM_NL "> ")); stream.write((uint8_t*)buff, len); stream.flush(); @@ -619,12 +619,12 @@ protected: size_t modemRead(size_t size, uint8_t mux) { - sendAT(GF("+SQNSRECV="), mux, ',', size); + sendAT(GF("+SQNSRECV="), mux, ',', (uint16_t)size); if (waitResponse(GF("+SQNSRECV: ")) != 1) { return 0; } streamSkipUntil(','); // Skip mux - size_t len = stream.readStringUntil('\n').toInt(); + int len = stream.readStringUntil('\n').toInt(); for (size_t i=0; i_timeout)) { TINY_GSM_YIELD(); } \ diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index df49ffe..579364b 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -583,7 +583,7 @@ protected: } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { - sendAT(GF("+USOWR="), mux, ',', len); + sendAT(GF("+USOWR="), mux, ',', (uint16_t)len); if (waitResponse(GF("@")) != 1) { return 0; } @@ -601,12 +601,12 @@ protected: } size_t modemRead(size_t size, uint8_t mux) { - sendAT(GF("+USORD="), mux, ',', size); + sendAT(GF("+USORD="), mux, ',', (uint16_t)size); if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; } streamSkipUntil(','); // Skip mux - size_t len = stream.readStringUntil(',').toInt(); + int len = stream.readStringUntil(',').toInt(); streamSkipUntil('\"'); for (size_t i=0; i Date: Thu, 5 Sep 2019 13:23:46 -0400 Subject: [PATCH 23/37] Oops, fixed some signed/unsigned comparisons --- src/TinyGsmClientBG96.h | 2 +- src/TinyGsmClientM95.h | 2 +- src/TinyGsmClientMC60.h | 2 +- src/TinyGsmClientSIM5360.h | 6 ++++-- src/TinyGsmClientSIM7000.h | 2 +- src/TinyGsmClientSIM7600.h | 2 +- src/TinyGsmClientSIM800.h | 2 +- src/TinyGsmClientSaraR4.h | 2 +- src/TinyGsmClientSequansMonarch.h | 2 +- src/TinyGsmClientUBLOX.h | 2 +- 10 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 1335667..c9f4510 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -556,7 +556,7 @@ protected: } int len = stream.readStringUntil('\n').toInt(); - for (size_t i=0; isock_available--; // ^^ One less character available after moving from modem's FIFO to our FIFO diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index ce23b76..ae15de1 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -646,7 +646,7 @@ protected: streamSkipUntil(','); // skip port streamSkipUntil(','); // skip connection type (TCP/UDP) int len = stream.readStringUntil('\n').toInt(); // read length - for (size_t i=0; isock_available--; // ^^ One less character available after moving from modem's FIFO to our FIFO diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index 8d27f75..46b5eaf 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -660,7 +660,9 @@ protected: return false; } - if (ssl) DBG("SSL not yet supported on this module!"); + if (ssl) { + DBG("SSL not yet supported on this module!"); + } // Establish a connection in multi-socket mode uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; @@ -706,7 +708,7 @@ protected: // ^^ Requested number of data bytes (1-1460 bytes)to be read int len_confirmed = stream.readStringUntil('\n').toInt(); // ^^ The data length which not read in the buffer - for (size_t i=0; i_timeout)) { TINY_GSM_YIELD(); } diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index d9c5393..ad13af1 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -865,7 +865,7 @@ protected: // ^^ Confirmed number of data bytes to be read, which may be less than requested. // 0 indicates that no data can be read. // This is actually be the number of bytes that will be remaining after the read - for (size_t i=0; i_timeout)) { TINY_GSM_YIELD(); } diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index 00f6d04..b9d767a 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -712,7 +712,7 @@ protected: // ^^ Requested number of data bytes (1-1460 bytes)to be read int len_confirmed = stream.readStringUntil('\n').toInt(); // ^^ The data length which not read in the buffer - for (size_t i=0; i_timeout)) { TINY_GSM_YIELD(); } diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index e45b1d9..c505eca 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -845,7 +845,7 @@ protected: // ^^ Confirmed number of data bytes to be read, which may be less than requested. // 0 indicates that no data can be read. // This is actually be the number of bytes that will be remaining after the read - for (size_t i=0; i_timeout)) { TINY_GSM_YIELD(); } diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index eaf1606..6044713 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -622,7 +622,7 @@ protected: int len = stream.readStringUntil(',').toInt(); streamSkipUntil('\"'); - for (size_t i=0; i_timeout)) { TINY_GSM_YIELD(); } \ char c = stream.read(); \ diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 579364b..09702b1 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -609,7 +609,7 @@ protected: int len = stream.readStringUntil(',').toInt(); streamSkipUntil('\"'); - for (size_t i=0; i Date: Thu, 5 Sep 2019 13:24:02 -0400 Subject: [PATCH 24/37] Implement XBee shutdown --- src/TinyGsmClientXBee.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index ed9a8f2..80ca71e 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -523,8 +523,13 @@ public: XBEE_COMMAND_END_DECORATOR } - bool poweroff() { // Not supported - return false; + bool poweroff() { // NOTE: Not supported for WiFi or older cellular firmware + XBEE_COMMAND_START_DECORATOR(5, false) + sendAT(GF("SD")); + bool ret_val = waitResponse(120000L) == 1; + ret_val &= writeChanges(); + XBEE_COMMAND_END_DECORATOR + return ret_val; } bool radioOff() TINY_GSM_ATTR_NOT_IMPLEMENTED; From 21431da99bcea21530c48b503612db8388a22493 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Thu, 5 Sep 2019 13:32:42 -0400 Subject: [PATCH 25/37] Check AI after XBee shutdown --- src/TinyGsmClientXBee.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 80ca71e..15abb59 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -527,7 +527,9 @@ public: XBEE_COMMAND_START_DECORATOR(5, false) sendAT(GF("SD")); bool ret_val = waitResponse(120000L) == 1; - ret_val &= writeChanges(); + if (ret_val) { + ret_val &= (sendATGetString(GF("AI")) == "2D"); + } XBEE_COMMAND_END_DECORATOR return ret_val; } From 4b0b4cb38adca24e16b80ede51f6fded6033df78 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Thu, 5 Sep 2019 14:02:21 -0400 Subject: [PATCH 26/37] Fix SARA R4 PDP deactivate --- src/TinyGsmClientSaraR4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 6044713..62349ca 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -411,7 +411,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() } bool gprsDisconnect() { - sendAT(GF("+CGACT=1,0")); // Deactivate PDP context 1 + sendAT(GF("+CGACT=0,1")); // Deactivate PDP context 1 if (waitResponse(40000L) != 1) { return false; } From 8e581b6398b7bd08a72dcac13f4657b6d6721e65 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Thu, 5 Sep 2019 14:19:02 -0400 Subject: [PATCH 27/37] deactivate all contexts, but don't check for success --- src/TinyGsmClientSaraR4.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 62349ca..62a2cd9 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -411,9 +411,10 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() } bool gprsDisconnect() { - sendAT(GF("+CGACT=0,1")); // Deactivate PDP context 1 + // sendAT(GF("+CGACT=0,1")); // Deactivate PDP context 1 + sendAT(GF("+CGACT=0")); // Deactivate all contexts if (waitResponse(40000L) != 1) { - return false; + // return false; } sendAT(GF("+CGATT=0")); // detach from GPRS From f3079d1b42d05f8aad0669f31b240a5b781895ab Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 6 Sep 2019 13:51:39 -0400 Subject: [PATCH 28/37] Don't disconnect immediately before connect --- src/TinyGsmClientSaraR4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 62a2cd9..b37e75f 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -381,7 +381,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() */ bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) { - gprsDisconnect(); + // gprsDisconnect(); sendAT(GF("+CGATT=1")); // attach to GPRS if (waitResponse(360000L) != 1) { From c83063fa5dba1f5b75dc605c19ca215843d25f35 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 6 Sep 2019 15:09:49 -0400 Subject: [PATCH 29/37] Fix QIRDI --- .github/ISSUE_TEMPLATE.md | 2 +- library.json | 2 +- library.properties | 2 +- src/TinyGsmClientM95.h | 13 +++++++------ src/TinyGsmClientMC60.h | 13 +++++++------ src/TinyGsmCommon.h | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 5c6066b..729dc17 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,7 +23,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/library.json b/library.json index fecff3d..c9fcf2a 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.13", + "version": "0.9.14", "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 386f113..ed9d8ad 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.13 +version=0.9.14 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 8b091fe..8877625 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -340,12 +340,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } - //Start TCPIP Task and Set APN, User Name and Password - sendAT("+QIREGAPP=\"", apn, "\",\"", user, "\",\"", pwd, "\"" ); - if (waitResponse() != 1) { - return false; - } - // Select TCP/IP transfer mode - NOT transparent mode sendAT(GF("+QIMODE=0")); if (waitResponse() != 1) { @@ -358,6 +352,12 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } + //Start TCPIP Task and Set APN, User Name and Password + sendAT("+QIREGAPP=\"", apn, "\",\"", user, "\",\"", pwd, "\"" ); + if (waitResponse() != 1) { + return false; + } + //Activate GPRS/CSD Context sendAT(GF("+QIACT")); if (waitResponse(60000L) != 1) { @@ -727,6 +727,7 @@ TINY_GSM_MODEM_STREAM_UTILITIES() if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; } + data = ""; } else if (data.endsWith(GF("CLOSED" GSM_NL))) { int nl = data.lastIndexOf(GSM_NL, data.length()-8); int coma = data.indexOf(',', nl+2); diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index ae15de1..61d6a2e 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -352,12 +352,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() sendAT(GF("+CGACT=1,1")); waitResponse(60000L); - //Start TCPIP Task and Set APN, User Name and Password - sendAT("+QIREGAPP=\"", apn, "\",\"", user, "\",\"", pwd, "\"" ); - if (waitResponse() != 1) { - return false; - } - // Select TCP/IP transfer mode - NOT transparent mode sendAT(GF("+QIMODE=0")); if (waitResponse() != 1) { @@ -370,6 +364,12 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } + //Start TCPIP Task and Set APN, User Name and Password + sendAT("+QIREGAPP=\"", apn, "\",\"", user, "\",\"", pwd, "\"" ); + if (waitResponse() != 1) { + return false; + } + //Activate GPRS/CSD Context sendAT(GF("+QIACT")); if (waitResponse(60000L) != 1) { @@ -732,6 +732,7 @@ TINY_GSM_MODEM_STREAM_UTILITIES() if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; } + data = ""; } else if (data.endsWith(GF("CLOSED" GSM_NL))) { int nl = data.lastIndexOf(GSM_NL, data.length()-8); int coma = data.indexOf(',', nl+2); diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 789eeae..5df479a 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.9.13" +#define TINYGSM_VERSION "0.9.14" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" From 7087a31e6e1852d5e5059f5a524646a7a500bf12 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 6 Sep 2019 15:37:35 -0400 Subject: [PATCH 30/37] Leave airplane mode on in disconnect --- src/TinyGsmClientXBee.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 15abb59..5052762 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -767,6 +767,8 @@ public: XBEE_COMMAND_START_DECORATOR(5, false) sendAT(GF("AN"), apn); // Set the APN bool success = waitResponse() == 1; + sendAT(GF("AM0")); // Airplane mode off + waitResponse(5000); writeChanges(); XBEE_COMMAND_END_DECORATOR return success; @@ -777,9 +779,9 @@ public: sendAT(GF("AM1")); // Cheating and disconnecting by turning on airplane mode int8_t res = (1 == waitResponse(5000)); writeChanges(); - sendAT(GF("AM0")); // Airplane mode off - waitResponse(5000); - writeChanges(); + // sendAT(GF("AM0")); // Airplane mode off + // waitResponse(5000); + // writeChanges(); XBEE_COMMAND_END_DECORATOR return res; } From aeb7579fd22d471c0fbb688a7ed3c921d2ef31bf Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 6 Sep 2019 18:06:11 -0400 Subject: [PATCH 31/37] More quectel fixes --- .github/ISSUE_TEMPLATE.md | 2 +- library.json | 2 +- library.properties | 2 +- src/TinyGsmClientM95.h | 84 ++++++++++++++++++++++++++++----------- src/TinyGsmClientMC60.h | 68 ++++++++++++++++++------------- src/TinyGsmCommon.h | 2 +- 6 files changed, 104 insertions(+), 56 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 729dc17..e1e354e 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,7 +23,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/library.json b/library.json index c9fcf2a..8108dc8 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.14", + "version": "0.9.15", "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 ed9d8ad..dcf23a2 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.14 +version=0.9.15 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 8877625..f83a056 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -64,7 +64,6 @@ public: this->mux = mux; sock_available = 0; sock_connected = false; - got_data = false; at->sockets[mux] = this; @@ -110,7 +109,6 @@ private: uint8_t mux; uint16_t sock_available; bool sock_connected; - bool got_data; RxFifo rx; }; @@ -369,17 +367,41 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } - //Set Method to Handle Received TCP/IP Data - Retrieve Data by Command + // Set Method to Handle Received TCP/IP Data + // Mode = 1 - Output a notification when data is received + // “+QIRDI: ,,” sendAT(GF("+QINDI=1")); if (waitResponse() != 1) { return false; } - //Request an IP header for received data ("IPD(data length):") - sendAT(GF("+QIHEAD=1")); - if (waitResponse() != 1) { - return false; - } + // // Request an IP header for received data + // // "IPD(data length):" + // sendAT(GF("+QIHEAD=1")); + // if (waitResponse() != 1) { + // return false; + // } + // + // // Do NOT show the IP address of the sender when receiving data + // // The format to show the address is: RECV FROM: : + // sendAT(GF("+QISHOWRA=0")); + // if (waitResponse() != 1) { + // return false; + // } + // + // // Do NOT show the protocol type at the end of the header for received data + // // IPD(data length)(TCP/UDP): + // sendAT(GF("+QISHOWPT=0")); + // if (waitResponse() != 1) { + // return false; + // } + // + // // Do NOT show the destination address before receiving data + // // The format to show the address is: TO: + // sendAT(GF("+QISHOWLA=0")); + // if (waitResponse() != 1) { + // return false; + // } return true; } @@ -637,22 +659,34 @@ protected: // sid = index of connection = mux // len = maximum length of data to retrieve sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size); - // sendAT(GF("+QIRD="), mux, ',', (uint16_t)size); - if (waitResponse(GF("+QIRD:")) != 1) { - return 0; - } - streamSkipUntil(':'); // skip IP address - streamSkipUntil(','); // skip port - streamSkipUntil(','); // skip connection type (TCP/UDP) - int len = stream.readStringUntil('\n').toInt(); // read length - for (int i=0; isock_available--; - // ^^ One less character available after moving from modem's FIFO to our FIFO + // If it replies only OK for the write command, it means there is no + // received data in the buffer of the connection. + int res = waitResponse(GF("+QIRD:"), GFP(GSM_OK), GFP(GSM_ERROR)); + if (res == 1) { + streamSkipUntil(':'); // skip IP address + streamSkipUntil(','); // skip port + streamSkipUntil(','); // skip connection type (TCP/UDP) + // read the real length of the retrieved data + uint16_t len = stream.readStringUntil('\n').toInt(); + // We have no way of knowing in advance how much data will be in the buffer + // so when data is received we always assume the buffer is completely full. + // Chances are, this is not true and there's really not that much there. + // In that case, make sure we make sure we re-set the amount of data available. + if (len < size) { + sockets[mux]->sock_available = len; + } + for (uint16_t i=0; isock_available--; + // ^^ One less character available after moving from modem's FIFO to our FIFO + } + waitResponse(); // ends with an OK + DBG("### READ:", len, "from", mux); + return len; + } else { + sockets[mux]->sock_available = 0; + return 0; } - waitResponse(); // ends with an OK - DBG("### READ:", len, "from", mux); - return len; } bool modemGetConnected(uint8_t mux) { @@ -725,7 +759,9 @@ TINY_GSM_MODEM_STREAM_UTILITIES() int mux = stream.readStringUntil('\n').toInt(); DBG("### Got Data:", mux); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { - sockets[mux]->got_data = true; + // We have no way of knowing how much data actually came in, so + // we set the value to 1500, the maximum possible size. + sockets[mux]->sock_available = 1500; } data = ""; } else if (data.endsWith(GF("CLOSED" GSM_NL))) { diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 61d6a2e..9ec3ade 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -68,7 +68,6 @@ public: this->mux = mux; sock_available = 0; sock_connected = false; - got_data = false; at->sockets[mux] = this; @@ -114,7 +113,6 @@ private: uint8_t mux; uint16_t sock_available; bool sock_connected; - bool got_data; RxFifo rx; }; @@ -381,14 +379,10 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() return false; } - //Set Method to Handle Received TCP/IP Data - Retrieve Data by Command - sendAT(GF("+QINDI=1")); - if (waitResponse() != 1) { - return false; - } - - //Request an IP header for received data ("IPD(data length):") - sendAT(GF("+QIHEAD=1")); + //Set Method to Handle Received TCP/IP Data + // Mode=2 - Output a notification statement: + // “+QIRDI: ,,,,,< tlen>” + sendAT(GF("+QINDI=2")); if (waitResponse() != 1) { return false; } @@ -638,22 +632,34 @@ protected: // sid = index of connection - mux // len = maximum length of data to send sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size); - // sendAT(GF("+QIRD="), mux, ',', (uint16_t)size); - if (waitResponse(GF("+QIRD:")) != 1) { - return 0; - } - streamSkipUntil(':'); // skip IP address - streamSkipUntil(','); // skip port - streamSkipUntil(','); // skip connection type (TCP/UDP) - int len = stream.readStringUntil('\n').toInt(); // read length - for (int i=0; isock_available--; - // ^^ One less character available after moving from modem's FIFO to our FIFO + // If it replies only OK for the write command, it means there is no + // received data in the buffer of the connection. + int res = waitResponse(GF("+QIRD:"), GFP(GSM_OK), GFP(GSM_ERROR)); + if (res == 1) { + streamSkipUntil(':'); // skip IP address + streamSkipUntil(','); // skip port + streamSkipUntil(','); // skip connection type (TCP/UDP) + // read the real length of the retrieved data + uint16_t len = stream.readStringUntil('\n').toInt(); + // It's possible that the real length available is less than expected + // This is quite likely if the buffer is broken into packets - which may + // be different sizes. + // If so, make sure we make sure we re-set the amount of data available. + if (len < size) { + sockets[mux]->sock_available = len; + } + for (uint16_t i=0; isock_available--; + // ^^ One less character available after moving from modem's FIFO to our FIFO + } + waitResponse(); + DBG("### READ:", len, "from", mux); + return len; + } else { + sockets[mux]->sock_available = 0; + return 0; } - waitResponse(); - DBG("### READ:", len, "from", mux); - return len; } bool modemGetConnected(uint8_t mux) { @@ -725,14 +731,20 @@ TINY_GSM_MODEM_STREAM_UTILITIES() index = 6; goto finish; } else if (data.endsWith(GF(GSM_NL "+QIRD:"))) { // TODO: QIRD? or QIRDI? + // +QIRDI: ,,,,,< tlen> streamSkipUntil(','); // Skip the context streamSkipUntil(','); // Skip the role - int mux = stream.readStringUntil('\n').toInt(); - DBG("### Got Data:", mux); + // read the connection id + int mux = stream.readStringUntil(',').toInt(); + // read the number of packets in the buffer + int num_packets = stream.readStringUntil(',').toInt(); + // read the length of the current packet + int len_packet = stream.readStringUntil('\n').toInt(); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { - sockets[mux]->got_data = true; + sockets[mux]->sock_available = len_packet*num_packets; } data = ""; + DBG("### Got Data:", len, "on", mux); } else if (data.endsWith(GF("CLOSED" GSM_NL))) { int nl = data.lastIndexOf(GSM_NL, data.length()-8); int coma = data.indexOf(',', nl+2); diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 5df479a..3e476f8 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.9.14" +#define TINYGSM_VERSION "0.9.15" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" From c02273ae758c564ff5b03b49a95c061d3229f4d9 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 6 Sep 2019 20:32:31 -0400 Subject: [PATCH 32/37] Add XBee (wifi) voltage and remove connection indicator for wifi --- src/TinyGsmClientXBee.h | 47 ++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 5052762..f978279 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -109,9 +109,12 @@ public: } virtual int connect(IPAddress ip, uint16_t port, int timeout_s) { + if (timeout_s != 75) { + DBG("Timeout [", timeout_s, "] doesn't apply here."); + } // NOTE: Not caling stop() or yeild() here at->streamClear(); // Empty anything in the buffer before starting - sock_connected = at->modemConnect(ip, port, mux, false, timeout_s); + sock_connected = at->modemConnect(ip, port, mux, false); return sock_connected; } virtual int connect(IPAddress ip, uint16_t port) { @@ -259,9 +262,12 @@ public: } virtual int connect(IPAddress ip, uint16_t port, int timeout_s) { + if (timeout_s != 75) { + DBG("Timeout [", timeout_s, "] doesn't apply here."); + } // NOTE: Not caling stop() or yeild() here at->streamClear(); // Empty anything in the buffer before starting - sock_connected = at->modemConnect(ip, port, mux, true, timeout_s); + sock_connected = at->modemConnect(ip, port, mux, true); return sock_connected; } }; @@ -827,12 +833,30 @@ public: */ // Use: float vBatt = modem.getBattVoltage() / 1000.0; - uint16_t getBattVoltage() TINY_GSM_ATTR_NOT_AVAILABLE; + uint16_t getBattVoltage() { + int16_t intRes = 0; + XBEE_COMMAND_START_DECORATOR(5, false) + if (beeType == XBEE_UNKNOWN) getSeries(); + if (beeType == XBEE_S6B_WIFI) { + sendAT(GF("%V")); + intRes = readResponseInt(); + } + XBEE_COMMAND_END_DECORATOR + return intRes; + } + int8_t getBattPercent() TINY_GSM_ATTR_NOT_AVAILABLE; uint8_t getBattChargeState() TINY_GSM_ATTR_NOT_AVAILABLE; - bool getBattStats(uint8_t &chargeState, int8_t &percent, uint16_t &milliVolts) TINY_GSM_ATTR_NOT_AVAILABLE; + + bool getBattStats(uint8_t &chargeState, int8_t &percent, uint16_t &milliVolts) { + chargeState = 0; + percent = 0; + milliVolts = getBattVoltage(); + return true; + } float getTemperature() { + XBEE_COMMAND_START_DECORATOR(5, (float)-9999) String res = sendATGetString(GF("TP")); if (res == "") { return (float)-9999; @@ -840,6 +864,7 @@ public: char buf[5] = {0,}; res.toCharArray(buf, 5); int8_t intRes = (int8_t)strtol(buf, 0, 16); // degrees Celsius displayed in 8-bit two's complement format. + XBEE_COMMAND_END_DECORATOR return (float)intRes; } @@ -907,7 +932,7 @@ public: bool ssl = false, int timeout_s = 75) { bool retVal = false; - XBEE_COMMAND_START_DECORATOR(5, false) + XBEE_COMMAND_START_DECORATOR(5, false) // If this is a new host name, replace the saved host and wipe out the saved host IP if (this->savedHost != String(host)) { @@ -931,13 +956,9 @@ public: } bool modemConnect(IPAddress ip, uint16_t port, uint8_t mux = 0, - bool ssl = false, int timeout_s = 75) { + bool ssl = false) { bool success = true; - if (timeout_s != 75) { - DBG("Timeout doesn't apply here."); - } - // empty the saved currelty-in-use destination address savedOperatingIP = IPAddress(0, 0, 0, 0); @@ -972,8 +993,10 @@ public: } // we'll accept either unknown or connected - uint16_t ci = getConnectionIndicator(); - success &= (ci == 0x00 || ci == 0xFF || ci == 0x28); + if (beeType != XBEE_S6B_WIFI) { + uint16_t ci = getConnectionIndicator(); + success &= (ci == 0x00 || ci == 0xFF || ci == 0x28); + } if (success) { sockets[mux]->sock_connected = true; From b1040a9c594b8ee8bd1cdc75582db132244f025b Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 6 Sep 2019 20:35:30 -0400 Subject: [PATCH 33/37] extra mux warning --- src/TinyGsmClientXBee.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index f978279..e1369d2 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -959,6 +959,10 @@ public: bool ssl = false) { bool success = true; + if (mux != 0) { + DBG("XBee only supports 1 IP channel in transparent mode!"); + } + // empty the saved currelty-in-use destination address savedOperatingIP = IPAddress(0, 0, 0, 0); From 803e74b87b282c6d9273ab34d7a34fad3f04020a Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 6 Sep 2019 21:13:48 -0400 Subject: [PATCH 34/37] skip verification for wifi --- src/TinyGsmClientXBee.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index e1369d2..4f72afc 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -109,7 +109,7 @@ public: } virtual int connect(IPAddress ip, uint16_t port, int timeout_s) { - if (timeout_s != 75) { + if (timeout_s != 0) { DBG("Timeout [", timeout_s, "] doesn't apply here."); } // NOTE: Not caling stop() or yeild() here @@ -118,7 +118,7 @@ public: return sock_connected; } virtual int connect(IPAddress ip, uint16_t port) { - return connect(ip, port, 75); + return connect(ip, port, 0); } virtual void stop(uint32_t maxWaitMs) { @@ -262,7 +262,7 @@ public: } virtual int connect(IPAddress ip, uint16_t port, int timeout_s) { - if (timeout_s != 75) { + if (timeout_s != 0) { DBG("Timeout [", timeout_s, "] doesn't apply here."); } // NOTE: Not caling stop() or yeild() here @@ -1018,14 +1018,16 @@ public: stream.write((uint8_t*)buff, len); stream.flush(); - // After a send, verify the outgoing ip if it isn't set - if (savedOperatingIP == IPAddress(0, 0, 0, 0)) { - modemGetConnected(); - } - // After sending several characters, also re-check - // NOTE: I'm intentionally not checking after every single character! - else if (len > 5) { - modemGetConnected(); + if (beeType != XBEE_S6B_WIFI) { + // After a send, verify the outgoing ip if it isn't set + if (savedOperatingIP == IPAddress(0, 0, 0, 0)) { + modemGetConnected(); + } + // After sending several characters, also re-check + // NOTE: I'm intentionally not checking after every single character! + else if (len > 5) { + modemGetConnected(); + } } return len; From 4b736d8cc9a2d7cfbd7418f39bb4840c451146c3 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 6 Sep 2019 22:17:37 -0400 Subject: [PATCH 35/37] Fixed xbee wifi perpetual instant timeout --- src/TinyGsmClientXBee.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 4f72afc..086c88b 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -126,24 +126,29 @@ public: // empty the saved currently-in-use destination address at->savedOperatingIP = IPAddress(0, 0, 0, 0); at->commandMode(); + + // Get the current socket timeout + at->sendAT(GF("TM")); + String timeoutUsed = at->readResponseString(5000L); + // For WiFi models, there's no direct way to close the socket. This is a // hack to shut the socket by setting the timeout to zero. if (at->beeType == XBEE_S6B_WIFI) { - at->sendAT(GF("TM0")); // Set socket timeout (using Digi default of 10 seconds) + at->sendAT(GF("TM0")); // Set socket timeout to 0 at->waitResponse(maxWaitMs); // This response can be slow at->writeChanges(); } - // For cellular models, per documentation: If you change the TM (socket + + // For cellular models, per documentation: If you write the TM (socket // timeout) value while in Transparent Mode, the current connection is - // immediately closed. - at->sendAT(GF("TM")); // Get socket timeout - String timeoutUsed = at->readResponseString(5000L); + // immediately closed - this works even if the TM values is unchanged at->sendAT(GF("TM"), timeoutUsed); // Re-set socket timeout at->waitResponse(maxWaitMs); // This response can be slow at->writeChanges(); at->exitCommand(); at->streamClear(); // Empty anything remaining in the buffer sock_connected = false; + // Note: because settings are saved in flash, the XBEE will attempt to // reconnect to the previous socket if it receives any outgoing data. // Setting sock_connected to false after the stop ensures that connected() @@ -1138,7 +1143,6 @@ public: // we force close so it can reopen case 0x21 : case 0x27 : { - Serial.println("Here!"); sendAT(GF("TM")); // Get socket timeout String timeoutUsed = readResponseString(5000L); sendAT(GF("TM"), timeoutUsed); // Re-set socket timeout From 97edce96bdf1e57630d5444cfe5bb6a2f13ccc46 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 6 Sep 2019 23:05:12 -0400 Subject: [PATCH 36/37] Try again to get stop right --- .github/ISSUE_TEMPLATE.md | 2 +- library.json | 2 +- library.properties | 2 +- src/TinyGsmClientXBee.h | 57 ++++++++++++++++++++++----------------- src/TinyGsmCommon.h | 2 +- 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index e1e354e..4e7fe68 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,7 +23,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/library.json b/library.json index 8108dc8..3a32dcb 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.15", + "version": "0.9.16", "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 dcf23a2..cca0b2a 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.15 +version=0.9.16 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 086c88b..320e5e2 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -124,31 +124,10 @@ public: virtual void stop(uint32_t maxWaitMs) { at->streamClear(); // Empty anything in the buffer // empty the saved currently-in-use destination address - at->savedOperatingIP = IPAddress(0, 0, 0, 0); - at->commandMode(); - - // Get the current socket timeout - at->sendAT(GF("TM")); - String timeoutUsed = at->readResponseString(5000L); - - // For WiFi models, there's no direct way to close the socket. This is a - // hack to shut the socket by setting the timeout to zero. - if (at->beeType == XBEE_S6B_WIFI) { - at->sendAT(GF("TM0")); // Set socket timeout to 0 - at->waitResponse(maxWaitMs); // This response can be slow - at->writeChanges(); - } - - // For cellular models, per documentation: If you write the TM (socket - // timeout) value while in Transparent Mode, the current connection is - // immediately closed - this works even if the TM values is unchanged - at->sendAT(GF("TM"), timeoutUsed); // Re-set socket timeout - at->waitResponse(maxWaitMs); // This response can be slow - at->writeChanges(); - at->exitCommand(); - at->streamClear(); // Empty anything remaining in the buffer + at->modemStop(maxWaitMs); + at->streamClear(); // Empty anything in the buffer sock_connected = false; - + // Note: because settings are saved in flash, the XBEE will attempt to // reconnect to the previous socket if it receives any outgoing data. // Setting sock_connected to false after the stop ensures that connected() @@ -1016,6 +995,36 @@ public: return success; } + bool modemStop(uint32_t maxWaitMs) { + streamClear(); // Empty anything in the buffer + // empty the saved currently-in-use destination address + savedOperatingIP = IPAddress(0, 0, 0, 0); + + XBEE_COMMAND_START_DECORATOR(5, false) + + // Get the current socket timeout + sendAT(GF("TM")); + String timeoutUsed = readResponseString(5000L); + + // For WiFi models, there's no direct way to close the socket. This is a + // hack to shut the socket by setting the timeout to zero. + if (beeType == XBEE_S6B_WIFI) { + sendAT(GF("TM0")); // Set socket timeout to 0 + waitResponse(maxWaitMs); // This response can be slow + writeChanges(); + } + + // For cellular models, per documentation: If you write the TM (socket + // timeout) value while in Transparent Mode, the current connection is + // immediately closed - this works even if the TM values is unchanged + sendAT(GF("TM"), timeoutUsed); // Re-set socket timeout + waitResponse(maxWaitMs); // This response can be slow + writeChanges(); + + XBEE_COMMAND_END_DECORATOR + return true; + } + int16_t modemSend(const void* buff, size_t len, uint8_t mux = 0) { if (mux != 0) { DBG("XBee only supports 1 IP channel in transparent mode!"); diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 3e476f8..9eac502 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.9.15" +#define TINYGSM_VERSION "0.9.16" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" From 17cdde291f90a45c3f556e2e11ffd155f69c9d24 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Mon, 9 Sep 2019 18:24:24 -0400 Subject: [PATCH 37/37] Tiny change to M95 and it works! --- .github/ISSUE_TEMPLATE.md | 2 +- library.json | 2 +- library.properties | 2 +- src/TinyGsmClientM95.h | 3 +-- src/TinyGsmClientMC60.h | 3 +-- src/TinyGsmCommon.h | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 4e7fe68..aeccd82 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -23,7 +23,7 @@ with your board before submitting any issues. Main processor board: Modem: -TinyGSM version: +TinyGSM version: Code: ### Scenario, steps to reproduce diff --git a/library.json b/library.json index 3a32dcb..4fec615 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.9.16", + "version": "0.9.17", "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 cca0b2a..549761f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.9.16 +version=0.9.17 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index f83a056..3e108d0 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -611,8 +611,7 @@ protected: DBG("SSL not yet supported on this module!"); } uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; - sendAT(GF("+QIOPEN="), mux, GF(",\""), GF("TCP"), GF("\",\""), host, - GF("\","), port); + sendAT(GF("+QIOPEN="), mux, GF(",\""), GF("TCP"), GF("\",\""), host, GF("\","), port); int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), GF("CONNECT FAIL" GSM_NL), diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 9ec3ade..6036e9c 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -582,8 +582,7 @@ protected: DBG("SSL not yet supported on this module!"); } uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; - sendAT(GF("+QIOPEN="), mux, GF(",\""), GF("TCP"), GF("\",\""), host, - GF("\","), port); + sendAT(GF("+QIOPEN="), mux, GF(",\""), GF("TCP"), GF("\",\""), host, GF("\","), port); int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), GF("CONNECT FAIL" GSM_NL), diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 9eac502..bb2e541 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.9.16" +#define TINYGSM_VERSION "0.9.17" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h"