Browse Source

Added some outs for if XBee fails to get to commandMode

v_master
SRGDamia1 7 years ago
parent
commit
e18b1659e3
6 changed files with 45 additions and 28 deletions
  1. +1
    -1
      src/TinyGsmClientA6.h
  2. +1
    -1
      src/TinyGsmClientESP8266.h
  3. +1
    -1
      src/TinyGsmClientM590.h
  4. +1
    -1
      src/TinyGsmClientSIM800.h
  5. +1
    -1
      src/TinyGsmClientU201.h
  6. +40
    -23
      src/TinyGsmClientXBee.h

+ 1
- 1
src/TinyGsmClientA6.h View File

@ -218,7 +218,7 @@ public:
void maintain() {
//while (stream.available()) {
waitResponse(50, NULL, NULL);
waitResponse(10, NULL, NULL);
//}
}


+ 1
- 1
src/TinyGsmClientESP8266.h View File

@ -210,7 +210,7 @@ public:
}
void maintain() {
waitResponse(50, NULL, NULL);
waitResponse(10, NULL, NULL);
}
bool factoryDefault() {


+ 1
- 1
src/TinyGsmClientM590.h View File

@ -214,7 +214,7 @@ public:
void maintain() {
//while (stream.available()) {
waitResponse(50, NULL, NULL);
waitResponse(10, NULL, NULL);
//}
}


+ 1
- 1
src/TinyGsmClientSIM800.h View File

@ -253,7 +253,7 @@ public:
}
}
while (stream.available()) {
waitResponse(50, NULL, NULL);
waitResponse(10, NULL, NULL);
}
}


+ 1
- 1
src/TinyGsmClientU201.h View File

@ -247,7 +247,7 @@ public:
}
}
while (stream.available()) {
waitResponse(50, NULL, NULL);
waitResponse(10, NULL, NULL);
}
}


+ 40
- 23
src/TinyGsmClientXBee.h View File

@ -73,19 +73,25 @@ public:
public:
virtual int connect(const char *host, uint16_t port) {
at->streamClear(); // Empty anything remaining in the buffer;
at->commandMode();
sock_connected = at->modemConnect(host, port, mux, false);
at->writeChanges();
at->exitCommand();
bool sock_connected = false;
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
sock_connected = at->modemConnect(host, port, mux, false);
at->writeChanges();
at->exitCommand();
}
at->streamClear(); // Empty anything remaining in the buffer;
return sock_connected;
}
virtual int connect(IPAddress ip, uint16_t port) {
at->streamClear(); // Empty anything remaining in the buffer;
at->commandMode();
sock_connected = at->modemConnect(ip, port, mux, false);
at->writeChanges();
at->exitCommand();
bool sock_connected = false;
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
sock_connected = at->modemConnect(ip, port, mux, false);
at->writeChanges();
at->exitCommand();
}
at->streamClear(); // Empty anything remaining in the buffer;
return sock_connected;
}
@ -168,19 +174,25 @@ public:
public:
virtual int connect(const char *host, uint16_t port) {
at->streamClear(); // Empty anything remaining in the buffer;
at->commandMode();
sock_connected = at->modemConnect(host, port, mux, true);
at->writeChanges();
at->exitCommand();
bool sock_connected = false;
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
sock_connected = at->modemConnect(host, port, mux, true);
at->writeChanges();
at->exitCommand();
}
at->streamClear(); // Empty anything remaining in the buffer;
return sock_connected;
}
virtual int connect(IPAddress ip, uint16_t port) {
at->streamClear(); // Empty anything remaining in the buffer;
at->commandMode();
sock_connected = at->modemConnect(ip, port, mux, true);
at->writeChanges();
at->exitCommand();
bool sock_connected = false;
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
sock_connected = at->modemConnect(ip, port, mux, true);
at->writeChanges();
at->exitCommand();
}
at->streamClear(); // Empty anything remaining in the buffer;
return sock_connected;
}
};
@ -484,12 +496,17 @@ fail:
private:
int modemConnect(const char* host, uint16_t port, uint8_t mux = 0, bool ssl = false) {
sendAT(GF("LA"), host);
String strIP; strIP.reserve(16);
// wait for the response
unsigned long startMillis = millis();
while (stream.available() < 8 && millis() - startMillis < 30000) {};
strIP = streamReadUntil('\r'); // read result
bool gotIP = false;
while (!gotIP && millis() - startMillis < 30000)
{
sendAT(GF("LA"), host);
while (stream.available() < 4) {};// wait for the response
strIP = streamReadUntil('\r'); // read result
if (!strIP.endsWith(GF("ERROR"))) gotIP = true;
delay(100); // short wait before trying again
}
IPAddress ip = TinyGsmIpFromString(strIP);
return modemConnect(ip, port, mux, ssl);
}
@ -563,7 +580,7 @@ public:
bool commandMode(void) {
delay(guardTime); // cannot send anything for 1 second before entering command mode
streamWrite(GF("+++")); // enter command mode
// DBG("\r\n+++\r\n");
// DBG("\r\n+++");
return 1 == waitResponse(guardTime*2);
}
@ -584,7 +601,7 @@ public:
streamWrite("AT", cmd..., GSM_NL);
stream.flush();
TINY_GSM_YIELD();
//DBG("### AT:", cmd...);
// DBG("### AT:", cmd...);
}
// TODO: Optimize this!
@ -657,7 +674,7 @@ finish:
uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
{
return waitResponse(1000, r1, r2, r3, r4, r5);
return waitResponse(5000, r1, r2, r3, r4, r5);
}
private:


Loading…
Cancel
Save