Added mux check for esp socket close

This commit is contained in:
SRGDamia1
2017-10-25 16:20:51 -04:00
parent 28903e76a5
commit 2444373357

View File

@@ -362,7 +362,7 @@ protected:
GFP(GSM_OK), GFP(GSM_OK),
GFP(GSM_ERROR), GFP(GSM_ERROR),
GF(GSM_NL "ALREADY CONNECT" GSM_NL)); GF(GSM_NL "ALREADY CONNECT" GSM_NL));
waitResponse(100, GF("1,CONNECT")); // TODO: use mux waitResponse(100, GF("CONNECT")); // TODO: use mux
return (1 == rsp); return (1 == rsp);
} }
@@ -480,12 +480,15 @@ public:
DBG("### Fewer characters received than expected: ", sockets[mux]->available(), " vs ", len_orig); DBG("### Fewer characters received than expected: ", sockets[mux]->available(), " vs ", len_orig);
} }
data = ""; data = "";
return index; } else if (data.endsWith(GF("CLOSED"))) {
} else if (data.endsWith(GF("1,CLOSED"))) { //TODO: use mux int nl = data.lastIndexOf(GSM_NL, data.length()-8);
DBG("### Socket has been closed."); int coma = data.indexOf(',', nl+2);
sockets[1]->sock_connected = false; int mux = data.substring(nl+2, coma).toInt();
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->sock_connected = false;
}
data = ""; data = "";
return index; DBG("### Closed: ", mux);
} }
} }
} while (millis() - startMillis < timeout); } while (millis() - startMillis < timeout);