Browse Source

Replace *most* toInt and toFloat's

Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
v_master
Sara Damiano 5 years ago
parent
commit
06c31aa856
16 changed files with 240 additions and 219 deletions
  1. +10
    -10
      src/TinyGsmClientA6.h
  2. +15
    -15
      src/TinyGsmClientBG96.h
  3. +3
    -3
      src/TinyGsmClientESP8266.h
  4. +7
    -7
      src/TinyGsmClientM590.h
  5. +12
    -12
      src/TinyGsmClientM95.h
  6. +13
    -15
      src/TinyGsmClientMC60.h
  7. +15
    -15
      src/TinyGsmClientSIM5360.h
  8. +31
    -29
      src/TinyGsmClientSIM7000.h
  9. +34
    -31
      src/TinyGsmClientSIM7600.h
  10. +9
    -9
      src/TinyGsmClientSIM800.h
  11. +22
    -20
      src/TinyGsmClientSIM808.h
  12. +16
    -16
      src/TinyGsmClientSaraR4.h
  13. +9
    -9
      src/TinyGsmClientSequansMonarch.h
  14. +10
    -12
      src/TinyGsmClientUBLOX.h
  15. +1
    -1
      src/TinyGsmClientXBee.h
  16. +33
    -15
      src/TinyGsmCommon.h

+ 10
- 10
src/TinyGsmClientA6.h View File

@ -362,10 +362,10 @@ class TinyGsmA6
sendAT(GF("+CUSD=1,\""), code, GF("\",15")); sendAT(GF("+CUSD=1,\""), code, GF("\",15"));
if (waitResponse(10000L) != 1) { return ""; } if (waitResponse(10000L) != 1) { return ""; }
if (waitResponse(GF(GSM_NL "+CUSD:")) != 1) { return ""; } if (waitResponse(GF(GSM_NL "+CUSD:")) != 1) { return ""; }
stream.readStringUntil('"');
streamSkipUntil('"');
String hex = stream.readStringUntil('"'); String hex = stream.readStringUntil('"');
stream.readStringUntil(',');
int dcs = stream.readStringUntil('\n').toInt();
streamSkipUntil(',');
int dcs = streamGetInt('\n');
if (dcs == 15) { if (dcs == 15) {
return TinyGsmDecodeHex7bit(hex); return TinyGsmDecodeHex7bit(hex);
@ -407,7 +407,7 @@ class TinyGsmA6
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; } if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; }
streamSkipUntil(','); // Skip battery charge status streamSkipUntil(','); // Skip battery charge status
// Read battery charge level // Read battery charge level
int res = stream.readStringUntil('\n').toInt();
int res = streamGetInt('\n');
// Wait for final OK // Wait for final OK
waitResponse(); waitResponse();
return res; return res;
@ -418,8 +418,8 @@ class TinyGsmA6
uint16_t& milliVolts) { uint16_t& milliVolts) {
sendAT(GF("+CBC?")); sendAT(GF("+CBC?"));
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; } if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; }
chargeState = stream.readStringUntil(',').toInt();
percent = stream.readStringUntil('\n').toInt();
chargeState = streamGetInt(',');
percent = streamGetInt('\n');
milliVolts = 0; milliVolts = 0;
// Wait for final OK // Wait for final OK
waitResponse(); waitResponse();
@ -439,7 +439,7 @@ class TinyGsmA6
sendAT(GF("+CIPSTART="), GF("\"TCP"), GF("\",\""), host, GF("\","), port); sendAT(GF("+CIPSTART="), GF("\"TCP"), GF("\",\""), host, GF("\","), port);
if (waitResponse(timeout_ms, GF(GSM_NL "+CIPNUM:")) != 1) { return false; } if (waitResponse(timeout_ms, GF(GSM_NL "+CIPNUM:")) != 1) { return false; }
int newMux = stream.readStringUntil('\n').toInt();
int newMux = streamGetInt('\n');
int rsp = waitResponse((timeout_ms - (millis() - startMillis)), int rsp = waitResponse((timeout_ms - (millis() - startMillis)),
GF("CONNECT OK" GSM_NL), GF("CONNECT FAIL" GSM_NL), GF("CONNECT OK" GSM_NL), GF("CONNECT FAIL" GSM_NL),
@ -519,8 +519,8 @@ class TinyGsmA6
index = 5; index = 5;
goto finish; goto finish;
} else if (data.endsWith(GF("+CIPRCV:"))) { } else if (data.endsWith(GF("+CIPRCV:"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil(',').toInt();
int mux = streamGetInt(',');
int len = streamGetInt(',');
int len_orig = len; int len_orig = len;
if (len > sockets[mux]->rx.free()) { if (len > sockets[mux]->rx.free()) {
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free()); DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
@ -535,7 +535,7 @@ class TinyGsmA6
} }
data = ""; data = "";
} else if (data.endsWith(GF("+TCPCLOSED:"))) { } else if (data.endsWith(GF("+TCPCLOSED:"))) {
int mux = stream.readStringUntil('\n').toInt();
int mux = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) {
sockets[mux]->sock_connected = false; sockets[mux]->sock_connected = false;
} }


+ 15
- 15
src/TinyGsmClientBG96.h View File

@ -327,9 +327,9 @@ class TinyGsmBG96
if (waitResponse(timeout_ms, GF(GSM_NL "+QIOPEN:")) != 1) { return false; } if (waitResponse(timeout_ms, GF(GSM_NL "+QIOPEN:")) != 1) { return false; }
if (stream.readStringUntil(',').toInt() != mux) { return false; }
if (streamGetInt(',') != mux) { return false; }
// Read status // Read status
rsp = stream.readStringUntil('\n').toInt();
rsp = streamGetInt('\n');
return (0 == rsp); return (0 == rsp);
} }
@ -347,7 +347,7 @@ class TinyGsmBG96
size_t modemRead(size_t size, uint8_t mux) { size_t modemRead(size_t size, uint8_t mux) {
sendAT(GF("+QIRD="), mux, ',', (uint16_t)size); sendAT(GF("+QIRD="), mux, ',', (uint16_t)size);
if (waitResponse(GF("+QIRD:")) != 1) { return 0; } if (waitResponse(GF("+QIRD:")) != 1) { return 0; }
int len = stream.readStringUntil('\n').toInt();
int len = streamGetInt('\n');
for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); } for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); }
waitResponse(); waitResponse();
@ -362,7 +362,7 @@ class TinyGsmBG96
if (waitResponse(GF("+QIRD:")) == 1) { if (waitResponse(GF("+QIRD:")) == 1) {
streamSkipUntil(','); // Skip total received streamSkipUntil(','); // Skip total received
streamSkipUntil(','); // Skip have read streamSkipUntil(','); // Skip have read
result = stream.readStringUntil('\n').toInt();
result = streamGetInt('\n');
if (result) { DBG("### DATA AVAILABLE:", result, "on", mux); } if (result) { DBG("### DATA AVAILABLE:", result, "on", mux); }
waitResponse(); waitResponse();
} }
@ -376,12 +376,12 @@ class TinyGsmBG96
if (waitResponse(GF("+QISTATE:")) != 1) { return false; } if (waitResponse(GF("+QISTATE:")) != 1) { return false; }
streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip socket type
streamSkipUntil(','); // Skip remote ip
streamSkipUntil(','); // Skip remote port
streamSkipUntil(','); // Skip local port
int res = stream.readStringUntil(',').toInt(); // socket state
streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip socket type
streamSkipUntil(','); // Skip remote ip
streamSkipUntil(','); // Skip remote port
streamSkipUntil(','); // Skip local port
int res = streamGetInt(','); // socket state
waitResponse(); waitResponse();
@ -434,23 +434,23 @@ class TinyGsmBG96
index = 5; index = 5;
goto finish; goto finish;
} else if (data.endsWith(GF(GSM_NL "+QIURC:"))) { } else if (data.endsWith(GF(GSM_NL "+QIURC:"))) {
stream.readStringUntil('\"');
streamSkipUntil('\"');
String urc = stream.readStringUntil('\"'); String urc = stream.readStringUntil('\"');
stream.readStringUntil(',');
streamSkipUntil(',');
if (urc == "recv") { if (urc == "recv") {
int mux = stream.readStringUntil('\n').toInt();
int mux = streamGetInt('\n');
DBG("### URC RECV:", mux); DBG("### URC RECV:", mux);
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->got_data = true;
} }
} else if (urc == "closed") { } else if (urc == "closed") {
int mux = stream.readStringUntil('\n').toInt();
int mux = streamGetInt('\n');
DBG("### URC CLOSE:", mux); DBG("### URC CLOSE:", mux);
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->sock_connected = false; sockets[mux]->sock_connected = false;
} }
} else { } else {
stream.readStringUntil('\n');
streamSkipUntil('\n');
} }
data = ""; data = "";
} }


