From 43cd516d1ffb382525fbe9bbe326504104afd06b Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 8 May 2019 13:08:40 -0400 Subject: [PATCH] (Hopefully) better wait for close on SARA R410 --- src/TinyGsmClientBG96.h | 2 +- src/TinyGsmClientM95.h | 2 +- src/TinyGsmClientMC60.h | 2 +- src/TinyGsmClientUBLOX.h | 22 ++++++++++------------ 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 02a8269..e24d718 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -668,7 +668,7 @@ protected: streamSkipUntil(','); // Skip total received streamSkipUntil(','); // Skip have read result = stream.readStringUntil('\n').toInt(); - 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 39022a9..170f764 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -723,7 +723,7 @@ protected: streamSkipUntil(','); // Skip total received streamSkipUntil(','); // Skip have read result = stream.readStringUntil('\n').toInt(); - DBG("### DATA AVAILABLE:", result, "on", mux); + if (result) DBG("### DATA AVAILABLE:", result, "on", mux); waitResponse(); } if (!result) { diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 8b6e021..583a9b7 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -752,7 +752,7 @@ protected: streamSkipUntil(','); // Skip total received streamSkipUntil(','); // Skip have read result = stream.readStringUntil('\n').toInt(); - DBG("### DATA AVAILABLE:", result, "on", mux); + if (result) DBG("### DATA AVAILABLE:", result, "on", mux); waitResponse(); } if (!result) { diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 9d938f0..4d4e0f9 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -71,17 +71,15 @@ public: public: virtual int connect(const char *host, uint16_t port) { - if (sock_connected) { - stop(); - // If we're creating a new connection on the same client, we need to wait - // until the async close has finished on Cat-M modems. - // After close has completed, the +UUSOCL should appear. - if (at->isCatM) { - DBG("Waiting for +UUSOCL URC on", mux); - for (unsigned long start = millis(); millis() - start < 120000L; ) { - at->maintain(); - if (!sock_connected) break; - } + stop(); + // If we're creating a new connection on the same client, we need to wait + // until the async close has finished on Cat-M modems. + // After close has completed, the +UUSOCL should appear. + if (at->isCatM && sock_connected) { + DBG("Waiting for +UUSOCL URC on", mux); + for (unsigned long start = millis(); millis() - start < 120000L; ) { + at->maintain(); + if (!sock_connected) break; } } TINY_GSM_YIELD(); @@ -844,7 +842,7 @@ protected: if (res == 1) { streamSkipUntil(','); // Skip mux result = stream.readStringUntil('\n').toInt(); - DBG("### DATA AVAILABLE:", result, "on", mux); + if (result) DBG("### DATA AVAILABLE:", result, "on", mux); waitResponse(); } if (!result && res != 2 && res != 3) { // Don't check modemGetConnected after an error