From 787fb330543626e6b62e3dc60418db24a37d59ce Mon Sep 17 00:00:00 2001 From: SRGDamia1 Date: Wed, 7 Jun 2017 11:38:47 -0400 Subject: [PATCH] Fixed ESP8266 GetSignalQuality --- TinyGsmClientA6.h | 2 +- TinyGsmClientESP8266.h | 50 ++++++++++++++++++++++++++++++------------ TinyGsmClientM590.h | 2 +- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/TinyGsmClientA6.h b/TinyGsmClientA6.h index 1e16bc5..2eb82b5 100644 --- a/TinyGsmClientA6.h +++ b/TinyGsmClientA6.h @@ -225,7 +225,7 @@ public: } /* - * SIM card & Networ Operator functions + * SIM card & Network Operator functions */ bool simUnlock(const char *pin) { diff --git a/TinyGsmClientESP8266.h b/TinyGsmClientESP8266.h index 21885c1..8f3d790 100644 --- a/TinyGsmClientESP8266.h +++ b/TinyGsmClientESP8266.h @@ -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]; diff --git a/TinyGsmClientM590.h b/TinyGsmClientM590.h index b83a7a2..9ddc6e1 100644 --- a/TinyGsmClientM590.h +++ b/TinyGsmClientM590.h @@ -234,7 +234,7 @@ public: } /* - * SIM card & Networ Operator functions + * SIM card & Network Operator functions */ bool simUnlock(const char *pin) {