Browse Source

Added more timeouts to XBee to prevent hanging

I'm remarkably good at getting all of these things to hang..
v_master
SRGDamia1 7 years ago
parent
commit
df8baffee6
1 changed files with 21 additions and 7 deletions
  1. +21
    -7
      TinyGsmClientXBee.h

+ 21
- 7
TinyGsmClientXBee.h View File

@ -222,7 +222,9 @@ public:
String getSimCCID() { String getSimCCID() {
commandMode(); commandMode();
sendAT(GF("S#")); sendAT(GF("S#"));
while (!stream.available()) {}; // wait for the response
// wait for the response
unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < 1000) {};
String res = streamReadUntil('\r'); // Does not send an OK, just the result String res = streamReadUntil('\r'); // Does not send an OK, just the result
exitCommand(); exitCommand();
return res; return res;
@ -231,7 +233,9 @@ public:
String getIMEI() { String getIMEI() {
commandMode(); commandMode();
sendAT(GF("IM")); sendAT(GF("IM"));
while (!stream.available()) {}; // wait for the response
// wait for the response
unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < 1000) {};
String res = streamReadUntil('\r'); // Does not send an OK, just the result String res = streamReadUntil('\r'); // Does not send an OK, just the result
exitCommand(); exitCommand();
return res; return res;
@ -240,7 +244,9 @@ public:
int getSignalQuality() { int getSignalQuality() {
commandMode(); commandMode();
sendAT(GF("DB")); sendAT(GF("DB"));
while (!stream.available()) {}; // wait for the response
// wait for the response
unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < 1000) {};
char buf[4] = { 0, }; // Does not send an OK, just the result char buf[4] = { 0, }; // Does not send an OK, just the result
buf[0] = streamRead(); buf[0] = streamRead();
buf[1] = streamRead(); buf[1] = streamRead();
@ -258,7 +264,9 @@ public:
RegStatus getRegistrationStatus() { RegStatus getRegistrationStatus() {
commandMode(); commandMode();
sendAT(GF("AI")); sendAT(GF("AI"));
while (!stream.available()) {}; // wait for the response
// wait for the response
unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < 1000) {};
String res = streamReadUntil('\r'); // Does not send an OK, just the result String res = streamReadUntil('\r'); // Does not send an OK, just the result
exitCommand(); exitCommand();
@ -281,7 +289,9 @@ public:
String getOperator() { String getOperator() {
commandMode(); commandMode();
sendAT(GF("MN")); sendAT(GF("MN"));
while (!stream.available()) {}; // wait for the response
// wait for the response
unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < 1000) {};
String res = streamReadUntil('\r'); // Does not send an OK, just the result String res = streamReadUntil('\r'); // Does not send an OK, just the result
exitCommand(); exitCommand();
return res; return res;
@ -292,7 +302,9 @@ public:
for (unsigned long start = millis(); millis() - start < timeout; ) { for (unsigned long start = millis(); millis() - start < timeout; ) {
commandMode(); commandMode();
sendAT(GF("AI")); sendAT(GF("AI"));
while (!stream.available()) {}; // wait for the response
// wait for the response
unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < 1000) {};
String res = streamReadUntil('\r'); // Does not send an OK, just the result String res = streamReadUntil('\r'); // Does not send an OK, just the result
exitCommand(); exitCommand();
if (res == GF("0")) { if (res == GF("0")) {
@ -463,7 +475,9 @@ private:
int modemConnect(const char* host, uint16_t port, uint8_t mux = 1) { int modemConnect(const char* host, uint16_t port, uint8_t mux = 1) {
sendAT(GF("LA"), host); sendAT(GF("LA"), host);
String IPaddr; IPaddr.reserve(16); String IPaddr; IPaddr.reserve(16);
while (!stream.available()) {}; // wait for the response
// wait for the response
unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < 1000) {};
IPaddr = streamReadUntil('\r'); // read result IPaddr = streamReadUntil('\r'); // read result
IPAddress ip; IPAddress ip;
ip.fromString(IPaddr); ip.fromString(IPaddr);


Loading…
Cancel
Save