Fixed ESP8266 GetSignalQuality
This commit is contained in:
@@ -225,7 +225,7 @@ public:
|
||||
}
|
||||
|
||||
/*
|
||||
* SIM card & Networ Operator functions
|
||||
* SIM card & Network Operator functions
|
||||
*/
|
||||
|
||||
bool simUnlock(const char *pin) {
|
||||
|
@@ -207,23 +207,25 @@ public:
|
||||
* SIM card & Network Operator functions
|
||||
*/
|
||||
|
||||
int getSignalQuality() {
|
||||
sendAT(GF("+CWLAP=\""), _ssid, GF("\""));
|
||||
String res1 = stream.readStringUntil(':');
|
||||
DBG(GSM_NL, res1, ':');
|
||||
String res2 = stream.readStringUntil(',');
|
||||
DBG(res2);
|
||||
waitResponse();
|
||||
return res2.toInt();
|
||||
}
|
||||
int getSignalQuality() {
|
||||
sendAT(GF("+CWLAP=\""), _ssid, GF("\""));
|
||||
DBG(GSM_NL, "<<< ");
|
||||
streamSkipUntil(':');
|
||||
streamSkipUntil(',');
|
||||
streamSkipUntil(',');
|
||||
streamSkipUntil(',');
|
||||
String res2 = streamReadUntil(',');
|
||||
streamSkipUntil(')');
|
||||
waitResponse();
|
||||
return res2.toInt();
|
||||
}
|
||||
|
||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||
sendAT(GF("+CIPSTATUS"));
|
||||
String res1 = stream.readStringUntil(':');
|
||||
DBG(GSM_NL, res1, ':');
|
||||
String res2 = stream.readStringUntil(*GSM_NL);
|
||||
DBG(res2);
|
||||
DBG(GSM_NL, "<<< ");
|
||||
String res1 = streamReadUntil(':');
|
||||
String res2 = streamReadUntil(*GSM_NL);
|
||||
waitResponse();
|
||||
if (res2 == GF("2") || res2 == GF("3") || res2 == GF("4")) {
|
||||
return true;
|
||||
@@ -280,7 +282,7 @@ public:
|
||||
streamWrite("AT", cmd..., GSM_NL);
|
||||
stream.flush();
|
||||
TINY_GSM_YIELD();
|
||||
DBG(GSM_NL, ">>> AT:", cmd...);
|
||||
DBG(GSM_NL, ">>> AT", cmd...);
|
||||
}
|
||||
|
||||
// TODO: Optimize this!
|
||||
@@ -431,6 +433,26 @@ private:
|
||||
|
||||
int streamRead() { return stream.read(); }
|
||||
|
||||
String streamReadUntil(char c) {
|
||||
String return_string = stream.readStringUntil(c);
|
||||
return_string.trim();
|
||||
if (String(c) == GSM_NL || String(c) == "\n"){
|
||||
DBG(return_string, c, " ");
|
||||
} else DBG(return_string, c);
|
||||
return return_string;
|
||||
}
|
||||
|
||||
bool streamSkipUntil(char c) {
|
||||
String skipped = stream.readStringUntil(c);
|
||||
skipped.trim();
|
||||
if (skipped.length()) {
|
||||
if (String(c) == GSM_NL || String(c) == "\n"){
|
||||
DBG(skipped, c, " ");
|
||||
} else DBG(skipped, c);
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
private:
|
||||
Stream& stream;
|
||||
GsmClient* sockets[5];
|
||||
|
@@ -234,7 +234,7 @@ public:
|
||||
}
|
||||
|
||||
/*
|
||||
* SIM card & Networ Operator functions
|
||||
* SIM card & Network Operator functions
|
||||
*/
|
||||
|
||||
bool simUnlock(const char *pin) {
|
||||
|
Reference in New Issue
Block a user