diff --git a/TinyGsmClientA6.h b/TinyGsmClientA6.h index f698b9f..82407c3 100644 --- a/TinyGsmClientA6.h +++ b/TinyGsmClientA6.h @@ -225,7 +225,7 @@ public: } /* - * SIM card & Network Operator functions + * SIM card functions */ bool simUnlock(const char *pin) { @@ -253,16 +253,6 @@ public: return res; } - int getSignalQuality() { - sendAT(GF("+CSQ")); - if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) { - return 99; - } - int res = streamReadUntil(',').toInt(); - waitResponse(); - return res; - } - SimStatus getSimStatus(unsigned long timeout = 10000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { sendAT(GF("+CPIN?")); @@ -304,6 +294,20 @@ public: return res; } + /* + * Generic network functions + */ + + int getSignalQuality() { + sendAT(GF("+CSQ")); + if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) { + return 99; + } + int res = streamReadUntil(',').toInt(); + waitResponse(); + return res; + } + bool waitForNetwork(unsigned long timeout = 60000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { RegStatus s = getRegistrationStatus(); @@ -392,12 +396,6 @@ public: * Messaging functions */ - void sendUSSD() { - } - - void sendSMS() { - } - bool sendSMS(const String& number, const String& text) { sendAT(GF("+CMGF=1")); waitResponse(); @@ -413,8 +411,7 @@ public: /* * Location functions */ - void getLocation() { - } + /* * Battery functions @@ -505,8 +502,8 @@ private: // TODO: Optimize this! uint8_t waitResponse(uint32_t timeout, String& data, - GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), - GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) + GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), + GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); @@ -599,15 +596,15 @@ private: } uint8_t waitResponse(uint32_t timeout, - GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), - GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) + GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), + GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) { String data; return waitResponse(timeout, data, r1, r2, r3, r4, r5); } uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), - GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) + GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/TinyGsmClientESP8266.h b/TinyGsmClientESP8266.h index a9f58f3..33017af 100644 --- a/TinyGsmClientESP8266.h +++ b/TinyGsmClientESP8266.h @@ -204,7 +204,11 @@ public: } /* - * SIM card & Network Operator functions + * SIM card functions + */ + + /* + * Generic network functions */ int getSignalQuality() { diff --git a/TinyGsmClientM590.h b/TinyGsmClientM590.h index 3d53d0a..cab8252 100644 --- a/TinyGsmClientM590.h +++ b/TinyGsmClientM590.h @@ -234,7 +234,7 @@ public: } /* - * SIM card & Network Operator functions + * SIM card functions */ bool simUnlock(const char *pin) { @@ -262,16 +262,6 @@ public: return res; } - int getSignalQuality() { - sendAT(GF("+CSQ")); - if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) { - return 99; - } - int res = streamReadUntil(',').toInt(); - waitResponse(); - return res; - } - SimStatus getSimStatus(unsigned long timeout = 10000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { sendAT(GF("+CPIN?")); @@ -313,6 +303,20 @@ public: return res; } + /* + * Generic network functions + */ + + int getSignalQuality() { + sendAT(GF("+CSQ")); + if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) { + return 99; + } + int res = streamReadUntil(',').toInt(); + waitResponse(); + return res; + } + bool waitForNetwork(unsigned long timeout = 60000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { RegStatus s = getRegistrationStatus(); @@ -399,12 +403,6 @@ public: * Messaging functions */ - void sendUSSD() { - } - - void sendSMS() { - } - bool sendSMS(const String& number, const String& text) { sendAT(GF("+CMGF=1")); waitResponse(); @@ -420,8 +418,6 @@ public: /* * Location functions */ - void getLocation() { - } /* * Battery functions diff --git a/TinyGsmClientSIM800.h b/TinyGsmClientSIM800.h index 840a00c..134703a 100644 --- a/TinyGsmClientSIM800.h +++ b/TinyGsmClientSIM800.h @@ -241,7 +241,7 @@ public: } /* - * SIM card & Network Operator functions + * SIM card functions */ bool simUnlock(const char *pin) { @@ -269,16 +269,6 @@ public: return res; } - int getSignalQuality() { - sendAT(GF("+CSQ")); - if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) { - return 99; - } - int res = streamReadUntil(',').toInt(); - waitResponse(); - return res; - } - SimStatus getSimStatus(unsigned long timeout = 10000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { sendAT(GF("+CPIN?")); @@ -320,6 +310,20 @@ public: return res; } + /* + * Generic network functions + */ + + int getSignalQuality() { + sendAT(GF("+CSQ")); + if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) { + return 99; + } + int res = streamReadUntil(',').toInt(); + waitResponse(); + return res; + } + bool waitForNetwork(unsigned long timeout = 60000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { RegStatus s = getRegistrationStatus(); @@ -456,12 +460,6 @@ public: * Messaging functions */ - void sendUSSD() { - } - - void sendSMS() { - } - bool sendSMS(const String& number, const String& text) { sendAT(GF("+CMGF=1")); waitResponse(); @@ -504,8 +502,6 @@ public: /* * Location functions */ - void getLocation() { - } String getGsmLocation() { sendAT(GF("+CIPGSMLOC=1,1")); diff --git a/TinyGsmClientXBee.h b/TinyGsmClientXBee.h index 91d0347..5afe740 100644 --- a/TinyGsmClientXBee.h +++ b/TinyGsmClientXBee.h @@ -224,7 +224,7 @@ public: } /* - * SIM card & Network Operator functions + * SIM card functions */ bool simUnlock(const char *pin) { // Not supported @@ -253,23 +253,6 @@ public: return res; } - int getSignalQuality() { - commandMode(); - 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) {}; - char buf[2] = {0}; // Set up buffer for response - buf[0] = streamRead(); - buf[1] = streamRead(); - DBG(buf[0], buf[1], "\n"); - exitCommand(); - int intr = strtol(buf, 0, 16); - 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) { return SIM_READY; // unsupported } @@ -311,6 +294,26 @@ public: return res; } + /* + * Generic network functions + */ + + int getSignalQuality() { + commandMode(); + 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) {}; + char buf[2] = {0}; // Set up buffer for response + buf[0] = streamRead(); + buf[1] = streamRead(); + DBG(buf[0], buf[1], "\n"); + exitCommand(); + int intr = strtol(buf, 0, 16); + if (beeType == S6B) return -93 + intr; // the maximum sensitivity is -93dBm + else return -1*intr; // need to convert to negative number + } bool waitForNetwork(unsigned long timeout = 60000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { diff --git a/tools/test_build/test_build.ino b/tools/test_build/test_build.ino index 1a08f5b..a7fca6f 100644 --- a/tools/test_build/test_build.ino +++ b/tools/test_build/test_build.ino @@ -5,10 +5,10 @@ **************************************************************/ // #define TINY_GSM_MODEM_SIM800 - //#define TINY_GSM_MODEM_A6 - //#define TINY_GSM_MODEM_M590 - //#define TINY_GSM_MODEM_ESP8266 - //#define TINY_GSM_MODEM_XBEE + // #define TINY_GSM_MODEM_A6 + // #define TINY_GSM_MODEM_M590 + // #define TINY_GSM_MODEM_ESP8266 + // #define TINY_GSM_MODEM_XBEE #include