From 344bacd73e8ec15aaedbce1c64572a220ad3dbe3 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 24 May 2019 14:40:09 -0400 Subject: [PATCH] Fixed SIM800 issue --- src/TinyGsmClientSIM800.h | 29 ++++++++++++++++------------- src/TinyGsmCommon.h | 4 ++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index f3396a0..c62f282 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -308,7 +308,7 @@ TINY_GSM_MODEM_GET_IMEI_GSN() 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"), GF("NOT READY")); waitResponse(); switch (status) { case 2: @@ -767,12 +767,10 @@ protected: size_t 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. - if (len_confirmed < len_requested) { - DBG("WARNING:", len_requested - len_confirmed, "fewer bytes confirmed readable than requested!"); - } - sockets[mux]->sock_available = len_confirmed; - - for (size_t i=0; i_timeout)) { TINY_GSM_YIELD(); } @@ -784,13 +782,16 @@ protected: while (!stream.available() && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); } char c = stream.read(); #endif - sockets[mux]->rx.put(c); - sockets[mux]->sock_available--; - // ^^ One less character available after moving from modem's FIFO to our FIFO + if (c > 0) { + sockets[mux]->rx.put(c); + len_read++; + } } + DBG("### READ:", len_read, "from", mux); + // sockets[mux]->sock_available = modemGetAvailable(mux); + sockets[mux]->sock_available = len_confirmed; waitResponse(); - DBG("### READ:", TinyGsmMin(len_confirmed, len_requested), "from", mux); - return TinyGsmMin(len_confirmed, len_requested); + return len_read; } size_t modemGetAvailable(uint8_t mux) { @@ -811,7 +812,9 @@ protected: bool modemGetConnected(uint8_t mux) { sendAT(GF("+CIPSTATUS="), mux); - int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), GF(",\"CLOSING\""), GF(",\"INITIAL\"")); + waitResponse(GF("+CIPSTATUS")); + int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), GF(",\"CLOSING\""), + GF(",\"REMOTE CLOSING\""), GF(",\"INITIAL\"")); waitResponse(); return 1 == res; } diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 68024ac..0876c51 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -249,7 +249,7 @@ String TinyGsmDecodeHex16bit(String &instr) { /* Workaround: sometimes module forgets to notify about data arrival. TODO: Currently we ping the module periodically, but maybe there's a better indicator that we need to poll */ \ - if (millis() - prev_check > 250) { \ + if (millis() - prev_check > 500) { \ got_data = true; \ prev_check = millis(); \ } \ @@ -311,7 +311,7 @@ String TinyGsmDecodeHex16bit(String &instr) { /* Workaround: sometimes module forgets to notify about data arrival. TODO: Currently we ping the module periodically, but maybe there's a better indicator that we need to poll */ \ - if (millis() - prev_check > 250) { \ + if (millis() - prev_check > 500) { \ got_data = true; \ prev_check = millis(); \ } \