diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 847de75..d701446 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -506,7 +506,7 @@ protected: bool modemConnect(const char* host, uint16_t port, uint8_t* mux, int timeout_s = 75) { unsigned long startMillis = millis(); - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; sendAT(GF("+CIPSTART="), GF("\"TCP"), GF("\",\""), host, GF("\","), port); if (waitResponse(timeout_ms, GF(GSM_NL "+CIPNUM:")) != 1) { diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 6902250..b36f16b 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -474,7 +474,7 @@ protected: bool ssl = false, int timeout_s = 20) { int rsp; - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; // (1-16), (0-11),"TCP/UDP/TCP LISTENER/UDP SERVICE", // "/",,,(0-2 0=buffer) diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 62ee45a..af8df8f 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -334,7 +334,7 @@ protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false, int timeout_s = 75) { - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; if (ssl) { sendAT(GF("+CIPSSLSIZE=4096")); waitResponse(); diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index e2a047d..f08b8c8 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -414,7 +414,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, int timeout_s = 75) { - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; for (int i=0; i<3; i++) { // TODO: no need for loop? String ip = dnsIpQuery(host); diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 8121d8b..1f83b22 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -521,7 +521,7 @@ protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false, int timeout_s = 75) { - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port); int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 997b489..4f62903 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -540,7 +540,7 @@ protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false, int timeout_s = 75) { - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port); int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index 96a9b34..8e6878d 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -764,7 +764,7 @@ protected: bool ssl = false, int timeout_s = 75) { int rsp; - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port); rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 816a530..cd1b9fa 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -685,7 +685,7 @@ protected: bool ssl = false, int timeout_s = 75) { int rsp; - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; #if !defined(TINY_GSM_MODEM_SIM900) sendAT(GF("+CIPSSL="), ssl); rsp = waitResponse(); diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 34f9688..5e3f058 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -531,7 +531,7 @@ protected: bool modemConnect(const char* host, uint16_t port, uint8_t* mux, bool ssl = false, int timeout_s = 120) { - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; sendAT(GF("+USOCR=6")); // create a socket if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { // reply is +USOCR: ## of socket created return false; diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index 1401c10..286840d 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -482,7 +482,7 @@ protected: { int rsp; unsigned long startMillis = millis(); - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; if (ssl) { // enable SSl and use security profile 1 diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 3a259e4..e1ca4d7 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -514,7 +514,7 @@ protected: bool modemConnect(const char* host, uint16_t port, uint8_t* mux, bool ssl = false, int timeout_s = 120) { - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; sendAT(GF("+USOCR=6")); // create a socket if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { // reply is +USOCR: ## of socket created return false; diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 3a71f8a..e018353 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -645,15 +645,17 @@ public: } bool waitForNetwork(unsigned long timeout_ms = 60000L) { + bool retVal = false; XBEE_COMMAND_START_DECORATOR(5, false) for (unsigned long start = millis(); millis() - start < timeout_ms; ) { if (isNetworkConnected()) { - return true; + retVal = true; + break; } delay(250); // per Neil H. - more stable with delay } XBEE_COMMAND_END_DECORATOR - return false; + return retVal; } /* @@ -662,28 +664,30 @@ public: bool networkConnect(const char* ssid, const char* pwd) { + bool retVal = true; XBEE_COMMAND_START_DECORATOR(5, false) //nh For no pwd don't set setscurity or pwd - if (NULL == ssid ) return exitAndFail(); + if (ssid == NULL) retVal = false;; - if (NULL != pwd) + if (pwd != NULL) { sendAT(GF("EE"), 2); // Set security to WPA2 - if (waitResponse() != 1) return exitAndFail(); + if (waitResponse() != 1) retVal = false; sendAT(GF("PK"), pwd); } else { sendAT(GF("EE"), 0); // Set No security } - if (waitResponse() != 1) return exitAndFail(); + if (waitResponse() != 1) retVal = false; sendAT(GF("ID"), ssid); - if (waitResponse() != 1) return exitAndFail(); + if (waitResponse() != 1) retVal = false; + + if (!writeChanges()) retVal = false; - if (!writeChanges()) return exitAndFail(); XBEE_COMMAND_END_DECORATOR - return true; + return retVal; } bool networkDisconnect() { @@ -794,18 +798,18 @@ protected: IPAddress getHostIP(const char* host, int timeout_s = 45) { String strIP; strIP.reserve(16); unsigned long startMillis = millis(); - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; bool gotIP = false; XBEE_COMMAND_START_DECORATOR(5, IPAddress(0,0,0,0)) // XBee's require a numeric IP address for connection, but do provide the // functionality to look up the IP address from a fully qualified domain name - while (millis() - startMillis < timeout_ms) // the lookup can take a while + while ((millis() - startMillis) < timeout_ms) // the lookup can take a while { sendAT(GF("LA"), host); - while (stream.available() < 4 && (millis() - startMillis < timeout_ms)) {}; // wait for any response + while (stream.available() < 4 && (millis() - startMillis < timeout_ms)) {TINY_GSM_YIELD()}; strIP = stream.readStringUntil('\r'); // read result strIP.trim(); - if (!strIP.endsWith(GF("ERROR"))) { + if (strIP != "" && strIP != GF("ERROR")) { gotIP = true; break; } @@ -824,7 +828,7 @@ protected: bool ssl = false, int timeout_s = 75) { unsigned long startMillis = millis(); - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; bool retVal = false; XBEE_COMMAND_START_DECORATOR(5, false) @@ -849,7 +853,7 @@ protected: savedIP = ip; // Set the newly requested IP address bool success = true; - uint32_t timeout_ms = timeout_s*1000; + uint32_t timeout_ms = ((uint32_t)timeout_s)*1000; XBEE_COMMAND_START_DECORATOR(5, false) String host; host.reserve(16); host += ip[0]; @@ -896,25 +900,25 @@ protected: // really be open, but no data has yet been sent. We return this unknown value // as true so there's a possibility it's wrong. bool modemGetConnected() { - - XBEE_COMMAND_START_DECORATOR(5, false) - // If the IP address is 0, it's not valid so we can't be connected if (savedIP == IPAddress(0,0,0,0)) return false; + XBEE_COMMAND_START_DECORATOR(5, false) + // Verify that we're connected to the *right* IP address // We might be connected - but to the wrong thing // NOTE: In transparent mode, there is only one connection possible - no multiplex - String strIP; strIP.reserve(16); - sendAT(GF("DL")); - strIP = stream.readStringUntil('\r'); // read result - if (TinyGsmIpFromString(strIP) != savedIP) return exitAndFail(); + // String strIP; strIP.reserve(16); + // sendAT(GF("DL")); + // strIP = stream.readStringUntil('\r'); // read result + // if (TinyGsmIpFromString(strIP) != savedIP) return exitAndFail(); if (beeType == XBEE_UNKNOWN) getSeries(); // Need to know the bee type to interpret response switch (beeType){ // The wifi be can only say if it's connected to the netowrk case XBEE_S6B_WIFI: { RegStatus s = getRegistrationStatus(); + XBEE_COMMAND_END_DECORATOR if (s != REG_OK) { sockets[0]->sock_connected = false; // no multiplex } @@ -926,6 +930,7 @@ protected: XBEE_COMMAND_END_DECORATOR switch(intRes) { case 0x00: // 0x00 = The socket is definitely open + case 0x28: // 0x28 = "Unknown." case 0xFF: // 0xFF = No known status - this is always returned prior to sending data return true; case 0x02: // 0x02 = Invalid parameters (bad IP/host)