|
|
@ -314,7 +314,7 @@ class TinyGsmSaraR4 |
|
|
|
sendAT(GF("+CEREG?")); |
|
|
|
if (waitResponse(GF(GSM_NL "+CEREG:")) != 1) { return REG_UNKNOWN; } |
|
|
|
streamSkipUntil(','); /* Skip format (0) */ |
|
|
|
int status = streamGetInt('\n'); |
|
|
|
int status = streamGetIntBefore('\n'); |
|
|
|
waitResponse(); |
|
|
|
|
|
|
|
// If we're connected on EPS, great! |
|
|
@ -326,7 +326,7 @@ class TinyGsmSaraR4 |
|
|
|
sendAT(GF("+CREG?")); |
|
|
|
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) { return REG_UNKNOWN; } |
|
|
|
streamSkipUntil(','); /* Skip format (0) */ |
|
|
|
status = streamGetInt('\n'); |
|
|
|
status = streamGetIntBefore('\n'); |
|
|
|
waitResponse(); |
|
|
|
return (RegStatus)status; |
|
|
|
} |
|
|
@ -520,28 +520,31 @@ class TinyGsmSaraR4 |
|
|
|
float secondWithSS = 0; |
|
|
|
|
|
|
|
// Date & Time |
|
|
|
iday = streamGetInt('/'); // Two digit day |
|
|
|
imonth = streamGetInt('/'); // Two digit month |
|
|
|
iyear = streamGetInt(','); // Four digit year |
|
|
|
ihour = streamGetInt(':'); // Two digit hour |
|
|
|
imin = streamGetInt(':'); // Two digit minute |
|
|
|
secondWithSS = streamGetFloat(','); // 6 digit second with subseconds |
|
|
|
|
|
|
|
ilat = streamGetFloat(','); // Estimated latitude, in degrees |
|
|
|
ilon = streamGetFloat(','); // Estimated longitude, in degrees |
|
|
|
ialt = streamGetFloat(','); // Estimated altitude, in meters - only forGNSS |
|
|
|
// positioning, 0 in case of CellLocate |
|
|
|
if (ialt != 0) { // values not returned for CellLocate |
|
|
|
iaccuracy = streamGetFloat(','); // Maximum possible error, in meters |
|
|
|
ispeed = streamGetFloat(','); // Speed over ground m/s3 |
|
|
|
iday = streamGetIntBefore('/'); // Two digit day |
|
|
|
imonth = streamGetIntBefore('/'); // Two digit month |
|
|
|
iyear = streamGetIntBefore(','); // Four digit year |
|
|
|
ihour = streamGetIntBefore(':'); // Two digit hour |
|
|
|
imin = streamGetIntBefore(':'); // Two digit minute |
|
|
|
secondWithSS = streamGetFloatBefore(','); // 6 digit second with subseconds |
|
|
|
|
|
|
|
ilat = streamGetFloatBefore(','); // Estimated latitude, in degrees |
|
|
|
ilon = streamGetFloatBefore(','); // Estimated longitude, in degrees |
|
|
|
ialt = streamGetFloatBefore( |
|
|
|
','); // Estimated altitude, in meters - only forGNSS |
|
|
|
// positioning, 0 in case of CellLocate |
|
|
|
if (ialt != 0) { // values not returned for CellLocate |
|
|
|
iaccuracy = |
|
|
|
streamGetFloatBefore(','); // Maximum possible error, in meters |
|
|
|
ispeed = streamGetFloatBefore(','); // Speed over ground m/s3 |
|
|
|
streamSkipUntil(','); // Course over ground in degree (0 deg - 360 deg) |
|
|
|
streamSkipUntil(','); // Vertical accuracy, in meters |
|
|
|
streamSkipUntil(','); // Sensor used for the position calculation |
|
|
|
iusat = streamGetInt(','); // Number of satellite used |
|
|
|
streamSkipUntil(','); // Antenna status |
|
|
|
streamSkipUntil('\n'); // Jamming status |
|
|
|
iusat = streamGetIntBefore(','); // Number of satellite used |
|
|
|
streamSkipUntil(','); // Antenna status |
|
|
|
streamSkipUntil('\n'); // Jamming status |
|
|
|
} else { |
|
|
|
iaccuracy = streamGetFloat('\n'); // Maximum possible error, in meters |
|
|
|
iaccuracy = |
|
|
|
streamGetFloatBefore('\n'); // Maximum possible error, in meters |
|
|
|
} |
|
|
|
|
|
|
|
// Set pointers |
|
|
@ -594,7 +597,7 @@ class TinyGsmSaraR4 |
|
|
|
sendAT(GF("+CIND?")); |
|
|
|
if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { return 0; } |
|
|
|
|
|
|
|
int8_t res = streamGetInt(','); |
|
|
|
int8_t res = streamGetIntBefore(','); |
|
|
|
int8_t percent = res * 20; // return is 0-5 |
|
|
|
// Wait for final OK |
|
|
|
waitResponse(); |
|
|
@ -623,7 +626,7 @@ class TinyGsmSaraR4 |
|
|
|
if (waitResponse(GF(GSM_NL "+UTEMP:")) != 1) { |
|
|
|
return static_cast<float>(-9999); |
|
|
|
} |
|
|
|
int16_t res = streamGetInt('\n'); |
|
|
|
int16_t res = streamGetIntBefore('\n'); |
|
|
|
float temp = -9999; |
|
|
|
if (res != -1) { temp = (static_cast<float>(res)) / 10; } |
|
|
|
return temp; |
|
|
@ -642,7 +645,7 @@ class TinyGsmSaraR4 |
|
|
|
sendAT(GF("+USOCR=6")); |
|
|
|
// reply is +USOCR: ## of socket created |
|
|
|
if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { return false; } |
|
|
|
*mux = streamGetInt('\n'); |
|
|
|
*mux = streamGetIntBefore('\n'); |
|
|
|
waitResponse(); |
|
|
|
|
|
|
|
if (ssl) { |
|
|
@ -676,8 +679,8 @@ class TinyGsmSaraR4 |
|
|
|
sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port, ",1"); |
|
|
|
if (waitResponse(timeout_ms - (millis() - startMillis), |
|
|
|
GF(GSM_NL "+UUSOCO:")) == 1) { |
|
|
|
streamGetInt(','); // skip repeated mux |
|
|
|
int8_t connection_status = streamGetInt('\n'); |
|
|
|
streamGetIntBefore(','); // skip repeated mux |
|
|
|
int8_t connection_status = streamGetIntBefore('\n'); |
|
|
|
DBG("### Waited", millis() - startMillis, "ms for socket to open"); |
|
|
|
return (0 == connection_status); |
|
|
|
} else { |
|
|
@ -702,7 +705,7 @@ class TinyGsmSaraR4 |
|
|
|
stream.flush(); |
|
|
|
if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; } |
|
|
|
streamSkipUntil(','); // Skip mux |
|
|
|
int16_t sent = streamGetInt('\n'); |
|
|
|
int16_t sent = streamGetIntBefore('\n'); |
|
|
|
waitResponse(); // sends back OK after the confirmation of number sent |
|
|
|
return sent; |
|
|
|
} |
|
|
@ -711,7 +714,7 @@ class TinyGsmSaraR4 |
|
|
|
sendAT(GF("+USORD="), mux, ',', (uint16_t)size); |
|
|
|
if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; } |
|
|
|
streamSkipUntil(','); // Skip mux |
|
|
|
int16_t len = streamGetInt(','); |
|
|
|
int16_t len = streamGetIntBefore(','); |
|
|
|
streamSkipUntil('\"'); |
|
|
|
|
|
|
|
for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); } |
|
|
@ -731,7 +734,7 @@ class TinyGsmSaraR4 |
|
|
|
// that you have already told to close |
|
|
|
if (res == 1) { |
|
|
|
streamSkipUntil(','); // Skip mux |
|
|
|
result = streamGetInt('\n'); |
|
|
|
result = streamGetIntBefore('\n'); |
|
|
|
// if (result) DBG("### DATA AVAILABLE:", result, "on", mux); |
|
|
|
waitResponse(); |
|
|
|
} |
|
|
@ -748,7 +751,7 @@ class TinyGsmSaraR4 |
|
|
|
|
|
|
|
streamSkipUntil(','); // Skip mux |
|
|
|
streamSkipUntil(','); // Skip type |
|
|
|
int8_t result = streamGetInt('\n'); |
|
|
|
int8_t result = streamGetIntBefore('\n'); |
|
|
|
// 0: the socket is in INACTIVE status (it corresponds to CLOSED status |
|
|
|
// defined in RFC793 "TCP Protocol Specification" [112]) |
|
|
|
// 1: the socket is in LISTEN status |
|
|
@ -810,8 +813,8 @@ class TinyGsmSaraR4 |
|
|
|
index = 5; |
|
|
|
goto finish; |
|
|
|
} else if (data.endsWith(GF("+UUSORD:"))) { |
|
|
|
int8_t mux = streamGetInt(','); |
|
|
|
int16_t len = streamGetInt('\n'); |
|
|
|
int8_t mux = streamGetIntBefore(','); |
|
|
|
int16_t len = streamGetIntBefore('\n'); |
|
|
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { |
|
|
|
sockets[mux]->got_data = true; |
|
|
|
sockets[mux]->sock_available = len; |
|
|
@ -819,15 +822,15 @@ class TinyGsmSaraR4 |
|
|
|
data = ""; |
|
|
|
DBG("### URC Data Received:", len, "on", mux); |
|
|
|
} else if (data.endsWith(GF("+UUSOCL:"))) { |
|
|
|
int8_t mux = streamGetInt('\n'); |
|
|
|
int8_t mux = streamGetIntBefore('\n'); |
|
|
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { |
|
|
|
sockets[mux]->sock_connected = false; |
|
|
|
} |
|
|
|
data = ""; |
|
|
|
DBG("### URC Sock Closed: ", mux); |
|
|
|
} else if (data.endsWith(GF("+UUSOCO:"))) { |
|
|
|
int8_t mux = streamGetInt('\n'); |
|
|
|
int8_t socket_error = streamGetInt('\n'); |
|
|
|
int8_t mux = streamGetIntBefore('\n'); |
|
|
|
int8_t socket_error = streamGetIntBefore('\n'); |
|
|
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux] && |
|
|
|
socket_error == 0) { |
|
|
|
sockets[mux]->sock_connected = true; |
|
|
|