From fc4c4332950239dd2bfad0c8c3b62116578ad4bf Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Sun, 24 Sep 2017 17:37:18 +0300 Subject: [PATCH 1/5] Fix modem selection --- examples/HttpsClient/HttpsClient.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/HttpsClient/HttpsClient.ino b/examples/HttpsClient/HttpsClient.ino index b0308ff..dfe5bd5 100644 --- a/examples/HttpsClient/HttpsClient.ino +++ b/examples/HttpsClient/HttpsClient.ino @@ -15,7 +15,7 @@ // Select your modem // SSL/TLS is currently supported only with SIM8xx series #define TINY_GSM_MODEM_SIM800 -#define TINY_GSM_MODEM_SIM808 +//#define TINY_GSM_MODEM_SIM808 // Increase RX buffer #define TINY_GSM_RX_BUFFER 64 From 086d2ea64e1737ccfee143253d8e9f14ce3aa4fc Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Sun, 24 Sep 2017 17:37:46 +0300 Subject: [PATCH 2/5] Add uno_pic32 --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ee065dd..5b5120e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,7 @@ env: - PLATFORMIO_CI_SRC=tools/FactoryReset # Arduino test - - PLATFORMIO_CI_SRC=tools/test_build PLATFORMIO_CI_ARGS="--project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=esp01 --board=nodemcuv2 --board=esp32dev" - #TODO: add --board=uno_pic32 + - PLATFORMIO_CI_SRC=tools/test_build PLATFORMIO_CI_ARGS="--project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=esp01 --board=nodemcuv2 --board=esp32dev --board=uno_pic32" # Energia test - PLATFORMIO_CI_SRC=tools/test_build PLATFORMIO_CI_ARGS="--project-option='framework=energia' --board=lplm4f120h5qr" From df2b5cae1c69e8f062c23599c9e3ce3805283192 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Sun, 24 Sep 2017 17:39:44 +0300 Subject: [PATCH 3/5] Add isNetworkConnected(), isGprsConnected(). Fix #82 --- TinyGsmClientSIM800.h | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/TinyGsmClientSIM800.h b/TinyGsmClientSIM800.h index b437719..7e1a52c 100644 --- a/TinyGsmClientSIM800.h +++ b/TinyGsmClientSIM800.h @@ -171,7 +171,7 @@ public: String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED; private: - TinyGsmSim800* at; + TinyGsmSim800* at; uint8_t mux; uint16_t sock_available; uint32_t prev_check; @@ -411,13 +411,17 @@ public: return res; } + bool isNetworkConnected() { + RegStatus s = getRegistrationStatus(); + return (s == REG_OK_HOME || s == REG_OK_ROAMING); + } + bool waitForNetwork(unsigned long timeout = 60000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { - RegStatus s = getRegistrationStatus(); - if (s == REG_OK_HOME || s == REG_OK_ROAMING) { + if (isNetworkConnected()) { return true; } - delay(1000); + delay(500); } return false; } @@ -503,7 +507,24 @@ public: bool gprsDisconnect() { sendAT(GF("+CIPSHUT")); - return waitResponse(60000L) == 1; + if (waitResponse(60000L) != 1) + return false; + + sendAT(GF("+CGATT=0")); + if (waitResponse(60000L) != 1) + return false; + + return true; + } + + bool isGprsConnected() { + sendAT(GF("+CGATT?")); + if (waitResponse(GF(GSM_NL "+CGATT:")) != 1) { + return false; + } + int res = stream.readStringUntil('\n').toInt(); + waitResponse(); + return res == 1; } String getLocalIP() { From 0389264e963a145076dbe1fe30ec44bd2daa41ab Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Sun, 24 Sep 2017 17:39:58 +0300 Subject: [PATCH 4/5] Add isNetworkConnected(), isGprsConnected(). Fix #82 --- keywords.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/keywords.txt b/keywords.txt index fa2df44..33f98c4 100644 --- a/keywords.txt +++ b/keywords.txt @@ -17,6 +17,8 @@ waitForNetwork KEYWORD2 getSimStatus KEYWORD2 gprsConnect KEYWORD2 gprsDisconnect KEYWORD2 +isGprsConnected KEYWORD2 +isNetworkConnected KEYWORD2 factoryReset KEYWORD2 ####################################### From 3149c335fbefd61d706544ecb1415dd79d8b9c92 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Mon, 25 Sep 2017 12:06:18 +0300 Subject: [PATCH 5/5] Fix isGprsConnected() for SIM8xx --- TinyGsmClientSIM800.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/TinyGsmClientSIM800.h b/TinyGsmClientSIM800.h index 7e1a52c..0daaba7 100644 --- a/TinyGsmClientSIM800.h +++ b/TinyGsmClientSIM800.h @@ -524,7 +524,14 @@ public: } int res = stream.readStringUntil('\n').toInt(); waitResponse(); - return res == 1; + if (res != 1) + return false; + + sendAT(GF("+CIFSR;E0")); // Another option is to use AT+CGPADDR=1 + if (waitResponse() != 1) + return false; + + return true; } String getLocalIP() {