diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 8fa02bb..6f892a5 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -58,6 +58,10 @@ public: this->mux = -1; sock_connected = false; + // at->sockets[mux] = this; + // ^^ TODO: attach the socket here at init? Or later at connect? + // Currently done inconsistently between modems + return true; } @@ -71,6 +75,8 @@ public: if (sock_connected) { mux = newMux; at->sockets[mux] = this; + // ^^ TODO: attach the socet after attempting connection or above at init? + // Currently done inconsistently between modems } return sock_connected; } @@ -112,7 +118,7 @@ public: virtual int available() { TINY_GSM_YIELD(); - if (!rx.size()) { + if (!rx.size() && sock_connected) { at->maintain(); } return rx.size(); diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 0131b81..3cf0499 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -62,6 +62,8 @@ public: got_data = false; at->sockets[mux] = this; + // ^^ TODO: attach the socket here at init? Or later at connect? + // Currently done inconsistently between modems return true; } @@ -72,6 +74,10 @@ public: TINY_GSM_YIELD(); rx.clear(); sock_connected = at->modemConnect(host, port, mux); + // sock_connected = at->modemConnect(host, port, &mux); + // at->sockets[mux] = this; + // ^^ TODO: attach the socet after attempting connection or above at init? + // Currently done inconsistently between modems return sock_connected; } @@ -97,7 +103,7 @@ public: rx.clear(); at->maintain(); while (sock_available > 0) { - sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); + at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); rx.clear(); at->maintain(); } @@ -641,6 +647,7 @@ protected: return 0; } size_t len = stream.readStringUntil('\n').toInt(); + sockets[mux]->sock_available = len; for (size_t i=0; isockets[mux] = this; + // ^^ TODO: attach the socket here at init? Or later at connect? + // Currently done inconsistently between modems return true; } @@ -69,6 +71,10 @@ public: TINY_GSM_YIELD(); rx.clear(); sock_connected = at->modemConnect(host, port, mux); + // sock_connected = at->modemConnect(host, port, &mux); + // at->sockets[mux] = this; + // ^^ TODO: attach the socet after attempting connection or above at init? + // Currently done inconsistently between modems return sock_connected; } @@ -109,7 +115,7 @@ public: virtual int available() { TINY_GSM_YIELD(); - if (!rx.size()) { + if (!rx.size() && sock_connected) { at->maintain(); } return rx.size(); @@ -183,6 +189,10 @@ public: TINY_GSM_YIELD(); rx.clear(); sock_connected = at->modemConnect(host, port, mux, true); + // sock_connected = at->modemConnect(host, port, &mux); + // at->sockets[mux] = this; + // ^^ TODO: attach the socet after attempting connection or above at init? + // Currently done inconsistently between modems return sock_connected; } }; diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index e138fa6..7eeb917 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -59,6 +59,8 @@ public: sock_connected = false; at->sockets[mux] = this; + // ^^ TODO: attach the socket here at init? Or later at connect? + // Currently done inconsistently between modems return true; } @@ -69,6 +71,10 @@ public: TINY_GSM_YIELD(); rx.clear(); sock_connected = at->modemConnect(host, port, mux); + // sock_connected = at->modemConnect(host, port, &mux); + // at->sockets[mux] = this; + // ^^ TODO: attach the socet after attempting connection or above at init? + // Currently done inconsistently between modems return sock_connected; } @@ -128,7 +134,7 @@ public: continue; } // TODO: Read directly into user buffer? - if (!rx.size()) { + if (!rx.size() && sock_connected) { at->maintain(); } } diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 669bd3b..51900a7 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -62,6 +62,8 @@ public: got_data = false; at->sockets[mux] = this; + // ^^ TODO: attach the socket here at init? Or later at connect? + // Currently done inconsistently between modems return true; } @@ -72,6 +74,10 @@ public: TINY_GSM_YIELD(); rx.clear(); sock_connected = at->modemConnect(host, port, mux); + // sock_connected = at->modemConnect(host, port, &mux); + // at->sockets[mux] = this; + // ^^ TODO: attach the socet after attempting connection or above at init? + // Currently done inconsistently between modems return sock_connected; } @@ -97,7 +103,7 @@ public: rx.clear(); at->maintain(); while (sock_available > 0) { - sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); + at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); rx.clear(); at->maintain(); } @@ -696,6 +702,7 @@ protected: return 0; } size_t len = stream.readStringUntil('\n').toInt(); + sockets[mux]->sock_available = len; for (size_t i=0; isockets[mux] = this; + // ^^ TODO: attach the socket here at init? Or later at connect? + // Currently done inconsistently between modems return true; } @@ -76,6 +78,10 @@ public: TINY_GSM_YIELD(); rx.clear(); sock_connected = at->modemConnect(host, port, mux); + // sock_connected = at->modemConnect(host, port, &mux); + // at->sockets[mux] = this; + // ^^ TODO: attach the socet after attempting connection or above at init? + // Currently done inconsistently between modems return sock_connected; } @@ -101,7 +107,7 @@ public: rx.clear(); at->maintain(); while (sock_available > 0) { - sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); + at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); rx.clear(); at->maintain(); } @@ -724,6 +730,7 @@ protected: return 0; } size_t len = stream.readStringUntil('\n').toInt(); + sockets[mux]->sock_available = len; for (size_t i=0; isockets[mux] = this; + // ^^ TODO: attach the socket here at init? Or later at connect? + // Currently done inconsistently between modems return true; } @@ -81,6 +83,10 @@ public: TINY_GSM_YIELD(); rx.clear(); sock_connected = at->modemConnect(host, port, mux); + // sock_connected = at->modemConnect(host, port, &mux); + // at->sockets[mux] = this; + // ^^ TODO: attach the socet after attempting connection or above at init? + // Currently done inconsistently between modems return sock_connected; } @@ -106,7 +112,7 @@ public: rx.clear(); at->maintain(); while (sock_available > 0) { - sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); + at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); rx.clear(); at->maintain(); } @@ -228,6 +234,9 @@ public: TINY_GSM_YIELD(); rx.clear(); sock_connected = at->modemConnect(host, port, mux, true); + // sock_connected = at->modemConnect(host, port, &mux, true); + // at->sockets[mux] = this; + // TODO: When is the socket attached? return sock_connected; } }; @@ -421,6 +430,7 @@ public: RegStatus getRegistrationStatus() { sendAT(GF("+CGREG?")); + // TODO: Shouldn't this be CEREG for the EPS status of this 4G module? if (waitResponse(GF(GSM_NL "+CGREG:")) != 1) { return REG_UNKNOWN; } diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 764b411..f3edce4 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -68,6 +68,8 @@ public: got_data = false; at->sockets[mux] = this; + // ^^ TODO: attach the socket here at init? Or later at connect? + // Currently done inconsistently between modems return true; } @@ -78,6 +80,10 @@ public: TINY_GSM_YIELD(); rx.clear(); sock_connected = at->modemConnect(host, port, mux); + // sock_connected = at->modemConnect(host, port, &mux); + // at->sockets[mux] = this; + // ^^ TODO: attach the socet after attempting connection or above at init? + // Currently done inconsistently between modems return sock_connected; } @@ -103,7 +109,7 @@ public: rx.clear(); at->maintain(); while (sock_available > 0) { - sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); + at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); rx.clear(); at->maintain(); } @@ -223,6 +229,9 @@ public: TINY_GSM_YIELD(); rx.clear(); sock_connected = at->modemConnect(host, port, mux, true); + // sock_connected = at->modemConnect(host, port, &mux, true); + // at->sockets[mux] = this; + // TODO: When is the socket attached? return sock_connected; } }; diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index c5384d6..4eeadcf 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -61,6 +61,11 @@ public: prev_check = 0; sock_connected = false; got_data = false; + + // at->sockets[mux] = this; + // ^^ TODO: attach the socket here at init? Or later at connect? + // Currently done inconsistently between modems + return true; } @@ -81,8 +86,11 @@ public: } TINY_GSM_YIELD(); rx.clear(); + // sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, &mux); at->sockets[mux] = this; + // ^^ TODO: attach the socet after attempting connection or above at init? + // Currently done inconsistently between modems at->maintain(); return sock_connected; } @@ -109,7 +117,7 @@ public: rx.clear(); at->maintain(); while (sock_available > 0) { - sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); + at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); rx.clear(); at->maintain(); } @@ -229,8 +237,10 @@ public: stop(); TINY_GSM_YIELD(); rx.clear(); + // sock_connected = at->modemConnect(host, port, mux, true); sock_connected = at->modemConnect(host, port, &mux, true); at->sockets[mux] = this; + // TODO: When is the socket attached? at->maintain(); return sock_connected; } @@ -809,6 +819,7 @@ protected: } streamSkipUntil(','); // Skip mux size_t len = stream.readStringUntil(',').toInt(); + sockets[mux]->sock_available = len; streamSkipUntil('\"'); for (size_t i=0; i 0) { int a = stream.read(); - if (a < 0) continue; + if (a <= 0) continue; // Skip 0x00 bytes, just in case data += (char)a; if (r1 && data.endsWith(r1)) { index = 1; @@ -926,7 +937,7 @@ public: sockets[mux]->sock_connected = false; } data = ""; - DBG("### Closed:", mux); + DBG("### Closed: ", mux); } } } while (millis() - startMillis < timeout);