+ 3
- 3
src/TinyGsmClientESP8266.h View File

@ -396,7 +396,7 @@ class TinyGsmESP8266
uint8_t has_status = waitResponse(GF("+CIPSTATUS:"), GFP(GSM_OK), uint8_t has_status = waitResponse(GF("+CIPSTATUS:"), GFP(GSM_OK),
GFP(GSM_ERROR)); GFP(GSM_ERROR));
if (has_status == 1) { if (has_status == 1) {
int returned_mux = stream.readStringUntil(',').toInt();
int returned_mux = streamGetInt(',');
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip type streamSkipUntil(','); // Skip type
streamSkipUntil(','); // Skip remote IP streamSkipUntil(','); // Skip remote IP
@ -454,8 +454,8 @@ class TinyGsmESP8266
index = 5; index = 5;
goto finish; goto finish;
} else if (data.endsWith(GF("+IPD,"))) { } else if (data.endsWith(GF("+IPD,"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil(':').toInt();
int mux = streamGetInt(',');
int len = streamGetInt(':');
int len_orig = len; int len_orig = len;
if (len > sockets[mux]->rx.free()) { if (len > sockets[mux]->rx.free()) {
DBG("### Buffer overflow: ", len, "received vs", DBG("### Buffer overflow: ", len, "received vs",


+ 7
- 7
src/TinyGsmClientM590.h View File

@ -261,7 +261,7 @@ class TinyGsmM590
bool isGprsConnectedImpl() { bool isGprsConnectedImpl() {
sendAT(GF("+XIIC?")); sendAT(GF("+XIIC?"));
if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { return false; } if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { return false; }
int res = stream.readStringUntil(',').toInt();
int res = streamGetInt(',');
waitResponse(); waitResponse();
return res == 1; return res == 1;
} }
@ -273,7 +273,7 @@ class TinyGsmM590
String getLocalIPImpl() { String getLocalIPImpl() {
sendAT(GF("+XIIC?")); sendAT(GF("+XIIC?"));
if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { return ""; } if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { return ""; }
stream.readStringUntil(',');
streamSkipUntil(',');
String res = stream.readStringUntil('\n'); String res = stream.readStringUntil('\n');
waitResponse(); waitResponse();
res.trim(); res.trim();
@ -356,7 +356,7 @@ class TinyGsmM590
stream.write(static_cast<char>(0x0D)); stream.write(static_cast<char>(0x0D));
stream.flush(); stream.flush();
if (waitResponse(30000L, GF(GSM_NL "+TCPSEND:")) != 1) { return 0; } if (waitResponse(30000L, GF(GSM_NL "+TCPSEND:")) != 1) { return 0; }
stream.readStringUntil('\n');
streamSkipUntil('\n');
return len; return len;
} }
@ -429,8 +429,8 @@ class TinyGsmM590
index = 5; index = 5;
goto finish; goto finish;
} else if (data.endsWith(GF("+TCPRECV:"))) { } else if (data.endsWith(GF("+TCPRECV:"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil(',').toInt();
int mux = streamGetInt(',');
int len = streamGetInt(',');
int len_orig = len; int len_orig = len;
if (len > sockets[mux]->rx.free()) { if (len > sockets[mux]->rx.free()) {
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free()); DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
@ -445,8 +445,8 @@ class TinyGsmM590
} }
data = ""; data = "";
} else if (data.endsWith(GF("+TCPCLOSE:"))) { } else if (data.endsWith(GF("+TCPCLOSE:"))) {
int mux = stream.readStringUntil(',').toInt();
stream.readStringUntil('\n');
int mux = streamGetInt(',');
streamSkipUntil('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) {
sockets[mux]->sock_connected = false; sockets[mux]->sock_connected = false;
} }


+ 12
- 12
src/TinyGsmClientM95.h View File

@ -339,7 +339,7 @@ class TinyGsmM95
protected: protected:
String getLocalIPImpl() { String getLocalIPImpl() {
sendAT(GF("+QILOCIP")); sendAT(GF("+QILOCIP"));
stream.readStringUntil('\n');
streamSkipUntil('\n');
String res = stream.readStringUntil('\n'); String res = stream.readStringUntil('\n');
res.trim(); res.trim();
return res; return res;
@ -396,9 +396,9 @@ class TinyGsmM95
} }
streamSkipUntil(','); // Skip mode streamSkipUntil(','); // Skip mode
// Read charge of thermistor // Read charge of thermistor
// milliVolts = stream.readStringUntil(',').toInt();
// milliVolts = streamGetInt(',');
streamSkipUntil(','); // Skip thermistor charge streamSkipUntil(','); // Skip thermistor charge
float temp = stream.readStringUntil('\n').toFloat();
float temp = streamGetFloat('\n');
// Wait for final OK // Wait for final OK
waitResponse(); waitResponse();
return temp; return temp;
@ -437,7 +437,7 @@ class TinyGsmM95
// streamSkipUntil(','); // Skip total length sent on connection // streamSkipUntil(','); // Skip total length sent on connection
// streamSkipUntil(','); // Skip length already acknowledged by remote // streamSkipUntil(','); // Skip length already acknowledged by remote
// // Make sure the total length un-acknowledged is 0 // // Make sure the total length un-acknowledged is 0
// if ( stream.readStringUntil('\n').toInt() == 0 ) {
// if ( streamGetInt('\n') == 0 ) {
// allAcknowledged = true; // allAcknowledged = true;
// } // }
// } // }
@ -463,7 +463,7 @@ class TinyGsmM95
streamSkipUntil(','); // skip port streamSkipUntil(','); // skip port
streamSkipUntil(','); // skip connection type (TCP/UDP) streamSkipUntil(','); // skip connection type (TCP/UDP)
// read the real length of the retrieved data // read the real length of the retrieved data
uint16_t len = stream.readStringUntil('\n').toInt();
uint16_t len = streamGetInt('\n');
// We have no way of knowing in advance how much data will be in the // We have no way of knowing in advance how much data will be in the
// buffer so when data is received we always assume the buffer is // buffer so when data is received we always assume the buffer is
// completely full. Chances are, this is not true and there's really not // completely full. Chances are, this is not true and there's really not
@ -495,12 +495,12 @@ class TinyGsmM95
if (waitResponse(GF("+QISTATE:")) != 1) { return false; } if (waitResponse(GF("+QISTATE:")) != 1) { return false; }
streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip socket type
streamSkipUntil(','); // Skip remote ip
streamSkipUntil(','); // Skip remote port
streamSkipUntil(','); // Skip local port
int res = stream.readStringUntil(',').toInt(); // socket state
streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip socket type
streamSkipUntil(','); // Skip remote ip
streamSkipUntil(','); // Skip remote port
streamSkipUntil(','); // Skip local port
int res = streamGetInt(','); // socket state
waitResponse(); waitResponse();
@ -555,7 +555,7 @@ class TinyGsmM95
} else if (data.endsWith(GF(GSM_NL "+QIRDI:"))) { } else if (data.endsWith(GF(GSM_NL "+QIRDI:"))) {
streamSkipUntil(','); // Skip the context streamSkipUntil(','); // Skip the context
streamSkipUntil(','); // Skip the role streamSkipUntil(','); // Skip the role
int mux = stream.readStringUntil('\n').toInt();
int mux = streamGetInt('\n');
DBG("### Got Data:", mux); DBG("### Got Data:", mux);
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
// We have no way of knowing how much data actually came in, so // We have no way of knowing how much data actually came in, so


+ 13
- 15
src/TinyGsmClientMC60.h View File

@ -331,7 +331,7 @@ class TinyGsmMC60
protected: protected:
String getLocalIPImpl() { String getLocalIPImpl() {
sendAT(GF("+QILOCIP")); sendAT(GF("+QILOCIP"));
stream.readStringUntil('\n');
streamSkipUntil('\n');
String res = stream.readStringUntil('\n'); String res = stream.readStringUntil('\n');
res.trim(); res.trim();
return res; return res;
@ -415,15 +415,13 @@ class TinyGsmMC60
} else { } else {
streamSkipUntil(','); /** Skip total */ streamSkipUntil(','); /** Skip total */
streamSkipUntil(','); /** Skip acknowledged data size */ streamSkipUntil(','); /** Skip acknowledged data size */
if (stream.readStringUntil('\n').toInt() == 0) {
allAcknowledged = true;
}
if (streamGetInt('\n') == 0) { allAcknowledged = true; }
} }
} }
waitResponse(5000L); waitResponse(5000L);
// streamSkipUntil(','); // Skip mux // streamSkipUntil(','); // Skip mux
// return stream.readStringUntil('\n').toInt();
// return streamGetInt('\n');
return len; // TODO(?): verify len/ack return len; // TODO(?): verify len/ack
} }
@ -444,7 +442,7 @@ class TinyGsmMC60
streamSkipUntil(','); // skip port streamSkipUntil(','); // skip port
streamSkipUntil(','); // skip connection type (TCP/UDP) streamSkipUntil(','); // skip connection type (TCP/UDP)
// read the real length of the retrieved data // read the real length of the retrieved data
uint16_t len = stream.readStringUntil('\n').toInt();
uint16_t len = streamGetInt('\n');
// It's possible that the real length available is less than expected // It's possible that the real length available is less than expected
// This is quite likely if the buffer is broken into packets - which may // This is quite likely if the buffer is broken into packets - which may
// be different sizes. // be different sizes.
@ -475,12 +473,12 @@ class TinyGsmMC60
if (waitResponse(GF("+QISTATE:")) != 1) { return false; } if (waitResponse(GF("+QISTATE:")) != 1) { return false; }
streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip socket type
streamSkipUntil(','); // Skip remote ip
streamSkipUntil(','); // Skip remote port
streamSkipUntil(','); // Skip local port
int res = stream.readStringUntil(',').toInt(); // socket state
streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip socket type
streamSkipUntil(','); // Skip remote ip
streamSkipUntil(','); // Skip remote port
streamSkipUntil(','); // Skip local port
int res = streamGetInt(','); // socket state
waitResponse(); waitResponse();
@ -543,11 +541,11 @@ class TinyGsmMC60
streamSkipUntil(','); // Skip the context streamSkipUntil(','); // Skip the context
streamSkipUntil(','); // Skip the role streamSkipUntil(','); // Skip the role
// read the connection id // read the connection id
int mux = stream.readStringUntil(',').toInt();
int mux = streamGetInt(',');
// read the number of packets in the buffer // read the number of packets in the buffer
int num_packets = stream.readStringUntil(',').toInt();
int num_packets = streamGetInt(',');
// read the length of the current packet // read the length of the current packet
int len_packet = stream.readStringUntil('\n').toInt();
int len_packet = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->sock_available = len_packet * num_packets; sockets[mux]->sock_available = len_packet * num_packets;
} }


+ 15
- 15
src/TinyGsmClientSIM5360.h View File

@ -445,7 +445,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE,
streamSkipUntil(','); // Skip battery charge status streamSkipUntil(','); // Skip battery charge status
streamSkipUntil(','); // Skip battery charge level streamSkipUntil(','); // Skip battery charge level
// get voltage in VOLTS // get voltage in VOLTS
float voltage = stream.readStringUntil('\n').toFloat();
float voltage = streamGetFloat('\n');
// Wait for final OK // Wait for final OK
waitResponse(); waitResponse();
// Return millivolts // Return millivolts
@ -458,10 +458,10 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE,
uint16_t& milliVolts) { uint16_t& milliVolts) {
sendAT(GF("+CBC")); sendAT(GF("+CBC"));
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; } if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; }
chargeState = stream.readStringUntil(',').toInt();
percent = stream.readStringUntil(',').toInt();
chargeState = streamGetInt(',');
percent = streamGetInt(',');
// get voltage in VOLTS // get voltage in VOLTS
float voltage = stream.readStringUntil('\n').toFloat();
float voltage = streamGetFloat('\n');
milliVolts = voltage * 1000; milliVolts = voltage * 1000;
// Wait for final OK // Wait for final OK
waitResponse(); waitResponse();
@ -476,7 +476,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE,
// Get Temparature Value // Get Temparature Value
sendAT(GF("+CMTE?")); sendAT(GF("+CMTE?"));
if (waitResponse(GF(GSM_NL "+CMTE:")) != 1) { return false; } if (waitResponse(GF(GSM_NL "+CMTE:")) != 1) { return false; }
float res = stream.readStringUntil('\n').toFloat();
float res = streamGetFloat('\n');
// Wait for final OK // Wait for final OK
waitResponse(); waitResponse();
return res; return res;
@ -511,7 +511,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE,
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip requested bytes to send streamSkipUntil(','); // Skip requested bytes to send
// TODO(?): make sure requested and confirmed bytes match // TODO(?): make sure requested and confirmed bytes match
return stream.readStringUntil('\n').toInt();
return streamGetInt('\n');
} }
size_t modemRead(size_t size, uint8_t mux) { size_t modemRead(size_t size, uint8_t mux) {
@ -524,9 +524,9 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE,
#endif #endif
streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX
streamSkipUntil(','); // Skip mux/cid (connecion id) streamSkipUntil(','); // Skip mux/cid (connecion id)
int len_requested = stream.readStringUntil(',').toInt();
int len_requested = streamGetInt(',');
// ^^ Requested number of data bytes (1-1460 bytes)to be read // ^^ Requested number of data bytes (1-1460 bytes)to be read
int len_confirmed = stream.readStringUntil('\n').toInt();
int len_confirmed = streamGetInt('\n');
// ^^ The data length which not read in the buffer // ^^ The data length which not read in the buffer
for (int i = 0; i < len_requested; i++) { for (int i = 0; i < len_requested; i++) {
uint32_t startMillis = millis(); uint32_t startMillis = millis();
@ -563,7 +563,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE,
if (waitResponse(GF("+CIPRXGET:")) == 1) { if (waitResponse(GF("+CIPRXGET:")) == 1) {
streamSkipUntil(','); // Skip mode 4 streamSkipUntil(','); // Skip mode 4
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
result = stream.readStringUntil('\n').toInt();
result = streamGetInt('\n');
waitResponse(); waitResponse();
} }
DBG("### Available:", result, "on", mux); DBG("### Available:", result, "on", mux);
@ -628,9 +628,9 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE,
index = 5; index = 5;
goto finish; goto finish;
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
String mode = stream.readStringUntil(',');
if (mode.toInt() == 1) {
int mux = stream.readStringUntil('\n').toInt();
int mode = streamGetInt(',');
if (mode == 1) {
int mux = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->got_data = true;
} }
@ -640,8 +640,8 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE,
data += mode; data += mode;
} }
} else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil('\n').toInt();
int mux = streamGetInt(',');
int len = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->got_data = true;
sockets[mux]->sock_available = len; sockets[mux]->sock_available = len;
@ -649,7 +649,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE,
data = ""; data = "";
DBG("### Got Data:", len, "on", mux); DBG("### Got Data:", len, "on", mux);
} else if (data.endsWith(GF("+IPCLOSE:"))) { } else if (data.endsWith(GF("+IPCLOSE:"))) {
int mux = stream.readStringUntil(',').toInt();
int mux = streamGetInt(',');
streamSkipUntil('\n'); // Skip the reason code streamSkipUntil('\n'); // Skip the reason code
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->sock_connected = false; sockets[mux]->sock_connected = false;


+ 31
- 29
src/TinyGsmClientSIM7000.h View File

@ -436,25 +436,27 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE,
sendAT(GF("+CGNSINF")); sendAT(GF("+CGNSINF"));
if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) { return false; } if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) { return false; }
stream.readStringUntil(','); // mode
if (stream.readStringUntil(',').toInt() == 1) fix = true;
stream.readStringUntil(','); // utctime
*lat = stream.readStringUntil(',').toFloat(); // lat
*lon = stream.readStringUntil(',').toFloat(); // lon
if (alt != NULL) *alt = stream.readStringUntil(',').toFloat(); // lon
if (speed != NULL) *speed = stream.readStringUntil(',').toFloat(); // speed
stream.readStringUntil(',');
stream.readStringUntil(',');
stream.readStringUntil(',');
stream.readStringUntil(',');
stream.readStringUntil(',');
stream.readStringUntil(',');
stream.readStringUntil(',');
if (vsat != NULL)
*vsat = stream.readStringUntil(',').toInt(); // viewed satelites
if (usat != NULL)
*usat = stream.readStringUntil(',').toInt(); // used satelites
stream.readStringUntil('\n');
streamSkipUntil(','); // GNSS run status
if (streamGetInt(',') == 1) fix = true; // fix status
streamSkipUntil(','); // UTC date & Time
*lat = streamGetFloat(','); // Latitude
*lon = streamGetFloat(','); // Longitude
if (alt != NULL) *alt = streamGetFloat(','); // MSL Altitude
if (speed != NULL) *speed = streamGetFloat(','); // Speed Over Ground
streamSkipUntil(','); // Course Over Ground
streamSkipUntil(','); // Fix Mode
streamSkipUntil(','); // Reserved1
streamSkipUntil(','); // Horizontal Dilution Of Precision
streamSkipUntil(','); // Position Dilution Of Precision
streamSkipUntil(','); // Vertical Dilution Of Precision
streamSkipUntil(','); // Reserved2
if (vsat != NULL) *vsat = streamGetInt(','); // GNSS Satellites in View
if (usat != NULL) *usat = streamGetInt(','); // GNSS Satellites Used
streamSkipUntil(','); // GLONASS Satellites Used
streamSkipUntil(','); // Reserved3
streamSkipUntil(','); // C/N0 max
streamSkipUntil(','); // HPA
streamSkipUntil('\n'); // VPA
waitResponse(); waitResponse();
@ -499,7 +501,7 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE,
break; break;
} }
} }
stream.readStringUntil('\n');
streamSkipUntil('\n');
waitResponse(); waitResponse();
if (fix) { if (fix) {
@ -541,7 +543,7 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE,
stream.flush(); stream.flush();
if (waitResponse(GF(GSM_NL "DATA ACCEPT:")) != 1) { return 0; } if (waitResponse(GF(GSM_NL "DATA ACCEPT:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
return stream.readStringUntil('\n').toInt();
return streamGetInt('\n');
} }
size_t modemRead(size_t size, uint8_t mux) { size_t modemRead(size_t size, uint8_t mux) {
@ -554,9 +556,9 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE,
#endif #endif
streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
int len_requested = stream.readStringUntil(',').toInt();
int len_requested = streamGetInt(',');
// ^^ Requested number of data bytes (1-1460 bytes)to be read // ^^ Requested number of data bytes (1-1460 bytes)to be read
int len_confirmed = stream.readStringUntil('\n').toInt();
int len_confirmed = streamGetInt('\n');
// ^^ Confirmed number of data bytes to be read, which may be less than // ^^ Confirmed number of data bytes to be read, which may be less than
// requested. 0 indicates that no data can be read. This is actually be the // requested. 0 indicates that no data can be read. This is actually be the
// number of bytes that will be remaining after the read // number of bytes that will be remaining after the read
@ -595,7 +597,7 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE,
if (waitResponse(GF("+CIPRXGET:")) == 1) { if (waitResponse(GF("+CIPRXGET:")) == 1) {
streamSkipUntil(','); // Skip mode 4 streamSkipUntil(','); // Skip mode 4
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
result = stream.readStringUntil('\n').toInt();
result = streamGetInt('\n');
waitResponse(); waitResponse();
} }
DBG("### Available:", result, "on", mux); DBG("### Available:", result, "on", mux);
@ -656,9 +658,9 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE,
index = 5; index = 5;
goto finish; goto finish;
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
String mode = stream.readStringUntil(',');
if (mode.toInt() == 1) {
int mux = stream.readStringUntil('\n').toInt();
int mode = streamGetInt(',');
if (mode == 1) {
int mux = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->got_data = true;
} }
@ -668,8 +670,8 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE,
data += mode; data += mode;
} }
} else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil('\n').toInt();
int mux = streamGetInt(',');
int len = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->got_data = true;
sockets[mux]->sock_available = len; sockets[mux]->sock_available = len;


+ 34
- 31
src/TinyGsmClientSIM7600.h View File

@ -410,25 +410,28 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE,
sendAT(GF("+CGNSSINFO")); sendAT(GF("+CGNSSINFO"));
if (waitResponse(GF(GSM_NL "+CGNSSINFO:")) != 1) { return false; } if (waitResponse(GF(GSM_NL "+CGNSSINFO:")) != 1) { return false; }
// stream.readStringUntil(','); // mode
if (stream.readStringUntil(',').toInt() == 1) fix = true;
stream.readStringUntil(','); // gps
stream.readStringUntil(','); // glonass
stream.readStringUntil(','); // beidu
*lat = stream.readStringUntil(',').toFloat(); // lat
stream.readStringUntil(','); // N/S
*lon = stream.readStringUntil(',').toFloat(); // lon
stream.readStringUntil(','); // E/W
stream.readStringUntil(','); // date
stream.readStringUntil(','); // UTC time
if (alt != NULL) *alt = stream.readStringUntil(',').toFloat(); // alt
if (speed != NULL) *speed = stream.readStringUntil(',').toFloat(); // speed
stream.readStringUntil(','); // course
stream.readStringUntil(','); // time
stream.readStringUntil(','); // PDOP
stream.readStringUntil(','); // HDOP
stream.readStringUntil(','); // VDOP
stream.readStringUntil('\n');
// streamSkipUntil(','); // mode
if (streamGetInt(',') == 1)
fix = true; // TODO(?) Shouldn't this be 2=2D Fix or 3=3DFix?
streamSkipUntil(','); // GPS satellite valid numbers
streamSkipUntil(','); // GLONASS satellite valid numbers
streamSkipUntil(','); // BEIDOU satellite valid numbers
*lat = streamGetFloat(','); // Latitude
streamSkipUntil(','); // N/S Indicator, N=north or S=south
*lon = streamGetFloat(','); // Longitude
streamSkipUntil(','); // E/W Indicator, E=east or W=west
streamSkipUntil(','); // Date. Output format is ddmmyy
streamSkipUntil(','); // UTC Time. Output format is hhmmss.s
if (alt != NULL)
*alt = streamGetFloat(','); // MSL Altitude. Unit is meters
if (speed != NULL)
*speed = streamGetFloat(','); // Speed Over Ground. Unit is knots.
streamSkipUntil(','); // Course. Degrees.
streamSkipUntil(','); // After set, will report GPS every x seconds
streamSkipUntil(','); // Position Dilution Of Precision
streamSkipUntil(','); // Horizontal Dilution Of Precision
streamSkipUntil(','); // Vertical Dilution Of Precision
streamSkipUntil('\n'); // TODO(?) is one more field reported??
waitResponse(); waitResponse();
@ -451,7 +454,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE,
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return 0; } if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return 0; }
// get voltage in VOLTS // get voltage in VOLTS
float voltage = stream.readStringUntil('\n').toFloat();
float voltage = streamGetFloat('\n');
// Wait for final OK // Wait for final OK
waitResponse(); waitResponse();
// Return millivolts // Return millivolts
@ -476,7 +479,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE,
sendAT(GF("+CPMUTEMP")); sendAT(GF("+CPMUTEMP"));
if (waitResponse(GF(GSM_NL "+CPMUTEMP:")) != 1) { return 0; } if (waitResponse(GF(GSM_NL "+CPMUTEMP:")) != 1) { return 0; }
// return temperature in C // return temperature in C
uint16_t res = stream.readStringUntil('\n').toInt();
uint16_t res = streamGetInt('\n');
// Wait for final OK // Wait for final OK
waitResponse(); waitResponse();
return res; return res;
@ -511,7 +514,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE,
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip requested bytes to send streamSkipUntil(','); // Skip requested bytes to send
// TODO(?): make sure requested and confirmed bytes match // TODO(?): make sure requested and confirmed bytes match
return stream.readStringUntil('\n').toInt();
return streamGetInt('\n');
} }
size_t modemRead(size_t size, uint8_t mux) { size_t modemRead(size_t size, uint8_t mux) {
@ -524,9 +527,9 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE,
#endif #endif
streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX
streamSkipUntil(','); // Skip mux/cid (connecion id) streamSkipUntil(','); // Skip mux/cid (connecion id)
int len_requested = stream.readStringUntil(',').toInt();
int len_requested = streamGetInt(',');
// ^^ Requested number of data bytes (1-1460 bytes)to be read // ^^ Requested number of data bytes (1-1460 bytes)to be read
int len_confirmed = stream.readStringUntil('\n').toInt();
int len_confirmed = streamGetInt('\n');
// ^^ The data length which not read in the buffer // ^^ The data length which not read in the buffer
for (int i = 0; i < len_requested; i++) { for (int i = 0; i < len_requested; i++) {
uint32_t startMillis = millis(); uint32_t startMillis = millis();
@ -563,7 +566,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE,
if (waitResponse(GF("+CIPRXGET:")) == 1) { if (waitResponse(GF("+CIPRXGET:")) == 1) {
streamSkipUntil(','); // Skip mode 4 streamSkipUntil(','); // Skip mode 4
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
result = stream.readStringUntil('\n').toInt();
result = streamGetInt('\n');
waitResponse(); waitResponse();
} }
DBG("### Available:", result, "on", mux); DBG("### Available:", result, "on", mux);
@ -630,9 +633,9 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE,
index = 5; index = 5;
goto finish; goto finish;
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
String mode = stream.readStringUntil(',');
if (mode.toInt() == 1) {
int mux = stream.readStringUntil('\n').toInt();
int mode = streamGetInt(',');
if (mode == 1) {
int mux = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->got_data = true;
} }
@ -642,8 +645,8 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE,
data += mode; data += mode;
} }
} else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil('\n').toInt();
int mux = streamGetInt(',');
int len = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->got_data = true;
sockets[mux]->sock_available = len; sockets[mux]->sock_available = len;
@ -651,7 +654,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE,
data = ""; data = "";
DBG("### Got Data:", len, "on", mux); DBG("### Got Data:", len, "on", mux);
} else if (data.endsWith(GF("+IPCLOSE:"))) { } else if (data.endsWith(GF("+IPCLOSE:"))) {
int mux = stream.readStringUntil(',').toInt();
int mux = streamGetInt(',');
streamSkipUntil('\n'); // Skip the reason code streamSkipUntil('\n'); // Skip the reason code
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->sock_connected = false; sockets[mux]->sock_connected = false;


+ 9
- 9
src/TinyGsmClientSIM800.h View File

@ -490,7 +490,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
stream.flush(); stream.flush();
if (waitResponse(GF(GSM_NL "DATA ACCEPT:")) != 1) { return 0; } if (waitResponse(GF(GSM_NL "DATA ACCEPT:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
return stream.readStringUntil('\n').toInt();
return streamGetInt('\n');
} }
size_t modemRead(size_t size, uint8_t mux) { size_t modemRead(size_t size, uint8_t mux) {
@ -503,9 +503,9 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
#endif #endif
streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
int len_requested = stream.readStringUntil(',').toInt();
int len_requested = streamGetInt(',');
// ^^ Requested number of data bytes (1-1460 bytes)to be read // ^^ Requested number of data bytes (1-1460 bytes)to be read
int len_confirmed = stream.readStringUntil('\n').toInt();
int len_confirmed = streamGetInt('\n');
// ^^ Confirmed number of data bytes to be read, which may be less than // ^^ Confirmed number of data bytes to be read, which may be less than
// requested. 0 indicates that no data can be read. This is actually be the // requested. 0 indicates that no data can be read. This is actually be the
// number of bytes that will be remaining after the read // number of bytes that will be remaining after the read
@ -544,7 +544,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
if (waitResponse(GF("+CIPRXGET:")) == 1) { if (waitResponse(GF("+CIPRXGET:")) == 1) {
streamSkipUntil(','); // Skip mode 4 streamSkipUntil(','); // Skip mode 4
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
result = stream.readStringUntil('\n').toInt();
result = streamGetInt('\n');
waitResponse(); waitResponse();
} }
DBG("### Available:", result, "on", mux); DBG("### Available:", result, "on", mux);
@ -607,9 +607,9 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
index = 5; index = 5;
goto finish; goto finish;
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
String mode = stream.readStringUntil(',');
if (mode.toInt() == 1) {
int mux = stream.readStringUntil('\n').toInt();
int mode = streamGetInt(',');
if (mode == 1) {
int mux = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->got_data = true;
} }
@ -619,8 +619,8 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
data += mode; data += mode;
} }
} else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil('\n').toInt();
int mux = streamGetInt(',');
int len = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->got_data = true;
sockets[mux]->sock_available = len; sockets[mux]->sock_available = len;


+ 22
- 20
src/TinyGsmClientSIM808.h View File

@ -61,25 +61,27 @@ class TinyGsmSim808 : public TinyGsmSim800 {
sendAT(GF("+CGNSINF")); sendAT(GF("+CGNSINF"));
if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) { return false; } if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) { return false; }
stream.readStringUntil(','); // mode
if (stream.readStringUntil(',').toInt() == 1) fix = true;
stream.readStringUntil(','); // utctime
*lat = stream.readStringUntil(',').toFloat(); // lat
*lon = stream.readStringUntil(',').toFloat(); // lon
if (alt != NULL) *alt = stream.readStringUntil(',').toFloat(); // lon
if (speed != NULL) *speed = stream.readStringUntil(',').toFloat(); // speed
stream.readStringUntil(',');
stream.readStringUntil(',');
stream.readStringUntil(',');
stream.readStringUntil(',');
stream.readStringUntil(',');
stream.readStringUntil(',');
stream.readStringUntil(',');
if (vsat != NULL)
*vsat = stream.readStringUntil(',').toInt(); // viewed satelites
if (usat != NULL)
*usat = stream.readStringUntil(',').toInt(); // used satelites
stream.readStringUntil('\n');
streamSkipUntil(','); // GNSS run status
if (streamGetInt(',') == 1) fix = true; // fix status
streamSkipUntil(','); // UTC date & Time
*lat = streamGetFloat(','); // Latitude
*lon = streamGetFloat(','); // Longitude
if (alt != NULL) *alt = streamGetFloat(','); // MSL Altitude
if (speed != NULL) *speed = streamGetFloat(','); // Speed Over Ground
streamSkipUntil(','); // Course Over Ground
streamSkipUntil(','); // Fix Mode
streamSkipUntil(','); // Reserved1
streamSkipUntil(','); // Horizontal Dilution Of Precision
streamSkipUntil(','); // Position Dilution Of Precision
streamSkipUntil(','); // Vertical Dilution Of Precision
streamSkipUntil(','); // Reserved2
if (vsat != NULL) *vsat = streamGetInt(','); // GNSS Satellites in View
if (usat != NULL) *usat = streamGetInt(','); // GNSS Satellites Used
streamSkipUntil(','); // GLONASS Satellites Used
streamSkipUntil(','); // Reserved3
streamSkipUntil(','); // C/N0 max
streamSkipUntil(','); // HPA
streamSkipUntil('\n'); // VPA
waitResponse(); waitResponse();
@ -121,7 +123,7 @@ class TinyGsmSim808 : public TinyGsmSim800 {
break; break;
} }
} }
stream.readStringUntil('\n');
streamSkipUntil('\n');
waitResponse(); waitResponse();
if (fix) { if (fix) {


+ 16
- 16
src/TinyGsmClientSaraR4.h View File

@ -304,7 +304,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
sendAT(GF("+CEREG?")); sendAT(GF("+CEREG?"));
if (waitResponse(GF(GSM_NL "+CEREG:")) != 1) { return REG_UNKNOWN; } if (waitResponse(GF(GSM_NL "+CEREG:")) != 1) { return REG_UNKNOWN; }
streamSkipUntil(','); /* Skip format (0) */ streamSkipUntil(','); /* Skip format (0) */
int status = stream.readStringUntil('\n').toInt();
int status = streamGetInt('\n');
waitResponse(); waitResponse();
// If we're connected on EPS, great! // If we're connected on EPS, great!
@ -316,7 +316,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
sendAT(GF("+CREG?")); sendAT(GF("+CREG?"));
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) { return REG_UNKNOWN; } if (waitResponse(GF(GSM_NL "+CREG:")) != 1) { return REG_UNKNOWN; }
streamSkipUntil(','); /* Skip format (0) */ streamSkipUntil(','); /* Skip format (0) */
status = stream.readStringUntil('\n').toInt();
status = streamGetInt('\n');
waitResponse(); waitResponse();
return (RegStatus)status; return (RegStatus)status;
} }
@ -453,7 +453,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
sendAT(GF("+CIND?")); sendAT(GF("+CIND?"));
if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { return 0; } if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { return 0; }
int res = stream.readStringUntil(',').toInt();
int res = streamGetInt(',');
int8_t percent = res * 20; // return is 0-5 int8_t percent = res * 20; // return is 0-5
// Wait for final OK // Wait for final OK
waitResponse(); waitResponse();
@ -478,7 +478,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
if (waitResponse(GF(GSM_NL "+UTEMP:")) != 1) { if (waitResponse(GF(GSM_NL "+UTEMP:")) != 1) {
return static_cast<float>(-9999); return static_cast<float>(-9999);
} }
int16_t res = stream.readStringUntil('\n').toInt();
int16_t res = streamGetInt('\n');
float temp = -9999; float temp = -9999;
if (res != -1) { temp = (static_cast<float>(res)) / 10; } if (res != -1) { temp = (static_cast<float>(res)) / 10; }
return temp; return temp;
@ -497,7 +497,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
sendAT(GF("+USOCR=6")); sendAT(GF("+USOCR=6"));
// reply is +USOCR: ## of socket created // reply is +USOCR: ## of socket created
if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { return false; } if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { return false; }
*mux = stream.readStringUntil('\n').toInt();
*mux = streamGetInt('\n');
waitResponse(); waitResponse();
if (ssl) { if (ssl) {
@ -531,8 +531,8 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port, ",1"); sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port, ",1");
if (waitResponse(timeout_ms - (millis() - startMillis), if (waitResponse(timeout_ms - (millis() - startMillis),
GF(GSM_NL "+UUSOCO:")) == 1) { GF(GSM_NL "+UUSOCO:")) == 1) {
stream.readStringUntil(',').toInt(); // skip repeated mux
int connection_status = stream.readStringUntil('\n').toInt();
streamGetInt(','); // skip repeated mux
int connection_status = streamGetInt('\n');
DBG("### Waited", millis() - startMillis, "ms for socket to open"); DBG("### Waited", millis() - startMillis, "ms for socket to open");
return (0 == connection_status); return (0 == connection_status);
} else { } else {
@ -557,7 +557,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
stream.flush(); stream.flush();
if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; } if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
int sent = stream.readStringUntil('\n').toInt();
int sent = streamGetInt('\n');
waitResponse(); // sends back OK after the confirmation of number sent waitResponse(); // sends back OK after the confirmation of number sent
return sent; return sent;
} }
@ -566,7 +566,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
sendAT(GF("+USORD="), mux, ',', (uint16_t)size); sendAT(GF("+USORD="), mux, ',', (uint16_t)size);
if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; } if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
int len = stream.readStringUntil(',').toInt();
int len = streamGetInt(',');
streamSkipUntil('\"'); streamSkipUntil('\"');
for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); } for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); }
@ -586,7 +586,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
// that you have already told to close // that you have already told to close
if (res == 1) { if (res == 1) {
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
result = stream.readStringUntil('\n').toInt();
result = streamGetInt('\n');
// if (result) DBG("### DATA AVAILABLE:", result, "on", mux); // if (result) DBG("### DATA AVAILABLE:", result, "on", mux);
waitResponse(); waitResponse();
} }
@ -603,7 +603,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip type streamSkipUntil(','); // Skip type
int result = stream.readStringUntil('\n').toInt();
int result = streamGetInt('\n');
// 0: the socket is in INACTIVE status (it corresponds to CLOSED status // 0: the socket is in INACTIVE status (it corresponds to CLOSED status
// defined in RFC793 "TCP Protocol Specification" [112]) // defined in RFC793 "TCP Protocol Specification" [112])
// 1: the socket is in LISTEN status // 1: the socket is in LISTEN status
@ -665,8 +665,8 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
index = 5; index = 5;
goto finish; goto finish;
} else if (data.endsWith(GF("+UUSORD:"))) { } else if (data.endsWith(GF("+UUSORD:"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil('\n').toInt();
int mux = streamGetInt(',');
int len = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->got_data = true;
sockets[mux]->sock_available = len; sockets[mux]->sock_available = len;
@ -674,15 +674,15 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE,
data = ""; data = "";
DBG("### URC Data Received:", len, "on", mux); DBG("### URC Data Received:", len, "on", mux);
} else if (data.endsWith(GF("+UUSOCL:"))) { } else if (data.endsWith(GF("+UUSOCL:"))) {
int mux = stream.readStringUntil('\n').toInt();
int mux = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->sock_connected = false; sockets[mux]->sock_connected = false;
} }
data = ""; data = "";
DBG("### URC Sock Closed: ", mux); DBG("### URC Sock Closed: ", mux);
} else if (data.endsWith(GF("+UUSOCO:"))) { } else if (data.endsWith(GF("+UUSOCO:"))) {
int mux = stream.readStringUntil('\n').toInt();
int socket_error = stream.readStringUntil('\n').toInt();
int mux = streamGetInt('\n');
int socket_error = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux] && if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux] &&
socket_error == 0) { socket_error == 0) {
sockets[mux]->sock_connected = true; sockets[mux]->sock_connected = true;


+ 9
- 9
src/TinyGsmClientSequansMonarch.h View File

@ -517,7 +517,7 @@ class TinyGsmSequansMonarch
sendAT(GF("+SQNSRECV="), mux, ',', (uint16_t)size); sendAT(GF("+SQNSRECV="), mux, ',', (uint16_t)size);
if (waitResponse(GF("+SQNSRECV: ")) != 1) { return 0; } if (waitResponse(GF("+SQNSRECV: ")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
int len = stream.readStringUntil('\n').toInt();
int len = streamGetInt('\n');
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
uint32_t startMillis = millis(); uint32_t startMillis = millis();
while (!stream.available() && while (!stream.available() &&
@ -538,10 +538,10 @@ class TinyGsmSequansMonarch
sendAT(GF("+SQNSI="), mux); sendAT(GF("+SQNSI="), mux);
size_t result = 0; size_t result = 0;
if (waitResponse(GF("+SQNSI:")) == 1) { if (waitResponse(GF("+SQNSI:")) == 1) {
streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip total sent
streamSkipUntil(','); // Skip total received
result = stream.readStringUntil(',').toInt(); // keep data not yet read
streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip total sent
streamSkipUntil(','); // Skip total received
result = streamGetInt(','); // keep data not yet read
waitResponse(); waitResponse();
} }
DBG("### Available:", result, "on", mux); DBG("### Available:", result, "on", mux);
@ -555,7 +555,7 @@ class TinyGsmSequansMonarch
for (int muxNo = 1; muxNo <= TINY_GSM_MUX_COUNT; muxNo++) { for (int muxNo = 1; muxNo <= TINY_GSM_MUX_COUNT; muxNo++) {
if (waitResponse(GFP(GSM_OK), GF(GSM_NL "+SQNSS: ")) != 2) { break; } if (waitResponse(GFP(GSM_OK), GF(GSM_NL "+SQNSS: ")) != 2) { break; }
uint8_t status = 0; uint8_t status = 0;
// if (stream.readStringUntil(',').toInt() != muxNo) { // check the mux no
// if (streamGetInt(',') != muxNo) { // check the mux no
// DBG("### Warning: misaligned mux numbers!"); // DBG("### Warning: misaligned mux numbers!");
// } // }
streamSkipUntil(','); // skip mux [use muxNo] streamSkipUntil(','); // skip mux [use muxNo]
@ -623,8 +623,8 @@ class TinyGsmSequansMonarch
index = 5; index = 5;
goto finish; goto finish;
} else if (data.endsWith(GF(GSM_NL "+SQNSRING:"))) { } else if (data.endsWith(GF(GSM_NL "+SQNSRING:"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil('\n').toInt();
int mux = streamGetInt(',');
int len = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && if (mux >= 0 && mux < TINY_GSM_MUX_COUNT &&
sockets[mux % TINY_GSM_MUX_COUNT]) { sockets[mux % TINY_GSM_MUX_COUNT]) {
sockets[mux % TINY_GSM_MUX_COUNT]->got_data = true; sockets[mux % TINY_GSM_MUX_COUNT]->got_data = true;
@ -633,7 +633,7 @@ class TinyGsmSequansMonarch
data = ""; data = "";
DBG("### URC Data Received:", len, "on", mux); DBG("### URC Data Received:", len, "on", mux);
} else if (data.endsWith(GF("SQNSH: "))) { } else if (data.endsWith(GF("SQNSH: "))) {
int mux = stream.readStringUntil('\n').toInt();
int mux = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && if (mux >= 0 && mux < TINY_GSM_MUX_COUNT &&
sockets[mux % TINY_GSM_MUX_COUNT]) { sockets[mux % TINY_GSM_MUX_COUNT]) {
sockets[mux % TINY_GSM_MUX_COUNT]->sock_connected = false; sockets[mux % TINY_GSM_MUX_COUNT]->sock_connected = false;


+ 10
- 12
src/TinyGsmClientUBLOX.h View File

@ -398,9 +398,7 @@ class TinyGsmUBLOX
// <accuracy> - Target accuracy in meters (1 - 999999) // <accuracy> - Target accuracy in meters (1 - 999999)
sendAT(GF("+ULOC=2,2,0,120,1")); sendAT(GF("+ULOC=2,2,0,120,1"));
// wait for first "OK" // wait for first "OK"
if (waitResponse(10000L) != 1) {
return "";
}
if (waitResponse(10000L) != 1) { return ""; }
// wait for the final result - wait full timeout time // wait for the final result - wait full timeout time
if (waitResponse(120000L, GF(GSM_NL "+UULOC:")) != 1) { return ""; } if (waitResponse(120000L, GF(GSM_NL "+UULOC:")) != 1) { return ""; }
String res = stream.readStringUntil('\n'); String res = stream.readStringUntil('\n');
@ -431,7 +429,7 @@ class TinyGsmUBLOX
sendAT(GF("+CIND?")); sendAT(GF("+CIND?"));
if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { return 0; } if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { return 0; }
int res = stream.readStringUntil(',').toInt();
int res = streamGetInt(',');
int8_t percent = res * 20; // return is 0-5 int8_t percent = res * 20; // return is 0-5
// Wait for final OK // Wait for final OK
waitResponse(); waitResponse();
@ -464,7 +462,7 @@ class TinyGsmUBLOX
1) { // reply is +USOCR: ## of socket created 1) { // reply is +USOCR: ## of socket created
return false; return false;
} }
*mux = stream.readStringUntil('\n').toInt();
*mux = streamGetInt('\n');
waitResponse(); waitResponse();
if (ssl) { if (ssl) {
@ -495,7 +493,7 @@ class TinyGsmUBLOX
stream.flush(); stream.flush();
if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; } if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
int sent = stream.readStringUntil('\n').toInt();
int sent = streamGetInt('\n');
waitResponse(); // sends back OK after the confirmation of number sent waitResponse(); // sends back OK after the confirmation of number sent
return sent; return sent;
} }
@ -504,7 +502,7 @@ class TinyGsmUBLOX
sendAT(GF("+USORD="), mux, ',', (uint16_t)size); sendAT(GF("+USORD="), mux, ',', (uint16_t)size);
if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; } if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
int len = stream.readStringUntil(',').toInt();
int len = streamGetInt(',');
streamSkipUntil('\"'); streamSkipUntil('\"');
for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); } for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); }
@ -524,7 +522,7 @@ class TinyGsmUBLOX
// that you have already told to close // that you have already told to close
if (res == 1) { if (res == 1) {
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
result = stream.readStringUntil('\n').toInt();
result = streamGetInt('\n');
// if (result) DBG("### DATA AVAILABLE:", result, "on", mux); // if (result) DBG("### DATA AVAILABLE:", result, "on", mux);
waitResponse(); waitResponse();
} }
@ -541,7 +539,7 @@ class TinyGsmUBLOX
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip type streamSkipUntil(','); // Skip type
int result = stream.readStringUntil('\n').toInt();
int result = streamGetInt('\n');
// 0: the socket is in INACTIVE status (it corresponds to CLOSED status // 0: the socket is in INACTIVE status (it corresponds to CLOSED status
// defined in RFC793 "TCP Protocol Specification" [112]) // defined in RFC793 "TCP Protocol Specification" [112])
// 1: the socket is in LISTEN status // 1: the socket is in LISTEN status
@ -603,8 +601,8 @@ class TinyGsmUBLOX
index = 5; index = 5;
goto finish; goto finish;
} else if (data.endsWith(GF("+UUSORD:"))) { } else if (data.endsWith(GF("+UUSORD:"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil('\n').toInt();
int mux = streamGetInt(',');
int len = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->got_data = true;
sockets[mux]->sock_available = len; sockets[mux]->sock_available = len;
@ -612,7 +610,7 @@ class TinyGsmUBLOX
data = ""; data = "";
DBG("### URC Data Received:", len, "on", mux); DBG("### URC Data Received:", len, "on", mux);
} else if (data.endsWith(GF("+UUSOCL:"))) { } else if (data.endsWith(GF("+UUSOCL:"))) {
int mux = stream.readStringUntil('\n').toInt();
int mux = streamGetInt('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->sock_connected = false; sockets[mux]->sock_connected = false;
} }


+ 1
- 1
src/TinyGsmClientXBee.h View File

@ -1212,7 +1212,7 @@ class TinyGsmXBee
// // read remote ip address // // read remote ip address
// String remoted_address = // String remoted_address =
// stream.readStringUntil('\r'); // read result // stream.readStringUntil('\r'); // read result
// stream.readStringUntil('\r'); // final carriage return
// streamSkipUntil('\r'); // final carriage return
// } // }
} }


+ 33
- 15
src/TinyGsmCommon.h View File

@ -755,7 +755,7 @@ class TinyGsmModem {
GF("+CEREG:")); GF("+CEREG:"));
if (resp != 1 && resp != 2 && resp != 3) { return -1; } if (resp != 1 && resp != 2 && resp != 3) { return -1; }
thisModem().streamSkipUntil(','); /* Skip format (0) */ thisModem().streamSkipUntil(','); /* Skip format (0) */
int status = thisModem().stream.readStringUntil('\n').toInt();
int status = thisModem().streamGetInt('\n');
thisModem().waitResponse(); thisModem().waitResponse();
return status; return status;
} }
@ -772,7 +772,7 @@ class TinyGsmModem {
int16_t getSignalQualityImpl() { int16_t getSignalQualityImpl() {
thisModem().sendAT(GF("+CSQ")); thisModem().sendAT(GF("+CSQ"));
if (thisModem().waitResponse(GF("+CSQ:")) != 1) { return 99; } if (thisModem().waitResponse(GF("+CSQ:")) != 1) { return 99; }
int res = thisModem().stream.readStringUntil(',').toInt();
int res = thisModem().streamGetInt(',');
thisModem().waitResponse(); thisModem().waitResponse();
return res; return res;
} }
@ -785,7 +785,7 @@ class TinyGsmModem {
bool isGprsConnectedImpl() { bool isGprsConnectedImpl() {
thisModem().sendAT(GF("+CGATT?")); thisModem().sendAT(GF("+CGATT?"));
if (thisModem().waitResponse(GF("+CGATT:")) != 1) { return false; } if (thisModem().waitResponse(GF("+CGATT:")) != 1) { return false; }
int res = thisModem().stream.readStringUntil('\n').toInt();
int res = thisModem().streamGetInt('\n');
thisModem().waitResponse(); thisModem().waitResponse();
if (res != 1) { return false; } if (res != 1) { return false; }
@ -975,7 +975,7 @@ class TinyGsmModem {
thisModem().stream.readStringUntil('"'); thisModem().stream.readStringUntil('"');
String hex = thisModem().stream.readStringUntil('"'); String hex = thisModem().stream.readStringUntil('"');
thisModem().stream.readStringUntil(','); thisModem().stream.readStringUntil(',');
int dcs = thisModem().stream.readStringUntil('\n').toInt();
int dcs = thisModem().streamGetInt('\n');
if (dcs == 15) { if (dcs == 15) {
return TinyGsmDecodeHex8bit(hex); return TinyGsmDecodeHex8bit(hex);
@ -1118,7 +1118,7 @@ class TinyGsmModem {
thisModem().streamSkipUntil(','); // Skip battery charge status thisModem().streamSkipUntil(','); // Skip battery charge status
thisModem().streamSkipUntil(','); // Skip battery charge level thisModem().streamSkipUntil(','); // Skip battery charge level
// return voltage in mV // return voltage in mV
uint16_t res = thisModem().stream.readStringUntil(',').toInt();
uint16_t res = thisModem().streamGetInt(',');
// Wait for final OK // Wait for final OK
thisModem().waitResponse(); thisModem().waitResponse();
return res; return res;
@ -1129,7 +1129,7 @@ class TinyGsmModem {
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; }
thisModem().streamSkipUntil(','); // Skip battery charge status thisModem().streamSkipUntil(','); // Skip battery charge status
// Read battery charge level // Read battery charge level
int res = thisModem().stream.readStringUntil(',').toInt();
int res = thisModem().streamGetInt(',');
// Wait for final OK // Wait for final OK
thisModem().waitResponse(); thisModem().waitResponse();
return res; return res;
@ -1139,7 +1139,7 @@ class TinyGsmModem {
thisModem().sendAT(GF("+CBC")); thisModem().sendAT(GF("+CBC"));
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; }
// Read battery charge status // Read battery charge status
int res = thisModem().stream.readStringUntil(',').toInt();
int res = thisModem().streamGetInt(',');
// Wait for final OK // Wait for final OK
thisModem().waitResponse(); thisModem().waitResponse();
return res; return res;
@ -1149,9 +1149,9 @@ class TinyGsmModem {
uint16_t& milliVolts) { uint16_t& milliVolts) {
thisModem().sendAT(GF("+CBC")); thisModem().sendAT(GF("+CBC"));
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; }
chargeState = thisModem().stream.readStringUntil(',').toInt();
percent = thisModem().stream.readStringUntil(',').toInt();
milliVolts = thisModem().stream.readStringUntil('\n').toInt();
chargeState = thisModem().streamGetInt(',');
percent = thisModem().streamGetInt(',');
milliVolts = thisModem().streamGetInt('\n');
// Wait for final OK // Wait for final OK
thisModem().waitResponse(); thisModem().waitResponse();
return true; return true;
@ -1179,11 +1179,29 @@ class TinyGsmModem {
thisModem().streamWrite(tail...); thisModem().streamWrite(tail...);
} }
// template <typename... Args> void sendAT(Args... cmd) {
// thisModem().streamWrite("AT", cmd..., thisModem().gsmNL);
// thisModem().stream.flush();
// TINY_GSM_YIELD(); /* DBG("### AT:", cmd...); */
// }
int16_t streamGetInt(char lastChar) {
char buf[6];
size_t bytesRead = thisModem().stream.readBytesUntil(
lastChar, buf, static_cast<size_t>(6));
if (bytesRead) {
int16_t res = atoi(buf);
return res;
} else {
return -9999;
}
}
float streamGetFloat(char lastChar) {
char buf[12];
size_t bytesRead = thisModem().stream.readBytesUntil(
lastChar, buf, static_cast<size_t>(12));
if (bytesRead) {
float res = atof(buf);
return res;
} else {
return static_cast<float>(-9999);
}
}
bool streamSkipUntil(const char c, const uint32_t timeout_ms = 1000L) { bool streamSkipUntil(const char c, const uint32_t timeout_ms = 1000L) {
uint32_t startMillis = millis(); uint32_t startMillis = millis();


Loading…
Cancel
Save