From b771b1f313b8b2fca65855453208463bd93b434e Mon Sep 17 00:00:00 2001 From: SRGDamia1 Date: Tue, 6 Jun 2017 14:51:06 -0400 Subject: [PATCH 1/8] Accounting for API differences in XBee between WiFi and Cellular --- TinyGsmClientXBee.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/TinyGsmClientXBee.h b/TinyGsmClientXBee.h index d3fc4d4..72b3c9d 100644 --- a/TinyGsmClientXBee.h +++ b/TinyGsmClientXBee.h @@ -160,7 +160,14 @@ public: sendAT(GF("GT64")); // shorten the guard time to 100ms waitResponse(); writeChanges(); + sendAT(GF("IM")); // Get the Hardware series; 0x601 for S6B (Wifi) + // 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 exitCommand(); + if (res == "0x601") series = "WIFI"; + else series = "CELL"; guardTime = 125; return true; } @@ -243,7 +250,8 @@ public: int getSignalQuality() { commandMode(); - sendAT(GF("DB")); + if (series == "WIFI") sendAT(GF("DB")); + else sendAT(GF("LM")); // wait for the response unsigned long startMillis = millis(); while (!stream.available() && millis() - startMillis < 1000) {}; @@ -263,7 +271,8 @@ public: RegStatus getRegistrationStatus() { commandMode(); - sendAT(GF("AI")); + if (series == "WIFI") sendAT(GF("AI")); + else sendAT(GF("CI")); // wait for the response unsigned long startMillis = millis(); while (!stream.available() && millis() - startMillis < 1000) {}; @@ -571,6 +580,7 @@ private: private: int guardTime; + String series; Stream& stream; GsmClient* sockets[1]; }; From a129331e426214870e5e777447778c548fd13b72 Mon Sep 17 00:00:00 2001 From: SRGDamia1 Date: Tue, 6 Jun 2017 16:53:13 -0400 Subject: [PATCH 2/8] Added getSignalQuality for ESP8266 --- TinyGsmClientESP8266.h | 17 +++++++++++++++++ TinyGsmClientXBee.h | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/TinyGsmClientESP8266.h b/TinyGsmClientESP8266.h index 0013eea..21885c1 100644 --- a/TinyGsmClientESP8266.h +++ b/TinyGsmClientESP8266.h @@ -203,6 +203,20 @@ public: return autoBaud(); } + /* + * 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(); + } + bool waitForNetwork(unsigned long timeout = 60000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { sendAT(GF("+CIPSTATUS")); @@ -224,6 +238,8 @@ public: */ bool networkConnect(const char* ssid, const char* pwd) { + _ssid = ssid; + sendAT(GF("+CIPMUX=1")); if (waitResponse() != 1) { return false; @@ -418,6 +434,7 @@ private: private: Stream& stream; GsmClient* sockets[5]; + const char* _ssid; }; typedef TinyGsm::GsmClient TinyGsmClient; diff --git a/TinyGsmClientXBee.h b/TinyGsmClientXBee.h index 72b3c9d..b837cb5 100644 --- a/TinyGsmClientXBee.h +++ b/TinyGsmClientXBee.h @@ -219,7 +219,7 @@ public: } /* - * SIM card & Networ Operator functions + * SIM card & Network Operator functions */ bool simUnlock(const char *pin) { // Not supported From d26f1f524ec4d34f8670cdf1a5e0bc99a3532c93 Mon Sep 17 00:00:00 2001 From: SRGDamia1 Date: Wed, 7 Jun 2017 10:58:00 -0400 Subject: [PATCH 3/8] Corrected call for hardware serial --- TinyGsmClientSIM800.h | 2 +- TinyGsmClientXBee.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TinyGsmClientSIM800.h b/TinyGsmClientSIM800.h index 3abbf96..97d54fa 100644 --- a/TinyGsmClientSIM800.h +++ b/TinyGsmClientSIM800.h @@ -241,7 +241,7 @@ public: } /* - * SIM card & Networ Operator functions + * SIM card & Network Operator functions */ bool simUnlock(const char *pin) { diff --git a/TinyGsmClientXBee.h b/TinyGsmClientXBee.h index b837cb5..af37c9f 100644 --- a/TinyGsmClientXBee.h +++ b/TinyGsmClientXBee.h @@ -160,7 +160,7 @@ public: sendAT(GF("GT64")); // shorten the guard time to 100ms waitResponse(); writeChanges(); - sendAT(GF("IM")); // Get the Hardware series; 0x601 for S6B (Wifi) + sendAT(GF("HS")); // Get the Hardware series; 0x601 for S6B (Wifi) // wait for the response unsigned long startMillis = millis(); while (!stream.available() && millis() - startMillis < 1000) {}; From 787fb330543626e6b62e3dc60418db24a37d59ce Mon Sep 17 00:00:00 2001 From: SRGDamia1 Date: Wed, 7 Jun 2017 11:38:47 -0400 Subject: [PATCH 4/8] 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) { From 56db5458e0899770e5903631e8aeb364ddeb4137 Mon Sep 17 00:00:00 2001 From: SRGDamia1 Date: Wed, 7 Jun 2017 14:11:33 -0400 Subject: [PATCH 5/8] Corrected more XBee errors Fixing hex return formats and catching missed wifi/cell differences --- TinyGsmClientXBee.h | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/TinyGsmClientXBee.h b/TinyGsmClientXBee.h index af37c9f..dc5525d 100644 --- a/TinyGsmClientXBee.h +++ b/TinyGsmClientXBee.h @@ -166,7 +166,7 @@ public: while (!stream.available() && millis() - startMillis < 1000) {}; String res = streamReadUntil('\r'); // Does not send an OK, just the result exitCommand(); - if (res == "0x601") series = "WIFI"; + if (res == "601") series = "WIFI"; else series = "CELL"; guardTime = 125; return true; @@ -250,16 +250,15 @@ public: int getSignalQuality() { commandMode(); - if (series == "WIFI") sendAT(GF("DB")); - else sendAT(GF("LM")); + if (series == "WIFI") sendAT(GF("LM")); + else sendAT(GF("DB")); // 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[3] = { 0, }; // Does not send an OK, just the result buf[0] = streamRead(); buf[1] = streamRead(); - buf[2] = streamRead(); - buf[3] = streamRead(); + DBG("\n"); exitCommand(); int intr = strtol(buf, 0, 16); return intr; @@ -279,17 +278,17 @@ public: String res = streamReadUntil('\r'); // Does not send an OK, just the result exitCommand(); - if(res == GF("0x00")) + if(res == GF("0")) return REG_OK_HOME; - else if(res == GF("0x13") || res == GF("0x2A")) + else if(res == GF("13") || res == GF("2A")) return REG_UNREGISTERED; - else if(res == GF("0xFF") || res == GF("0x22") || res == GF("0x23") || - res == GF("0x40") || res == GF("0x41") || res == GF("0x42")) + else if(res == GF("FF") || res == GF("22") || res == GF("23") || + res == GF("40") || res == GF("41") || res == GF("42")) return REG_SEARCHING; - else if(res == GF("0x24")) + else if(res == GF("24")) return REG_DENIED; else return REG_UNKNOWN; @@ -310,7 +309,8 @@ public: bool waitForNetwork(unsigned long timeout = 60000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { commandMode(); - sendAT(GF("AI")); + if (series == "WIFI") sendAT(GF("AI")); + else sendAT(GF("CI")); // wait for the response unsigned long startMillis = millis(); while (!stream.available() && millis() - startMillis < 1000) {}; @@ -519,7 +519,8 @@ private: bool modemGetConnected(uint8_t mux = 1) { commandMode(); - sendAT(GF("AI")); + if (series == "WIFI") sendAT(GF("AI")); + else sendAT(GF("CI")); int res = waitResponse(GF("0")); exitCommand(); return 1 == res; From 8a49f72f1953ee953ae48acd186e9aaab5e51e82 Mon Sep 17 00:00:00 2001 From: SRGDamia1 Date: Wed, 7 Jun 2017 15:51:41 -0400 Subject: [PATCH 6/8] Trying to find error in XBee --- TinyGsmClientXBee.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/TinyGsmClientXBee.h b/TinyGsmClientXBee.h index dc5525d..74a56fd 100644 --- a/TinyGsmClientXBee.h +++ b/TinyGsmClientXBee.h @@ -255,10 +255,10 @@ public: // wait for the response unsigned long startMillis = millis(); while (!stream.available() && millis() - startMillis < 1000) {}; - char buf[3] = { 0, }; // Does not send an OK, just the result + char buf[2] = {0}; // Set up buffer for response buf[0] = streamRead(); buf[1] = streamRead(); - DBG("\n"); + DBG(buf, "\n"); exitCommand(); int intr = strtol(buf, 0, 16); return intr; @@ -538,12 +538,7 @@ private: streamWrite(tail...); } - int streamRead() { - TINY_GSM_YIELD(); - int c = stream.read(); - DBG((char)c); - return c; - } + int streamRead() { return stream.read(); } String streamReadUntil(char c) { TINY_GSM_YIELD(); From 4cbdd941cb7786c29c96a11f3a1caf345214e164 Mon Sep 17 00:00:00 2001 From: SRGDamia1 Date: Wed, 7 Jun 2017 17:11:20 -0400 Subject: [PATCH 7/8] Rewrote XBeeType as an enum, which seems to work much better --- TinyGsmClientXBee.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/TinyGsmClientXBee.h b/TinyGsmClientXBee.h index 74a56fd..fa3b0d1 100644 --- a/TinyGsmClientXBee.h +++ b/TinyGsmClientXBee.h @@ -27,6 +27,11 @@ enum SimStatus { SIM_LOCKED = 2, }; +enum XBeeType { + S6B = 0, + LTEC1 = 1, +}; + enum RegStatus { REG_UNREGISTERED = 0, REG_SEARCHING = 2, @@ -160,14 +165,14 @@ public: sendAT(GF("GT64")); // shorten the guard time to 100ms waitResponse(); writeChanges(); - sendAT(GF("HS")); // Get the Hardware series; 0x601 for S6B (Wifi) + sendAT(GF("HS")); // Get the "Hardware Series"; 0x601 for S6B (Wifi) // 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 exitCommand(); - if (res == "601") series = "WIFI"; - else series = "CELL"; + if (res == "601") beeType = S6B; + else beeType = LTEC1; guardTime = 125; return true; } @@ -250,8 +255,8 @@ public: int getSignalQuality() { commandMode(); - if (series == "WIFI") sendAT(GF("LM")); - else sendAT(GF("DB")); + if (beeType == S6B) sendAT(GF("LM")); // ask for the "link margin" - the dB above sensitivity + else sendAT(GF("DB")); // ask for the cell strenght in dBm // wait for the response unsigned long startMillis = millis(); while (!stream.available() && millis() - startMillis < 1000) {}; @@ -261,7 +266,8 @@ public: DBG(buf, "\n"); exitCommand(); int intr = strtol(buf, 0, 16); - return intr; + if (beeType == S6B) return -93 + intr; // the maximum sensitivity is -93dBm + else return -1*intr; // need to convert to negative number } SimStatus getSimStatus(unsigned long timeout = 10000L) { @@ -270,7 +276,7 @@ public: RegStatus getRegistrationStatus() { commandMode(); - if (series == "WIFI") sendAT(GF("AI")); + if (beeType == S6B) sendAT(GF("AI")); else sendAT(GF("CI")); // wait for the response unsigned long startMillis = millis(); @@ -309,7 +315,7 @@ public: bool waitForNetwork(unsigned long timeout = 60000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { commandMode(); - if (series == "WIFI") sendAT(GF("AI")); + if (beeType == S6B) sendAT(GF("AI")); else sendAT(GF("CI")); // wait for the response unsigned long startMillis = millis(); @@ -519,7 +525,7 @@ private: bool modemGetConnected(uint8_t mux = 1) { commandMode(); - if (series == "WIFI") sendAT(GF("AI")); + if (beeType == S6B) sendAT(GF("AI")); else sendAT(GF("CI")); int res = waitResponse(GF("0")); exitCommand(); @@ -576,7 +582,7 @@ private: private: int guardTime; - String series; + XBeeType beeType; Stream& stream; GsmClient* sockets[1]; }; From 3b6f4b7f598d7b7b25fa6d2c83568ebacd67e76a Mon Sep 17 00:00:00 2001 From: SRGDamia1 Date: Wed, 7 Jun 2017 17:17:34 -0400 Subject: [PATCH 8/8] Tiny fix to XBee debug --- TinyGsmClientXBee.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TinyGsmClientXBee.h b/TinyGsmClientXBee.h index fa3b0d1..aa083e1 100644 --- a/TinyGsmClientXBee.h +++ b/TinyGsmClientXBee.h @@ -263,7 +263,7 @@ public: char buf[2] = {0}; // Set up buffer for response buf[0] = streamRead(); buf[1] = streamRead(); - DBG(buf, "\n"); + DBG(buf[0], buf[1], "\n"); exitCommand(); int intr = strtol(buf, 0, 16); if (beeType == S6B) return -93 + intr; // the maximum sensitivity is -93dBm