From 799ab7c0785023ca3badbef8b0f00fc774c31b7d Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Mon, 11 Jun 2018 00:50:14 +0300 Subject: [PATCH 1/7] Update examples --- examples/AllFunctions/AllFunctions.ino | 5 ++++- examples/BlynkClient/BlynkClient.ino | 2 ++ examples/FileDownload/FileDownload.ino | 2 ++ examples/HttpClient/HttpClient.ino | 2 ++ examples/HttpsClient/HttpsClient.ino | 4 +++- examples/MqttClient/MqttClient.ino | 10 +++++++--- examples/WebClient/WebClient.ino | 2 ++ 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/examples/AllFunctions/AllFunctions.ino b/examples/AllFunctions/AllFunctions.ino index d175ec2..573e279 100644 --- a/examples/AllFunctions/AllFunctions.ino +++ b/examples/AllFunctions/AllFunctions.ino @@ -13,6 +13,8 @@ #define TINY_GSM_MODEM_SIM800 // #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM900 +// #define TINY_GSM_MODEM_UBLOX +// #define TINY_GSM_MODEM_BG96 // #define TINY_GSM_MODEM_A6 // #define TINY_GSM_MODEM_A7 // #define TINY_GSM_MODEM_M590 @@ -97,7 +99,8 @@ void loop() { return; } - bool res; + bool res = modem.isGprsConnected(); + DBG("GPRS status:", res ? "connected" : "not connected"); String ccid = modem.getSimCCID(); DBG("CCID:", ccid); diff --git a/examples/BlynkClient/BlynkClient.ino b/examples/BlynkClient/BlynkClient.ino index 821e8b4..d3d7ce3 100644 --- a/examples/BlynkClient/BlynkClient.ino +++ b/examples/BlynkClient/BlynkClient.ino @@ -32,6 +32,8 @@ #define TINY_GSM_MODEM_SIM800 // #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM900 +// #define TINY_GSM_MODEM_UBLOX +// #define TINY_GSM_MODEM_BG96 // #define TINY_GSM_MODEM_A6 // #define TINY_GSM_MODEM_A7 // #define TINY_GSM_MODEM_M590 diff --git a/examples/FileDownload/FileDownload.ino b/examples/FileDownload/FileDownload.ino index f7eecc3..19c73a6 100644 --- a/examples/FileDownload/FileDownload.ino +++ b/examples/FileDownload/FileDownload.ino @@ -17,6 +17,8 @@ #define TINY_GSM_MODEM_SIM800 // #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM900 +// #define TINY_GSM_MODEM_UBLOX +// #define TINY_GSM_MODEM_BG96 // #define TINY_GSM_MODEM_A6 // #define TINY_GSM_MODEM_A7 // #define TINY_GSM_MODEM_M590 diff --git a/examples/HttpClient/HttpClient.ino b/examples/HttpClient/HttpClient.ino index c52a664..95b3453 100644 --- a/examples/HttpClient/HttpClient.ino +++ b/examples/HttpClient/HttpClient.ino @@ -18,6 +18,8 @@ #define TINY_GSM_MODEM_SIM800 // #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM900 +// #define TINY_GSM_MODEM_UBLOX +// #define TINY_GSM_MODEM_BG96 // #define TINY_GSM_MODEM_A6 // #define TINY_GSM_MODEM_A7 // #define TINY_GSM_MODEM_M590 diff --git a/examples/HttpsClient/HttpsClient.ino b/examples/HttpsClient/HttpsClient.ino index 73cd3be..bd892d7 100644 --- a/examples/HttpsClient/HttpsClient.ino +++ b/examples/HttpsClient/HttpsClient.ino @@ -10,7 +10,8 @@ * TinyGSM Getting Started guide: * http://tiny.cc/tiny-gsm-readme * - * SSL/TLS is currently supported only with SIM8xx series + * SSL/TLS is currently supported only with: SIM8xx, uBlox + * * For more HTTP API examples, see ArduinoHttpClient library * **************************************************************/ @@ -18,6 +19,7 @@ // Select your modem: #define TINY_GSM_MODEM_SIM800 // #define TINY_GSM_MODEM_SIM808 +// #define TINY_GSM_MODEM_UBLOX // Increase RX buffer if needed //#define TINY_GSM_RX_BUFFER 512 diff --git a/examples/MqttClient/MqttClient.ino b/examples/MqttClient/MqttClient.ino index b398d15..4086868 100644 --- a/examples/MqttClient/MqttClient.ino +++ b/examples/MqttClient/MqttClient.ino @@ -31,6 +31,8 @@ #define TINY_GSM_MODEM_SIM800 // #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM900 +// #define TINY_GSM_MODEM_UBLOX +// #define TINY_GSM_MODEM_BG96 // #define TINY_GSM_MODEM_A6 // #define TINY_GSM_MODEM_A7 // #define TINY_GSM_MODEM_M590 @@ -131,9 +133,8 @@ boolean mqttConnect() { void loop() { - if (mqtt.connected()) { - mqtt.loop(); - } else { + if (!mqtt.connected()) { + SerialMon.println("=== MQTT NOT CONNECTED ==="); // Reconnect every 10 seconds unsigned long t = millis(); if (t - lastReconnectAttempt > 10000L) { @@ -142,8 +143,11 @@ void loop() { lastReconnectAttempt = 0; } } + delay(100); + return; } + mqtt.loop(); } void mqttCallback(char* topic, byte* payload, unsigned int len) { diff --git a/examples/WebClient/WebClient.ino b/examples/WebClient/WebClient.ino index 5fa5111..e1127fd 100644 --- a/examples/WebClient/WebClient.ino +++ b/examples/WebClient/WebClient.ino @@ -12,6 +12,8 @@ #define TINY_GSM_MODEM_SIM800 // #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM900 +// #define TINY_GSM_MODEM_UBLOX +// #define TINY_GSM_MODEM_BG96 // #define TINY_GSM_MODEM_A6 // #define TINY_GSM_MODEM_A7 // #define TINY_GSM_MODEM_M590 From fe4ee102ec9fccc9c32c3a6355affa058ca4d22b Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Mon, 11 Jun 2018 00:50:39 +0300 Subject: [PATCH 2/7] Update tools --- tools/AT_Debug/AT_Debug.ino | 2 ++ tools/Diagnostics/Diagnostics.ino | 4 +++- tools/FactoryReset/FactoryReset.ino | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/AT_Debug/AT_Debug.ino b/tools/AT_Debug/AT_Debug.ino index 878d7d2..e8e985d 100644 --- a/tools/AT_Debug/AT_Debug.ino +++ b/tools/AT_Debug/AT_Debug.ino @@ -12,6 +12,8 @@ #define TINY_GSM_MODEM_SIM800 // #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM900 +// #define TINY_GSM_MODEM_UBLOX +// #define TINY_GSM_MODEM_BG96 // #define TINY_GSM_MODEM_A6 // #define TINY_GSM_MODEM_A7 // #define TINY_GSM_MODEM_M590 diff --git a/tools/Diagnostics/Diagnostics.ino b/tools/Diagnostics/Diagnostics.ino index 38d3ffa..a57f2b8 100644 --- a/tools/Diagnostics/Diagnostics.ino +++ b/tools/Diagnostics/Diagnostics.ino @@ -14,6 +14,7 @@ // #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM900 // #define TINY_GSM_MODEM_UBLOX +// #define TINY_GSM_MODEM_BG96 // #define TINY_GSM_MODEM_A6 // #define TINY_GSM_MODEM_A7 // #define TINY_GSM_MODEM_M590 @@ -56,6 +57,7 @@ const char resource[] = "/TinyGSM/logo.txt"; const int port = 80; TinyGsmClient client(modem); +// For SSL: //const int port = 443; //TinyGsmClientSecure client(modem); @@ -155,7 +157,7 @@ void loop() { while (client.connected() && millis() - timeout < 10000L) { while (client.available()) { char c = client.read(); - SerialMon.print(c); + //SerialMon.print(c); bytesReceived += 1; timeout = millis(); } diff --git a/tools/FactoryReset/FactoryReset.ino b/tools/FactoryReset/FactoryReset.ino index 305c67c..1570cfc 100644 --- a/tools/FactoryReset/FactoryReset.ino +++ b/tools/FactoryReset/FactoryReset.ino @@ -13,6 +13,8 @@ #define TINY_GSM_MODEM_SIM800 // #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM900 +// #define TINY_GSM_MODEM_UBLOX +// #define TINY_GSM_MODEM_BG96 // #define TINY_GSM_MODEM_A6 // #define TINY_GSM_MODEM_A7 // #define TINY_GSM_MODEM_M590 From bc9818c35367ab5958d62b7aa3aaa9e1c25d33bc Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Mon, 11 Jun 2018 00:52:36 +0300 Subject: [PATCH 3/7] Add comments --- src/TinyGsmClientSIM800.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index a841a66..08e256a 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -244,8 +244,8 @@ public: for (unsigned long start = millis(); millis() - start < timeout; ) { sendAT(GF("")); if (waitResponse(200) == 1) { - delay(100); - return true; + delay(100); + return true; } delay(100); } @@ -313,6 +313,7 @@ public: return false; } //Enable Local Time Stamp for getting network time + // TODO: Find a better place for this sendAT(GF("+CLTS=1")); if (waitResponse(10000L) != 1) { return false; From 4c994651b37c2a9d62138686f0c4612327916878 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Mon, 11 Jun 2018 00:56:23 +0300 Subject: [PATCH 4/7] Override Client.write(const char*) --- src/TinyGsmClientA6.h | 5 +++++ src/TinyGsmClientBG96.h | 5 +++++ src/TinyGsmClientESP8266.h | 5 +++++ src/TinyGsmClientM590.h | 5 +++++ src/TinyGsmClientSIM800.h | 5 +++++ src/TinyGsmClientUBLOX.h | 5 +++++ src/TinyGsmClientXBee.h | 5 +++++ 7 files changed, 35 insertions(+) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index a53890b..9cc061c 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -108,6 +108,11 @@ public: return write(&c, 1); } + virtual size_t write(const char *str) { + if (str == NULL) return 0; + return write((const uint8_t *)str, strlen(str)); + } + virtual int available() { TINY_GSM_YIELD(); if (!rx.size() && sock_connected) { diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index f65da65..2903647 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -108,6 +108,11 @@ public: return write(&c, 1); } + virtual size_t write(const char *str) { + if (str == NULL) return 0; + return write((const uint8_t *)str, strlen(str)); + } + virtual int available() { TINY_GSM_YIELD(); if (!rx.size()) { diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 44ed149..5d9bbdf 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -90,6 +90,11 @@ public: return write(&c, 1); } + virtual size_t write(const char *str) { + if (str == NULL) return 0; + return write((const uint8_t *)str, strlen(str)); + } + virtual int available() { TINY_GSM_YIELD(); if (!rx.size() && sock_connected) { diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index 21539ae..4597b6c 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -105,6 +105,11 @@ public: return write(&c, 1); } + virtual size_t write(const char *str) { + if (str == NULL) return 0; + return write((const uint8_t *)str, strlen(str)); + } + virtual int available() { TINY_GSM_YIELD(); if (!rx.size() && sock_connected) { diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 08e256a..3859dfa 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -114,6 +114,11 @@ public: return write(&c, 1); } + virtual size_t write(const char *str) { + if (str == NULL) return 0; + return write((const uint8_t *)str, strlen(str)); + } + virtual int available() { TINY_GSM_YIELD(); if (!rx.size() && sock_connected) { diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 9ea3c63..2c25b71 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -107,6 +107,11 @@ public: return write(&c, 1); } + virtual size_t write(const char *str) { + if (str == NULL) return 0; + return write((const uint8_t *)str, strlen(str)); + } + virtual int available() { TINY_GSM_YIELD(); if (!rx.size()) { diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 87dbcda..9cb5861 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -118,6 +118,11 @@ public: return write(&c, 1); } + virtual size_t write(const char *str) { + if (str == NULL) return 0; + return write((const uint8_t *)str, strlen(str)); + } + virtual int available() { TINY_GSM_YIELD(); return at->stream.available(); From 0524f232733f8627904e20a4ca267c155998f283 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Mon, 11 Jun 2018 01:09:00 +0300 Subject: [PATCH 5/7] Add MQTT Auth example --- examples/MqttClient/MqttClient.ino | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/MqttClient/MqttClient.ino b/examples/MqttClient/MqttClient.ino index 4086868..da5933a 100644 --- a/examples/MqttClient/MqttClient.ino +++ b/examples/MqttClient/MqttClient.ino @@ -121,7 +121,14 @@ void setup() { boolean mqttConnect() { SerialMon.print("Connecting to "); SerialMon.print(broker); - if (!mqtt.connect("GsmClientTest")) { + + // 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; } From d899424cca04b36fb229be4f113a1ccb658d270b Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Mon, 11 Jun 2018 01:17:13 +0300 Subject: [PATCH 6/7] Cleanup --- src/TinyGsmClientSIM800.h | 46 +++++---------------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 79c2cf9..5660c7c 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -45,22 +45,9 @@ enum TinyGSMDateTimeFormat { DATE_DATE = 2 }; -//============================================================================// -//============================================================================// -// Declaration of the TinyGsmSim800 Class -//============================================================================// -//============================================================================// - class TinyGsmSim800 { -//============================================================================// -//============================================================================// -// The Sim800 Internal Client Class -//============================================================================// -//============================================================================// - - public: class GsmClient : public Client @@ -205,13 +192,6 @@ private: RxFifo rx; }; -//============================================================================// -//============================================================================// -// The SIM800 Secure Client -//============================================================================// -//============================================================================// - - class GsmClientSecure : public GsmClient { public: @@ -231,19 +211,9 @@ public: } }; -//============================================================================// -//============================================================================// -// The SIM800 Modem Functions -//============================================================================// -//============================================================================// - public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmSim800(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmSim800(Stream& stream) -#endif : stream(stream) { memset(sockets, 0, sizeof(sockets)); @@ -432,10 +402,10 @@ public: int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), GF("NOT INSERTED")); waitResponse(); switch (status) { - case 2: - case 3: return SIM_LOCKED; - case 1: return SIM_READY; - default: return SIM_ERROR; + case 2: + case 3: return SIM_LOCKED; + case 1: return SIM_READY; + default: return SIM_ERROR; } } return SIM_ERROR; @@ -492,10 +462,6 @@ public: return false; } - /* - * WiFi functions - */ - /* * GPRS functions */ @@ -932,8 +898,7 @@ public: streamWrite(tail...); } - bool streamSkipUntil(char c) { - const unsigned long timeout = 1000L; + bool streamSkipUntil(const char c, const unsigned long timeout = 3000L) { unsigned long startMillis = millis(); while (millis() - startMillis < timeout) { while (millis() - startMillis < timeout && !stream.available()) { @@ -1019,7 +984,6 @@ finish: } data = ""; } - //DBG('<', index, '>'); return index; } From 74a4bf5d4a6016597447ed5fc629b017dfe2e8f2 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Mon, 11 Jun 2018 01:35:09 +0300 Subject: [PATCH 7/7] boost ver to 0.3.5 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index fc40cfd..29ac518 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.3.3", + "version": "0.3.5", "description": "A small Arduino library for GPRS modules, that just works. Includes examples for Blynk, MQTT, File Download, and Web Client. Supports GSM modules with AT command interface: SIM800, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900, SIM900A, SIM900D, SIM908, SIM968", "keywords": "GSM, AT commands, AT, SIM800, SIM900, A6, A7, M590, ESP8266, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900A, SIM900D, SIM908, SIM968", "authors": diff --git a/library.properties b/library.properties index 383fb0f..7762874 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.3.3 +version=0.3.5 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works.