mirror of
				https://github.com/KevinMidboe/TinyGSM.git
				synced 2025-10-29 18:00:18 +00:00 
			
		
		
		
	Clarify units of timeouts
This commit is contained in:
		| @@ -66,12 +66,12 @@ public: | ||||
|   } | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     uint8_t newMux = -1; | ||||
|     sock_connected = at->modemConnect(host, port, &newMux, timeout) | ||||
|     sock_connected = at->modemConnect(host, port, &newMux, timeout_s) | ||||
|     if (sock_connected) { | ||||
|       mux = newMux; | ||||
|       at->sockets[mux] = this; | ||||
| @@ -222,8 +222,8 @@ TINY_GSM_MODEM_SIM_UNLOCK_CPIN() | ||||
|  | ||||
| TINY_GSM_MODEM_GET_IMEI_GSN() | ||||
|  | ||||
|   SimStatus getSimStatus(unsigned long timeout = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("+CPIN?")); | ||||
|       if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { | ||||
|         delay(1000); | ||||
| @@ -504,16 +504,17 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() | ||||
|  | ||||
| protected: | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t* mux, int timeout = 75000L) { | ||||
|   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; | ||||
|  | ||||
|     sendAT(GF("+CIPSTART="),  GF("\"TCP"), GF("\",\""), host, GF("\","), port); | ||||
|     if (waitResponse(timeout, GF(GSM_NL "+CIPNUM:")) != 1) { | ||||
|     if (waitResponse(timeout_ms, GF(GSM_NL "+CIPNUM:")) != 1) { | ||||
|       return false; | ||||
|     } | ||||
|     int newMux = stream.readStringUntil('\n').toInt(); | ||||
|  | ||||
|     int rsp = waitResponse((timeout - (millis() - startMillis)), | ||||
|     int rsp = waitResponse((timeout_ms- (millis() - startMillis)), | ||||
|                            GF("CONNECT OK" GSM_NL), | ||||
|                            GF("CONNECT FAIL" GSM_NL), | ||||
|                            GF("ALREADY CONNECT" GSM_NL)); | ||||
| @@ -554,7 +555,7 @@ public: | ||||
| TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|  | ||||
|   // TODO: Optimize this! | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
| @@ -614,7 +615,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           DBG("### Closed: ", mux); | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -627,12 +628,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|   | ||||
| @@ -71,11 +71,11 @@ public: | ||||
|   } | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
|  | ||||
| @@ -134,11 +134,11 @@ private: | ||||
| //   {} | ||||
| // | ||||
| // public: | ||||
| //   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
| //   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
| //     stop(); | ||||
| //     TINY_GSM_YIELD(); | ||||
| //     rx.clear(); | ||||
| //     sock_connected = at->modemConnect(host, port, mux, true, timeout); | ||||
| //     sock_connected = at->modemConnect(host, port, mux, true, timeout_s); | ||||
| //     return sock_connected; | ||||
| //   } | ||||
| // }; | ||||
| @@ -257,8 +257,8 @@ TINY_GSM_MODEM_SIM_UNLOCK_CPIN() | ||||
|  | ||||
| TINY_GSM_MODEM_GET_IMEI_GSN() | ||||
|  | ||||
|   SimStatus getSimStatus(unsigned long timeout = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("+CPIN?")); | ||||
|       if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { | ||||
|         delay(1000); | ||||
| @@ -471,15 +471,17 @@ TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED() | ||||
| protected: | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t mux, | ||||
|                     bool ssl = false, int timeout = 20000L) | ||||
|                     bool ssl = false, int timeout_s = 20) | ||||
|  { | ||||
|     int rsp; | ||||
|     uint32_t timeout_ms = timeout_s*1000; | ||||
|  | ||||
|     // <PDPcontextID>(1-16), <connectID>(0-11),"TCP/UDP/TCP LISTENER/UDP SERVICE", | ||||
|     // "<IP_address>/<domain_name>",<remote_port>,<local_port>,<access_mode>(0-2 0=buffer) | ||||
|     sendAT(GF("+QIOPEN=1,"), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port, GF(",0,0")); | ||||
|     rsp = waitResponse(); | ||||
|  | ||||
|     if (waitResponse(timeout, GF(GSM_NL "+QIOPEN:")) != 1) { | ||||
|     if (waitResponse(timeout_ms, GF(GSM_NL "+QIOPEN:")) != 1) { | ||||
|       return false; | ||||
|     } | ||||
|  | ||||
| @@ -569,7 +571,7 @@ public: | ||||
| TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|  | ||||
|   // TODO: Optimize this! | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
| @@ -625,7 +627,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           data = ""; | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -638,12 +640,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|   | ||||
| @@ -68,11 +68,11 @@ public: | ||||
|   } | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
|  | ||||
| @@ -118,11 +118,11 @@ public: | ||||
|   {} | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     sock_connected = at->modemConnect(host, port, mux, true, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, true, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
| }; | ||||
| @@ -270,8 +270,8 @@ TINY_GSM_MODEM_MAINTAIN_LISTEN() | ||||
|     return (s == REG_OK_IP || s == REG_OK_TCP); | ||||
|   } | ||||
|  | ||||
|   bool waitForNetwork(unsigned long timeout = 60000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   bool waitForNetwork(unsigned long timeout_ms = 60000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("+CIPSTATUS")); | ||||
|       int res1 = waitResponse(3000, GF("busy p..."), GF("STATUS:")); | ||||
|       if (res1 == 2) { | ||||
| @@ -332,8 +332,9 @@ TINY_GSM_MODEM_MAINTAIN_LISTEN() | ||||
| protected: | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t mux, | ||||
|                     bool ssl = false, int timeout = 75000L) | ||||
|                     bool ssl = false, int timeout_s = 75) | ||||
|  { | ||||
|     uint32_t timeout_ms = timeout_s*1000; | ||||
|     if (ssl) { | ||||
|       sendAT(GF("+CIPSSLSIZE=4096")); | ||||
|       waitResponse(); | ||||
| @@ -341,7 +342,7 @@ protected: | ||||
|     sendAT(GF("+CIPSTART="), mux, ',', ssl ? GF("\"SSL") : GF("\"TCP"), | ||||
|            GF("\",\""), host, GF("\","), port, GF(","), TINY_GSM_TCP_KEEP_ALIVE); | ||||
|     // TODO: Check mux | ||||
|     int rsp = waitResponse(timeout, | ||||
|     int rsp = waitResponse(timeout_ms, | ||||
|                            GFP(GSM_OK), | ||||
|                            GFP(GSM_ERROR), | ||||
|                            GF("ALREADY CONNECT")); | ||||
| @@ -376,7 +377,7 @@ public: | ||||
| TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|  | ||||
|   // TODO: Optimize this! | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
| @@ -438,7 +439,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           DBG("### Closed: ", mux); | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -451,12 +452,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|   | ||||
| @@ -68,11 +68,11 @@ public: | ||||
|   } | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout_s); | ||||
|  | ||||
|     return sock_connected; | ||||
|   } | ||||
| @@ -219,8 +219,8 @@ TINY_GSM_MODEM_GET_SIMCCID_CCID() | ||||
|  | ||||
| TINY_GSM_MODEM_GET_IMEI_GSN() | ||||
|  | ||||
|   SimStatus getSimStatus(unsigned long timeout = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("+CPIN?")); | ||||
|       if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { | ||||
|         delay(1000); | ||||
| @@ -276,8 +276,8 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() | ||||
|     sendAT(GF("+XIIC=1")); | ||||
|     waitResponse(); | ||||
|  | ||||
|     const unsigned long timeout = 60000L; | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|     const unsigned long timeout_ms = 60000L; | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       if (isGprsConnected()) { | ||||
|         //goto set_dns; // TODO | ||||
|         return true; | ||||
| @@ -413,12 +413,13 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() | ||||
|  | ||||
| protected: | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t mux, int timeout = 75000L) { | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t mux, int timeout_s = 75) { | ||||
|     uint32_t timeout_ms = timeout_s*1000; | ||||
|     for (int i=0; i<3; i++) { // TODO: no need for loop? | ||||
|       String ip = dnsIpQuery(host); | ||||
|  | ||||
|       sendAT(GF("+TCPSETUP="), mux, GF(","), ip, GF(","), port); | ||||
|       int rsp = waitResponse(timeout, | ||||
|       int rsp = waitResponse(timeout_ms, | ||||
|                             GF(",OK" GSM_NL), | ||||
|                             GF(",FAIL" GSM_NL), | ||||
|                             GF("+TCPSETUP:Error" GSM_NL)); | ||||
| @@ -475,7 +476,7 @@ public: | ||||
| TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|  | ||||
|   // TODO: Optimize this! | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
| @@ -536,7 +537,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           DBG("### Closed: ", mux); | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -549,12 +550,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|   | ||||
| @@ -71,11 +71,11 @@ public: | ||||
|   } | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
|  | ||||
| @@ -134,11 +134,11 @@ private: | ||||
| //   {} | ||||
| // | ||||
| // public: | ||||
| //   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
| //   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
| //     stop(); | ||||
| //     TINY_GSM_YIELD(); | ||||
| //     rx.clear(); | ||||
| //     sock_connected = at->modemConnect(host, port, mux, true, timeout); | ||||
| //     sock_connected = at->modemConnect(host, port, mux, true, timeout_s); | ||||
| //     return sock_connected; | ||||
| //   } | ||||
| // }; | ||||
| @@ -265,8 +265,8 @@ TINY_GSM_MODEM_SIM_UNLOCK_CPIN() | ||||
|  | ||||
| TINY_GSM_MODEM_GET_IMEI_GSN() | ||||
|  | ||||
|   SimStatus getSimStatus(unsigned long timeout = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("+CPIN?")); | ||||
|       if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { | ||||
|         delay(1000); | ||||
| @@ -519,10 +519,11 @@ TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED() | ||||
| protected: | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t mux, | ||||
|                     bool ssl = false, int timeout = 75000L) | ||||
|                     bool ssl = false, int timeout_s = 75) | ||||
|  { | ||||
|     uint32_t timeout_ms = timeout_s*1000; | ||||
|     sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port); | ||||
|     int rsp = waitResponse(timeout, | ||||
|     int rsp = waitResponse(timeout_ms, | ||||
|                            GF("CONNECT OK" GSM_NL), | ||||
|                            GF("CONNECT FAIL" GSM_NL), | ||||
|                            GF("ALREADY CONNECT" GSM_NL)); | ||||
| @@ -624,7 +625,7 @@ public: | ||||
| TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|  | ||||
|   // TODO: Optimize this! | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
| @@ -677,7 +678,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           DBG("### Closed: ", mux); | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -690,12 +691,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|   | ||||
| @@ -75,11 +75,11 @@ public: | ||||
|   } | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
|  | ||||
| @@ -138,11 +138,11 @@ private: | ||||
| //   {} | ||||
| // | ||||
| // public: | ||||
| //   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
| //   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
| //     stop(); | ||||
| //     TINY_GSM_YIELD(); | ||||
| //     rx.clear(); | ||||
| //     sock_connected = at->modemConnect(host, port, mux, true, timeout); | ||||
| //     sock_connected = at->modemConnect(host, port, mux, true, timeout_s); | ||||
| //     return sock_connected; | ||||
| //   } | ||||
| // }; | ||||
| @@ -278,8 +278,8 @@ TINY_GSM_MODEM_GET_SIMCCID_CCID() | ||||
|  | ||||
| TINY_GSM_MODEM_GET_IMEI_GSN() | ||||
|  | ||||
|   SimStatus getSimStatus(unsigned long timeout = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("+CPIN?")); | ||||
|       if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { | ||||
|         delay(1000); | ||||
| @@ -538,10 +538,11 @@ TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED() | ||||
| protected: | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t mux, | ||||
|                     bool ssl = false, int timeout = 75000L) | ||||
|                     bool ssl = false, int timeout_s = 75) | ||||
|  { | ||||
|     uint32_t timeout_ms = timeout_s*1000; | ||||
|     sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port); | ||||
|     int rsp = waitResponse(timeout, | ||||
|     int rsp = waitResponse(timeout_ms, | ||||
|                            GF("CONNECT OK" GSM_NL), | ||||
|                            GF("CONNECT FAIL" GSM_NL), | ||||
|                            GF("ALREADY CONNECT" GSM_NL)); | ||||
| @@ -644,7 +645,7 @@ public: | ||||
| TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|  | ||||
|   // TODO: Optimize this! | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL, GsmConstStr r6=NULL) | ||||
|   { | ||||
| @@ -701,7 +702,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           DBG("### Closed: ", mux); | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -714,12 +715,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL, GsmConstStr r6=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5, r6); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5, r6); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|   | ||||
| @@ -76,11 +76,11 @@ public: | ||||
|   } | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
|  | ||||
| @@ -140,11 +140,11 @@ public: | ||||
|   {} | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     sock_connected = at->modemConnect(host, port, mux, true, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, true, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
| }; | ||||
| @@ -269,8 +269,8 @@ TINY_GSM_MODEM_GET_SIMCCID_CCID() | ||||
|  | ||||
| TINY_GSM_MODEM_GET_IMEI_GSN() | ||||
|  | ||||
|   SimStatus getSimStatus(unsigned long timeout = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("+CPIN?")); | ||||
|       if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { | ||||
|         delay(1000); | ||||
| @@ -761,11 +761,12 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() | ||||
| protected: | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t mux, | ||||
|                     bool ssl = false, int timeout = 75000L) | ||||
|                     bool ssl = false, int timeout_s = 75) | ||||
|  { | ||||
|     int rsp; | ||||
|     uint32_t timeout_ms = timeout_s*1000; | ||||
|     sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port); | ||||
|     rsp = waitResponse(timeout, | ||||
|     rsp = waitResponse(timeout_ms, | ||||
|                        GF("CONNECT OK" GSM_NL), | ||||
|                        GF("CONNECT FAIL" GSM_NL), | ||||
|                        GF("ALREADY CONNECT" GSM_NL), | ||||
| @@ -862,7 +863,7 @@ public: | ||||
| TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|  | ||||
|   // TODO: Optimize this! | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
| @@ -928,7 +929,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           DBG("### Closed: ", mux); | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -941,12 +942,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|   | ||||
| @@ -77,11 +77,11 @@ public: | ||||
|   } | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
|  | ||||
| @@ -141,11 +141,11 @@ public: | ||||
|   {} | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     sock_connected = at->modemConnect(host, port, mux, true, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, true, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
| }; | ||||
| @@ -301,8 +301,8 @@ TINY_GSM_MODEM_GET_SIMCCID_CCID() | ||||
|  | ||||
| TINY_GSM_MODEM_GET_IMEI_GSN() | ||||
|  | ||||
|   SimStatus getSimStatus(unsigned long timeout = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("+CPIN?")); | ||||
|       if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { | ||||
|         delay(1000); | ||||
| @@ -682,9 +682,10 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() | ||||
| protected: | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t mux, | ||||
|                     bool ssl = false, int timeout = 75000L) | ||||
|                     bool ssl = false, int timeout_s = 75) | ||||
|  { | ||||
|     int rsp; | ||||
|     uint32_t timeout_ms = timeout_s*1000; | ||||
| #if !defined(TINY_GSM_MODEM_SIM900) | ||||
|     sendAT(GF("+CIPSSL="), ssl); | ||||
|     rsp = waitResponse(); | ||||
| @@ -693,7 +694,7 @@ protected: | ||||
|     } | ||||
| #endif | ||||
|     sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port); | ||||
|     rsp = waitResponse(timeout, | ||||
|     rsp = waitResponse(timeout_ms, | ||||
|                        GF("CONNECT OK" GSM_NL), | ||||
|                        GF("CONNECT FAIL" GSM_NL), | ||||
|                        GF("ALREADY CONNECT" GSM_NL), | ||||
| @@ -790,7 +791,7 @@ public: | ||||
| TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|  | ||||
|   // TODO: Optimize this! | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
| @@ -856,7 +857,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           DBG("### Closed: ", mux); | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -869,12 +870,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|   | ||||
| @@ -72,7 +72,7 @@ public: | ||||
|   } | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     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. | ||||
| @@ -94,7 +94,7 @@ public: | ||||
|     rx.clear(); | ||||
|  | ||||
|     uint8_t oldMux = mux; | ||||
|     sock_connected = at->modemConnect(host, port, &mux, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, &mux, timeout_s); | ||||
|     if (mux != oldMux) { | ||||
|         DBG("WARNING:  Mux number changed from", oldMux, "to", mux); | ||||
|         at->sockets[oldMux] = NULL; | ||||
| @@ -159,12 +159,12 @@ public: | ||||
|   {} | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     uint8_t oldMux = mux; | ||||
|     sock_connected = at->modemConnect(host, port, &mux, true, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, &mux, true, timeout_s); | ||||
|     if (mux != oldMux) { | ||||
|         DBG("WARNING:  Mux number changed from", oldMux, "to", mux); | ||||
|         at->sockets[oldMux] = NULL; | ||||
| @@ -325,8 +325,8 @@ TINY_GSM_MODEM_GET_SIMCCID_CCID() | ||||
|     return res; | ||||
|   } | ||||
|  | ||||
|   SimStatus getSimStatus(unsigned long timeout = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("+CPIN?")); | ||||
|       if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { | ||||
|         delay(1000); | ||||
| @@ -529,8 +529,9 @@ TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED() | ||||
| protected: | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t* mux, | ||||
|                     bool ssl = false, int timeout = 120000L) | ||||
|                     bool ssl = false, int timeout_s = 120) | ||||
|   { | ||||
|     uint32_t timeout_ms = 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; | ||||
| @@ -555,7 +556,7 @@ protected: | ||||
|     // TODO:  Use faster "asynchronous" connection? | ||||
|     // We would have to wait for the +UUSOCO URC to verify connection | ||||
|     sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port); | ||||
|     int rsp = waitResponse(timeout); | ||||
|     int rsp = waitResponse(timeout_ms); | ||||
|     return (1 == rsp); | ||||
|   } | ||||
|  | ||||
| @@ -663,7 +664,7 @@ public: | ||||
| TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|  | ||||
|   // TODO: Optimize this! | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=GFP(GSM_CME_ERROR), GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
| @@ -715,7 +716,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           DBG("### Closed: ", mux); | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -728,12 +729,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=GFP(GSM_CME_ERROR), GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|   | ||||
| @@ -83,11 +83,11 @@ public: | ||||
|   } | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     if (sock_connected) stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
|  | ||||
| @@ -150,7 +150,7 @@ protected: | ||||
|   bool          strictSSL = false; | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
| @@ -172,7 +172,7 @@ public: | ||||
|       return false; | ||||
|     } | ||||
|  | ||||
|     sock_connected = at->modemConnect(host, port, mux, true, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, true, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
|  | ||||
| @@ -217,8 +217,8 @@ public: | ||||
|  | ||||
| TINY_GSM_MODEM_SET_BAUD_IPR() | ||||
|  | ||||
|   bool testAT(unsigned long timeout = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   bool testAT(unsigned long timeout_ms = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("")); | ||||
|       if (waitResponse(200) == 1) { | ||||
|           delay(100); | ||||
| @@ -317,8 +317,8 @@ TINY_GSM_MODEM_SIM_UNLOCK_CPIN() | ||||
|  | ||||
| TINY_GSM_MODEM_GET_IMEI_GSN() | ||||
|  | ||||
|   SimStatus getSimStatus(unsigned long timeout = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("+CPIN?")); | ||||
|       if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { | ||||
|         delay(1000); | ||||
| @@ -478,10 +478,11 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK() | ||||
| protected: | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t mux, | ||||
|                     bool ssl = false, int timeout = 75000L) | ||||
|                     bool ssl = false, int timeout_s = 75) | ||||
|  { | ||||
|     int rsp; | ||||
|     unsigned long startMillis = millis(); | ||||
|     uint32_t timeout_ms = timeout_s*1000; | ||||
|  | ||||
|     if (ssl) { | ||||
|       // enable SSl and use security profile 1 | ||||
| @@ -499,7 +500,7 @@ protected: | ||||
|     waitResponse(); | ||||
|  | ||||
|     sendAT(GF("+SQNSD="), mux, ",0,", port, ',', GF("\""), host, GF("\""), ",0,0,1"); | ||||
|     rsp = waitResponse((timeout - (millis() - startMillis)), | ||||
|     rsp = waitResponse((timeout_ms - (millis() - startMillis)), | ||||
|                       GF("OK" GSM_NL), | ||||
|                       GF("NO CARRIER" GSM_NL) | ||||
|                       ); | ||||
| @@ -509,7 +510,7 @@ protected: | ||||
|  | ||||
|     // wait until we get a good status | ||||
|     bool connected = false; | ||||
|     while (!connected && ((millis() - startMillis) < timeout)) { | ||||
|     while (!connected && ((millis() - startMillis) < timeout_ms)) { | ||||
|       connected = modemGetConnected(mux); | ||||
|       delay(100); // socket may be in opening state | ||||
|     } | ||||
| @@ -593,7 +594,7 @@ public: | ||||
| TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|  | ||||
|   // TODO: Optimize this! | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
| @@ -643,7 +644,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           DBG("### Closed: ", mux); | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -655,12 +656,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|   | ||||
| @@ -72,13 +72,13 @@ public: | ||||
|   } | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|  | ||||
|     uint8_t oldMux = mux; | ||||
|     sock_connected = at->modemConnect(host, port, &mux, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, &mux, timeout_s); | ||||
|     if (mux != oldMux) { | ||||
|         DBG("WARNING:  Mux number changed from", oldMux, "to", mux); | ||||
|         at->sockets[oldMux] = NULL; | ||||
| @@ -143,12 +143,12 @@ public: | ||||
|   {} | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     stop(); | ||||
|     TINY_GSM_YIELD(); | ||||
|     rx.clear(); | ||||
|     uint8_t oldMux = mux; | ||||
|     sock_connected = at->modemConnect(host, port, &mux, true, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, &mux, true, timeout_s); | ||||
|     if (mux != oldMux) { | ||||
|         DBG("WARNING:  Mux number changed from", oldMux, "to", mux); | ||||
|         at->sockets[oldMux] = NULL; | ||||
| @@ -314,8 +314,8 @@ TINY_GSM_MODEM_GET_SIMCCID_CCID() | ||||
|     return res; | ||||
|   } | ||||
|  | ||||
|   SimStatus getSimStatus(unsigned long timeout = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|   SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       sendAT(GF("+CPIN?")); | ||||
|       if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { | ||||
|         delay(1000); | ||||
| @@ -512,8 +512,9 @@ TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED() | ||||
| protected: | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t* mux, | ||||
|                     bool ssl = false, int timeout = 120000L) | ||||
|                     bool ssl = false, int timeout_s = 120) | ||||
|   { | ||||
|     uint32_t timeout_ms = 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; | ||||
| @@ -538,7 +539,7 @@ protected: | ||||
|     // TODO:  Use faster "asynchronous" connection? | ||||
|     // We would have to wait for the +UUSOCO URC to verify connection | ||||
|     sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port); | ||||
|     int rsp = waitResponse(timeout); | ||||
|     int rsp = waitResponse(timeout_ms); | ||||
|     return (1 == rsp); | ||||
|   } | ||||
|  | ||||
| @@ -648,7 +649,7 @@ public: | ||||
| TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|  | ||||
|   // TODO: Optimize this! | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=GFP(GSM_CME_ERROR), GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
| @@ -700,7 +701,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           DBG("### Closed: ", mux); | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -713,12 +714,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=GFP(GSM_CME_ERROR), GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|   | ||||
| @@ -96,20 +96,20 @@ public: | ||||
|   // last set.  The TCP connection itself is not opened until you attempt to send data. | ||||
|   // Because all settings are saved to flash, it is possible (or likely) that | ||||
|   // you could send data even if you haven't "made" any connection. | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     // NOTE:  Not caling stop() or yeild() here | ||||
|     at->streamClear();  // Empty anything in the buffer before starting | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
|   virtual int connect(const char *host, uint16_t port) { | ||||
|     return connect(host, port, 75000L); | ||||
|   } | ||||
|  | ||||
|   virtual int connect(IPAddress ip, uint16_t port, int timeout) { | ||||
|   virtual int connect(IPAddress ip, uint16_t port, int timeout_s) { | ||||
|     // NOTE:  Not caling stop() or yeild() here | ||||
|     at->streamClear();  // Empty anything in the buffer before starting | ||||
|     sock_connected = at->modemConnect(ip, port, mux, timeout); | ||||
|     sock_connected = at->modemConnect(ip, port, mux, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
|   virtual int connect(IPAddress ip, uint16_t port) { | ||||
| @@ -237,17 +237,17 @@ public: | ||||
|   {} | ||||
|  | ||||
| public: | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout) { | ||||
|   virtual int connect(const char *host, uint16_t port, int timeout_s) { | ||||
|     // NOTE:  Not caling stop() or yeild() here | ||||
|     at->streamClear();  // Empty anything in the buffer before starting | ||||
|     sock_connected = at->modemConnect(host, port, mux, true, timeout); | ||||
|     sock_connected = at->modemConnect(host, port, mux, true, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
|  | ||||
|   virtual int connect(IPAddress ip, uint16_t port, int timeout) { | ||||
|   virtual int connect(IPAddress ip, uint16_t port, int timeout_s) { | ||||
|     // NOTE:  Not caling stop() or yeild() here | ||||
|     at->streamClear();  // Empty anything in the buffer before starting | ||||
|     sock_connected = at->modemConnect(ip, port, mux, timeout); | ||||
|     sock_connected = at->modemConnect(ip, port, mux, timeout_s); | ||||
|     return sock_connected; | ||||
|   } | ||||
| }; | ||||
| @@ -347,10 +347,10 @@ public: | ||||
|     XBEE_COMMAND_END_DECORATOR | ||||
|   } | ||||
|  | ||||
|   bool testAT(unsigned long timeout = 10000L) { | ||||
|   bool testAT(unsigned long timeout_ms = 10000L) { | ||||
|     unsigned long start = millis(); | ||||
|     bool success = false; | ||||
|     while (!success && millis() - start < timeout) { | ||||
|     while (!success && millis() - start < timeout_ms) { | ||||
|       if (!inCommandMode) { | ||||
|         success = commandMode(); | ||||
|         if (success) exitCommand(); | ||||
| @@ -525,7 +525,7 @@ public: | ||||
|     return sendATGetString(GF("IM")); | ||||
|   } | ||||
|  | ||||
|   SimStatus getSimStatus(unsigned long timeout = 10000L) { | ||||
|   SimStatus getSimStatus(unsigned long timeout_ms = 10000L) { | ||||
|     return SIM_READY;  // unsupported | ||||
|   } | ||||
|  | ||||
| @@ -644,9 +644,9 @@ public: | ||||
|     return (s == REG_OK); | ||||
|   } | ||||
|  | ||||
|   bool waitForNetwork(unsigned long timeout = 60000L) { | ||||
|   bool waitForNetwork(unsigned long timeout_ms = 60000L) { | ||||
|     XBEE_COMMAND_START_DECORATOR(5, false) | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       if (isNetworkConnected()) { | ||||
|         return true; | ||||
|       } | ||||
| @@ -791,17 +791,18 @@ public: | ||||
|  | ||||
| protected: | ||||
|  | ||||
|   IPAddress getHostIP(const char* host, int timeout = 45000L) { | ||||
|   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; | ||||
|     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)  // 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)) {};  // wait for any response | ||||
|       while (stream.available() < 4 && (millis() - startMillis < timeout_ms)) {};  // wait for any response | ||||
|       strIP = stream.readStringUntil('\r');  // read result | ||||
|       strIP.trim(); | ||||
|       if (!strIP.endsWith(GF("ERROR"))) { | ||||
| @@ -820,9 +821,10 @@ protected: | ||||
|   } | ||||
|  | ||||
|   bool modemConnect(const char* host, uint16_t port, uint8_t mux = 0, | ||||
|                     bool ssl = false, int timeout = 75000L) | ||||
|                     bool ssl = false, int timeout_s = 75) | ||||
|   { | ||||
|     unsigned long startMillis = millis(); | ||||
|     uint32_t timeout_ms = timeout_s*1000; | ||||
|     bool retVal = false; | ||||
|      XBEE_COMMAND_START_DECORATOR(5, false) | ||||
|  | ||||
| @@ -830,12 +832,12 @@ protected: | ||||
|     // search for the IP to connect to | ||||
|     if (this->savedHost != String(host) || savedIP == IPAddress(0,0,0,0)) { | ||||
|       this->savedHost = String(host); | ||||
|       savedIP = getHostIP(host, timeout);  // This will return 0.0.0.0 if lookup fails | ||||
|       savedIP = getHostIP(host, timeout_s);  // This will return 0.0.0.0 if lookup fails | ||||
|     } | ||||
|  | ||||
|     // If we now have a valid IP address, use it to connect | ||||
|     if (savedIP != IPAddress(0,0,0,0)) {  // Only re-set connection information if we have an IP address | ||||
|       retVal = modemConnect(savedIP, port, mux, ssl, timeout - (millis() - startMillis)); | ||||
|       retVal = modemConnect(savedIP, port, mux, ssl, timeout_ms - (millis() - startMillis)); | ||||
|     } | ||||
|  | ||||
|     XBEE_COMMAND_END_DECORATOR | ||||
| @@ -843,10 +845,11 @@ protected: | ||||
|     return retVal; | ||||
|   } | ||||
|  | ||||
|   bool modemConnect(IPAddress ip, uint16_t port, uint8_t mux = 0, bool ssl = false, int timeout = 75000L) { | ||||
|   bool modemConnect(IPAddress ip, uint16_t port, uint8_t mux = 0, bool ssl = false, int timeout_s = 75) { | ||||
|  | ||||
|     savedIP = ip;  // Set the newly requested IP address | ||||
|     bool success = true; | ||||
|     uint32_t timeout_ms = timeout_s*1000; | ||||
|     XBEE_COMMAND_START_DECORATOR(5, false) | ||||
|     String host; host.reserve(16); | ||||
|     host += ip[0]; | ||||
| @@ -870,7 +873,7 @@ protected: | ||||
|     sendAT(GF("DE"), String(port, HEX));  // Set the destination port | ||||
|     success &= (1 == waitResponse()); | ||||
|  | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { | ||||
|       if (modemGetConnected()) { | ||||
|         sockets[mux]->sock_connected = true; | ||||
|         break; | ||||
| @@ -956,7 +959,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|   // NOTE:  This function is used while INSIDE command mode, so we're only | ||||
|   // waiting for requested responses.  The XBee has no unsoliliced responses | ||||
|   // (URC's) when in command mode. | ||||
|   uint8_t waitResponse(uint32_t timeout, String& data, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, String& data, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
| @@ -992,7 +995,7 @@ TINY_GSP_MODEM_STREAM_UTILITIES() | ||||
|           goto finish; | ||||
|         } | ||||
|       } | ||||
|     } while (millis() - startMillis < timeout); | ||||
|     } while (millis() - startMillis < timeout_ms); | ||||
| finish: | ||||
|     if (!index) { | ||||
|       data.trim(); | ||||
| @@ -1014,12 +1017,12 @@ finish: | ||||
|     return index; | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(uint32_t timeout, | ||||
|   uint8_t waitResponse(uint32_t timeout_ms, | ||||
|                        GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
|                        GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) | ||||
|   { | ||||
|     String data; | ||||
|     return waitResponse(timeout, data, r1, r2, r3, r4, r5); | ||||
|     return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); | ||||
|   } | ||||
|  | ||||
|   uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), | ||||
| @@ -1092,17 +1095,17 @@ finish: | ||||
|     DBG(GF("### Modem: "), getModemName()); | ||||
|   } | ||||
|  | ||||
|   String readResponseString(uint32_t timeout = 1000) { | ||||
|   String readResponseString(uint32_t timeout_ms = 1000) { | ||||
|     TINY_GSM_YIELD(); | ||||
|     unsigned long startMillis = millis(); | ||||
|     while (!stream.available() && millis() - startMillis < timeout) {}; | ||||
|     while (!stream.available() && millis() - startMillis < timeout_ms) {}; | ||||
|     String res = stream.readStringUntil('\r');  // lines end with carriage returns | ||||
|     res.trim(); | ||||
|     return res; | ||||
|   } | ||||
|  | ||||
|   int16_t readResponseInt(uint32_t timeout = 1000) { | ||||
|     String res = readResponseString(timeout);  // it just works better reading a string first | ||||
|   int16_t readResponseInt(uint32_t timeout_ms = 1000) { | ||||
|     String res = readResponseString(timeout_ms);  // it just works better reading a string first | ||||
|     char buf[5] = {0,}; | ||||
|     res.toCharArray(buf, 5); | ||||
|     int16_t intRes = strtol(buf, 0, 16); | ||||
|   | ||||
| @@ -202,7 +202,7 @@ String TinyGsmDecodeHex16bit(String &instr) { | ||||
| // Connect to a IP address given as an IPAddress object by | ||||
| // converting said IP address to text | ||||
| #define TINY_GSM_CLIENT_CONNECT_OVERLOADS() \ | ||||
|   virtual int connect(IPAddress ip, uint16_t port, int timeout) { \ | ||||
|   virtual int connect(IPAddress ip, uint16_t port, int timeout_s) { \ | ||||
|     String host; host.reserve(16); \ | ||||
|     host += ip[0]; \ | ||||
|     host += "."; \ | ||||
| @@ -211,13 +211,13 @@ String TinyGsmDecodeHex16bit(String &instr) { | ||||
|     host += ip[2]; \ | ||||
|     host += "."; \ | ||||
|     host += ip[3]; \ | ||||
|     return connect(host.c_str(), port, timeout); \ | ||||
|     return connect(host.c_str(), port, timeout_s); \ | ||||
|   } \ | ||||
|   virtual int connect(const char *host, uint16_t port) \ | ||||
|     return connect(host, port, 75000L); \ | ||||
|   virtual int connect(const char *host, uint16_t port) { \ | ||||
|     return connect(host, port, 75); \ | ||||
|   } \ | ||||
|   virtual int connect(IPAddress ip, uint16_t port) \ | ||||
|     return connect(ip, port, 75000L); \ | ||||
|   virtual int connect(IPAddress ip, uint16_t port) { \ | ||||
|     return connect(ip, port, 75); \ | ||||
|   } | ||||
|  | ||||
|  | ||||
| @@ -415,8 +415,8 @@ String TinyGsmDecodeHex16bit(String &instr) { | ||||
|  | ||||
| // Test response to AT commands | ||||
| #define TINY_GSM_MODEM_TEST_AT() \ | ||||
|   bool testAT(unsigned long timeout = 10000L) { \ | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { \ | ||||
|   bool testAT(unsigned long timeout_ms = 10000L) { \ | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { \ | ||||
|       sendAT(GF("")); \ | ||||
|       if (waitResponse(200) == 1) return true; \ | ||||
|       delay(100); \ | ||||
| @@ -535,8 +535,8 @@ String TinyGsmDecodeHex16bit(String &instr) { | ||||
|  | ||||
| // Waits for network attachment | ||||
| #define TINY_GSM_MODEM_WAIT_FOR_NETWORK() \ | ||||
|   bool waitForNetwork(unsigned long timeout = 60000L) { \ | ||||
|     for (unsigned long start = millis(); millis() - start < timeout; ) { \ | ||||
|   bool waitForNetwork(unsigned long timeout_ms = 60000L) { \ | ||||
|     for (unsigned long start = millis(); millis() - start < timeout_ms; ) { \ | ||||
|       if (isNetworkConnected()) { \ | ||||
|         return true; \ | ||||
|       } \ | ||||
| @@ -596,10 +596,10 @@ String TinyGsmDecodeHex16bit(String &instr) { | ||||
|     /* DBG("### AT:", cmd...); */ \ | ||||
|   } \ | ||||
|   \ | ||||
|   bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { \ | ||||
|   bool streamSkipUntil(const char c, const unsigned long timeout_ms = 1000L) { \ | ||||
|     unsigned long startMillis = millis(); \ | ||||
|     while (millis() - startMillis < timeout) { \ | ||||
|       while (millis() - startMillis < timeout && !stream.available()) { \ | ||||
|     while (millis() - startMillis < timeout_ms) { \ | ||||
|       while (millis() - startMillis < timeout_ms && !stream.available()) { \ | ||||
|         TINY_GSM_YIELD(); \ | ||||
|       } \ | ||||
|       if (stream.read() == c) { \ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user