From 56dca5185baf5418bd3d6a9b360fcf82f6c966c4 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 7 Sep 2018 18:15:42 -0400 Subject: [PATCH 1/9] Added virtual master class --- src/TinyGsmClientA6.h | 12 ++--- src/TinyGsmClientBG96.h | 12 ++--- src/TinyGsmClientESP8266.h | 12 ++--- src/TinyGsmClientM590.h | 12 ++--- src/TinyGsmClientM95.h | 12 ++--- src/TinyGsmClientMC60.h | 37 +++------------ src/TinyGsmClientSIM800.h | 12 ++--- src/TinyGsmClientUBLOX.h | 12 ++--- src/TinyGsmClientXBee.h | 12 ++--- src/TinyGsmCommon.h | 95 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 149 insertions(+), 79 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 6ad2752..9dbd80c 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -39,7 +39,7 @@ enum RegStatus { }; -class TinyGsmA6 +class TinyGsmA6 : public TinyGsmMasterModem { public: @@ -182,7 +182,7 @@ public: #else TinyGsmA6(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -445,6 +445,10 @@ public: return (res == 1); } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIFSR")); String res; @@ -457,10 +461,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 566ad3d..6a1de31 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmBG96 +class TinyGsmBG96 : public TinyGsmMasterModem { public: @@ -206,7 +206,7 @@ public: #else TinyGsmBG96(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -467,6 +467,10 @@ public: return localIP() != 0; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CGPADDR=1")); if (waitResponse(10000L, GF(GSM_NL "+CGPADDR:")) != 1) { @@ -480,10 +484,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 1a990ad..4381e85 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -39,7 +39,7 @@ enum RegStatus { -class TinyGsmESP8266 +class TinyGsmESP8266 : public TinyGsmMasterModem { public: @@ -198,7 +198,7 @@ public: #else TinyGsmESP8266(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -366,6 +366,10 @@ public: return retVal; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIPSTA_CUR??")); int res1 = waitResponse(GF("ERROR"), GF("+CWJAP_CUR:")); @@ -377,10 +381,6 @@ public: return res2; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * GPRS functions */ diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index 5c085ae..d3ef97f 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -39,7 +39,7 @@ enum RegStatus { }; -class TinyGsmM590 +class TinyGsmM590 : public TinyGsmMasterModem { public: @@ -179,7 +179,7 @@ public: #else TinyGsmM590(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -451,6 +451,10 @@ public: return res == 1; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+XIIC?")); if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { @@ -463,10 +467,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 808cea7..e45b94f 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmM95 +class TinyGsmM95 : public TinyGsmMasterModem { public: @@ -186,7 +186,7 @@ public: #else TinyGsmM95(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -470,6 +470,10 @@ public: return true; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+QILOCIP")); stream.readStringUntil('\n'); @@ -478,10 +482,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Phone Call functions */ diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 8928c41..7c1c0f4 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -43,24 +43,10 @@ enum RegStatus { REG_UNKNOWN = 4, }; -//============================================================================// -//============================================================================// -// Declaration of the TinyGsmMC60 Class -//============================================================================// -//============================================================================// - - -class TinyGsmMC60 +class TinyGsmMC60 : public TinyGsmMasterModem { -//============================================================================// -//============================================================================// -// The MC60 Internal Client Class -//============================================================================// -//============================================================================// - - public: class GsmClient : public Client @@ -199,12 +185,6 @@ private: RxFifo rx; }; -//============================================================================// -//============================================================================// -// The MC60 Secure Client -//============================================================================// -//============================================================================// - class GsmClientSecure : public GsmClient { @@ -225,11 +205,6 @@ public: } }; -//============================================================================// -//============================================================================// -// The MC60 Modem Functions -//============================================================================// -//============================================================================// public: @@ -238,7 +213,7 @@ public: #else TinyGsmMC60(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -614,6 +589,10 @@ public: return waitResponse(60000L) == 1; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIFSR;E0")); String res; @@ -624,10 +603,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index a6fd8a5..2a77e1b 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -46,7 +46,7 @@ enum RegStatus { //============================================================================// -class TinyGsmSim800 +class TinyGsmSim800 : public TinyGsmMasterModem { //============================================================================// @@ -228,7 +228,7 @@ public: #else TinyGsmSim800(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -602,6 +602,10 @@ public: return true; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIFSR;E0")); String res; @@ -614,10 +618,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index c411e63..f98ff2b 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmUBLOX +class TinyGsmUBLOX : public TinyGsmMasterModem { public: @@ -205,7 +205,7 @@ public: #else TinyGsmUBLOX(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -485,6 +485,10 @@ public: return localIP() != 0; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+UPSND=0,0")); if (waitResponse(GF(GSM_NL "+UPSND:")) != 1) { @@ -499,10 +503,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index f297a1b..89cc696 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -45,7 +45,7 @@ enum XBeeType { }; -class TinyGsmXBee +class TinyGsmXBee : public TinyGsmMasterModem { public: @@ -211,7 +211,7 @@ public: #else TinyGsmXBee(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) {} /* @@ -559,6 +559,10 @@ fail: return res; } + /* + * IP Address functions + */ + String getLocalIP() { if (!commandMode()) return ""; // Return immediately sendAT(GF("MY")); @@ -570,10 +574,6 @@ fail: return IPaddr; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * GPRS functions */ diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index b803651..9df812f 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -194,4 +194,99 @@ String TinyGsmDecodeHex16bit(String &instr) { return result; } + + + +class TinyGsmMasterModem +{ + +public: + +class GsmClient : public Client +{ + friend class TinyGsmXBee; +}; + + +public: + +#ifdef GSM_DEFAULT_STREAM + TinyGsmMasterModem(Stream& stream = GSM_DEFAULT_STREAM) +#else + TinyGsmMasterModem(Stream& stream) +#endif + : stream(stream) + {} + + /* + * Basic functions + */ + + virtual bool begin() = 0; + virtual bool init() = 0; + virtual void setBaud(unsigned long baud) = 0; + virtual bool testAT(unsigned long timeout = 10000L) = 0; + virtual void maintain() = 0; + virtual bool factoryDefault() = 0; + virtual String getModemInfo() = 0; + virtual bool hasSSL() = 0; + + /* + * Power functions + */ + + virtual bool restart() = 0; + + /* + * SIM card functions + */ + + virtual bool simUnlock(const char *pin) = 0; + virtual String getSimCCID() = 0; + virtual String getIMEI() = 0; + virtual String getOperator() = 0; + + /* + * Generic network functions + */ + + virtual int getSignalQuality() = 0; + virtual bool isNetworkConnected() = 0; + + /* + * WiFi functions + */ + + virtual bool networkConnect(const char* ssid, const char* pwd) = 0; + virtual bool networkDisconnect() = 0; + + /* + * GPRS functions + */ + virtual bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) = 0; + virtual bool gprsDisconnect() = 0; + virtual bool isGprsConnected() = 0; + + /* + * IP Address functions + */ + + virtual String getLocalIP() = 0; + virtual IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + + /* + * Messaging functions + */ + + virtual bool sendSMS(const String& number, const String& text) = 0; + +public: + Stream& stream; +}; + + + + #endif From 63ed6fafb730a0500bd5c6de84706e5b2d956bef Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Mon, 10 Sep 2018 15:25:13 -0400 Subject: [PATCH 2/9] Some class cleaning --- src/TinyGsmClientA6.h | 38 ++++++++++----------- src/TinyGsmClientBG96.h | 33 ++++++++----------- src/TinyGsmClientESP8266.h | 41 ++++++++--------------- src/TinyGsmClientM590.h | 33 ++++++++----------- src/TinyGsmClientM95.h | 23 +++++++------ src/TinyGsmClientMC60.h | 58 +++++++++++++++++---------------- src/TinyGsmClientSIM800.h | 42 ++++++++++++------------ src/TinyGsmClientSIM808.h | 6 ++-- src/TinyGsmClientUBLOX.h | 31 +++++++----------- src/TinyGsmClientXBee.h | 26 ++++++++++----- src/TinyGsmCommon.h | 58 +++++++++++++++++++++++---------- tools/test_build/test_build.ino | 7 +++- 12 files changed, 201 insertions(+), 195 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 9dbd80c..e0b8122 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -190,11 +190,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -212,6 +209,15 @@ public: return true; } + String getModemName() { + #if defined(TINY_GSM_MODEM_A6) + return "AI-Thinker A6"; + #elif defined(TINY_GSM_MODEM_A7) + return "AI-Thinker A7"; + #endif + return "AI-Thinker A6"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -255,6 +261,14 @@ public: return false; } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -371,22 +385,6 @@ public: return (s == REG_OK_HOME || s == REG_OK_ROAMING); } - bool waitForNetwork(unsigned long timeout = 60000L) { - for (unsigned long start = millis(); millis() - start < timeout; ) { - if (isNetworkConnected()) { - return true; - } - delay(250); - } - return false; - } - - /* - * WiFi functions - */ - bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE; - bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE; - /* * GPRS functions */ diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 6a1de31..2550cd0 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -214,11 +214,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -230,6 +227,10 @@ public: return true; } + String getModemName() { + return "Quectel BG96"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -284,6 +285,14 @@ public: return false; // TODO: For now } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -405,22 +414,6 @@ public: return (s == REG_OK_HOME || s == REG_OK_ROAMING); } - bool waitForNetwork(unsigned long timeout = 60000L) { - for (unsigned long start = millis(); millis() - start < timeout; ) { - if (isNetworkConnected()) { - return true; - } - delay(250); - } - return false; - } - - /* - * WiFi functions - */ - bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE; - bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE; - /* * GPRS functions */ diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 4381e85..0e12c57 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -206,11 +206,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -229,6 +226,10 @@ public: return true; } + String getModemName() { + return "ESP8266"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -270,6 +271,14 @@ public: return true; } + bool hasWifi() { + return true; + } + + bool hasGPRS() { + return false; + } + /* * Power functions */ @@ -381,30 +390,6 @@ public: return res2; } - /* - * GPRS functions - */ - bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) TINY_GSM_ATTR_NOT_AVAILABLE; - bool gprsDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE; - - /* - * Messaging functions - */ - - /* - * Location functions - */ - - String getGsmLocation() TINY_GSM_ATTR_NOT_AVAILABLE; - - /* - * Battery functions - */ - - uint16_t getBattVoltage() TINY_GSM_ATTR_NOT_AVAILABLE; - - int getBattPercent() TINY_GSM_ATTR_NOT_AVAILABLE; - protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false) { diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index d3ef97f..c6cffd0 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -187,11 +187,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -208,6 +205,10 @@ public: return true; } + String getModemName() { + return "Neoway M590"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -259,6 +260,14 @@ public: return false; } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -379,22 +388,6 @@ public: return (s == REG_OK_HOME || s == REG_OK_ROAMING); } - bool waitForNetwork(unsigned long timeout = 60000L) { - for (unsigned long start = millis(); millis() - start < timeout; ) { - if (isNetworkConnected()) { - return true; - } - delay(250); - } - return false; - } - - /* - * WiFi functions - */ - bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE; - bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE; - /* * GPRS functions */ diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index e45b94f..37ff4dc 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -194,11 +194,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -215,6 +212,10 @@ public: return true; } + String getModemName() { + return "Quectel M95"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -273,6 +274,14 @@ public: return false; // TODO: For now } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -416,12 +425,6 @@ public: waitResponse(); } - /* - * WiFi functions - */ - bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE; - bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE; - /* * GPRS functions */ diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 7c1c0f4..4324f31 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -221,11 +221,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -239,6 +236,17 @@ public: return true; } + String getModemName() { + #if defined(TINY_GSM_MODEM_MC60) + return "Quectel MC60"; + #elif defined(TINY_GSM_MODEM_MC60E) + return "Quectel MC60E"; + #endif + return "Quectel MC60"; + } + + void setBaud(unsigned long baud) { return false; }; + bool testAT(unsigned long timeout = 10000L) { //streamWrite(GF("AAAAA" GSM_NL)); // TODO: extra A's to help detect the baud rate for (unsigned long start = millis(); millis() - start < timeout; ) { @@ -294,15 +302,25 @@ public: /* * under development - * - bool hasSSL() { - sendAT(GF("+QIPSSL=?")); - if (waitResponse(GF(GSM_NL "+CIPSSL:")) != 1) { - return false; - } - return waitResponse() == 1; + */ + // bool hasSSL() { + // sendAT(GF("+QIPSSL=?")); + // if (waitResponse(GF(GSM_NL "+CIPSSL:")) != 1) { + // return false; + // } + // return waitResponse() == 1; + // } + + bool hasSSL() { return false; } + + bool hasWifi() { + return false; } -*/ + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -433,22 +451,6 @@ public: return (s == REG_OK_HOME || s == REG_OK_ROAMING); } - bool waitForNetwork(unsigned long timeout = 60000L) { - for (unsigned long start = millis(); millis() - start < timeout; ) { - if (isNetworkConnected()) { - return true; - } - delay(250); - } - return false; - } - - /* - * WiFi functions - */ - bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE; - bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE; - /* * GPRS functions */ diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 2a77e1b..5071504 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -236,11 +236,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -254,6 +251,19 @@ public: return true; } + String getModemName() { + #if defined(TINY_GSM_MODEM_SIM800) + return "SIMCom SIM800"; + #elif defined(TINY_GSM_MODEM_SIM808) + return "SIMCom SIM808"; + #elif defined(TINY_GSM_MODEM_SIM868) + return "SIMCom SIM868"; + #elif defined(TINY_GSM_MODEM_SIM900) + return "SIMCom SIM900"; + #endif + return "SIMCom SIM800"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -323,6 +333,14 @@ public: #endif } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -466,22 +484,6 @@ public: return (s == REG_OK_HOME || s == REG_OK_ROAMING); } - bool waitForNetwork(unsigned long timeout = 60000L) { - for (unsigned long start = millis(); millis() - start < timeout; ) { - if (isNetworkConnected()) { - return true; - } - delay(250); - } - return false; - } - - /* - * WiFi functions - */ - bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE; - bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE; - /* * GPRS functions */ diff --git a/src/TinyGsmClientSIM808.h b/src/TinyGsmClientSIM808.h index 94d7428..7f3417e 100644 --- a/src/TinyGsmClientSIM808.h +++ b/src/TinyGsmClientSIM808.h @@ -27,7 +27,7 @@ public: // enable GPS bool enableGPS() { - uint16_t state; + // uint16_t state; sendAT(GF("+CGNSPWR=1")); if (waitResponse() != 1) { @@ -38,7 +38,7 @@ public: } bool disableGPS() { - uint16_t state; + // uint16_t state; sendAT(GF("+CGNSPWR=0")); if (waitResponse() != 1) { @@ -65,7 +65,7 @@ public: // works only with ans SIM808 V2 bool getGPS(float *lat, float *lon, float *speed=0, int *alt=0, int *vsat=0, int *usat=0) { //String buffer = ""; - char chr_buffer[12]; + // char chr_buffer[12]; bool fix = false; sendAT(GF("+CGNSINF")); diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index f98ff2b..6024409 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -213,9 +213,6 @@ public: /* * Basic functions */ - bool begin(const char* pin = NULL) { - return init(pin); - } bool init(const char* pin = NULL) { if (!testAT()) { @@ -232,6 +229,10 @@ public: return (getSimStatus() == SIM_READY); } + String getModemName() { + return "ESP8266"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -284,6 +285,14 @@ public: return true; } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -404,22 +413,6 @@ public: return (s == REG_OK_HOME || s == REG_OK_ROAMING); } - bool waitForNetwork(unsigned long timeout = 60000L) { - for (unsigned long start = millis(); millis() - start < timeout; ) { - if (isNetworkConnected()) { - return true; - } - delay(250); - } - return false; - } - - /* - * WiFi functions - */ - bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE; - bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE; - /* * GPRS functions */ diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 89cc696..d99ba8d 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -217,11 +217,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { guardTime = 1100; // Start with a default guard time of 1 second if (!commandMode(10)) return false; // Try up to 10 times for the init @@ -246,6 +243,10 @@ public: return ret_val; } + String getModemName() { + return getBeeName(); + } + void setBaud(unsigned long baud) { if (!commandMode()) return; switch(baud) @@ -313,6 +314,16 @@ public: else return true; } + bool hasWifi() { + if (beeType == XBEE_S6B_WIFI) return true; + else return false; + } + + bool hasGPRS() { + if (beeType == XBEE_S6B_WIFI) return false; + else return true; + } + XBeeType getBeeType() { return beeType; } @@ -360,8 +371,8 @@ public: return false; } - void setupPinSleep(bool maintainAssociation = false) { - if (!commandMode()) return; // Return immediately + bool sleepEnable(bool maintainAssociation = false) { + if (!commandMode()) return false; // Return immediately sendAT(GF("SM"),1); // Pin sleep waitResponse(); if (beeType == XBEE_S6B_WIFI && !maintainAssociation) { @@ -375,14 +386,13 @@ public: } writeChanges(); exitCommand(); + return true; } bool poweroff() TINY_GSM_ATTR_NOT_IMPLEMENTED; bool radioOff() TINY_GSM_ATTR_NOT_IMPLEMENTED; - bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; - /* * SIM card functions */ diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 9df812f..e65fd9a 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -204,7 +204,7 @@ public: class GsmClient : public Client { - friend class TinyGsmXBee; + friend class TinyGsmMasterModem; }; @@ -222,50 +222,78 @@ public: * Basic functions */ - virtual bool begin() = 0; - virtual bool init() = 0; + // Prepare the modem for further functionality + virtual bool init(const char* pin = NULL) = 0; + // Begin is redundant with init + virtual bool begin(const char* pin = NULL) { + return init(pin); + } + // Returns a string with the chip name + virtual String getModemName() = 0; + // Sets the serial communication baud rate virtual void setBaud(unsigned long baud) = 0; + // Checks that the modem is responding to standard AT commands virtual bool testAT(unsigned long timeout = 10000L) = 0; + // Holds open communication with the modem waiting for data to come in virtual void maintain() = 0; + // Resets all modem chip settings to factor defaults virtual bool factoryDefault() = 0; + // Returns the response to a get info request. The format varies by modem. virtual String getModemInfo() = 0; + // Answers whether secure communication is available on this modem virtual bool hasSSL() = 0; + virtual bool hasWifi() = 0; + virtual bool hasGPRS() = 0; /* * Power functions */ virtual bool restart() = 0; + virtual bool poweroff() { return false; } + virtual bool radioOff() { return false; } + virtual bool sleepEnable(bool enable = true) { return false; } /* * SIM card functions */ - virtual bool simUnlock(const char *pin) = 0; - virtual String getSimCCID() = 0; - virtual String getIMEI() = 0; - virtual String getOperator() = 0; + virtual bool simUnlock(const char *pin) { return false; } + virtual String getSimCCID() { return ""; } + virtual String getIMEI() { return ""; } + virtual String getOperator() { return ""; } /* * Generic network functions */ virtual int getSignalQuality() = 0; + // NOTE: this returns whether the modem is registered on the cellular or WiFi + // network NOT whether GPRS or other internet connections are available virtual bool isNetworkConnected() = 0; + virtual bool waitForNetwork(unsigned long timeout = 60000L) { + for (unsigned long start = millis(); millis() - start < timeout; ) { + if (isNetworkConnected()) { + return true; + } + delay(250); + } + return false; + } /* * WiFi functions */ - virtual bool networkConnect(const char* ssid, const char* pwd) = 0; - virtual bool networkDisconnect() = 0; + virtual bool networkConnect(const char* ssid, const char* pwd) { return false; } + virtual bool networkDisconnect() { return false; } /* * GPRS functions */ - virtual bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) = 0; - virtual bool gprsDisconnect() = 0; - virtual bool isGprsConnected() = 0; + + virtual bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) { return false; } + virtual bool gprsDisconnect() { return false; } /* * IP Address functions @@ -276,12 +304,6 @@ public: return TinyGsmIpFromString(getLocalIP()); } - /* - * Messaging functions - */ - - virtual bool sendSMS(const String& number, const String& text) = 0; - public: Stream& stream; }; diff --git a/tools/test_build/test_build.ino b/tools/test_build/test_build.ino index 245e38a..34d2ae9 100644 --- a/tools/test_build/test_build.ino +++ b/tools/test_build/test_build.ino @@ -3,6 +3,12 @@ * DO NOT USE THIS - this is just a compilation test! * **************************************************************/ +// #define TINY_GSM_MODEM_SIM800 // Select for a SIM800, SIM900, or variant thereof +// #define TINY_GSM_MODEM_A6 // Select for a AI-Thinker A6 or A7 chip +// #define TINY_GSM_MODEM_M590 // Select for a Neoway M590 +// #define TINY_GSM_MODEM_UBLOX // Select for most u-blox cellular modems +// #define TINY_GSM_MODEM_ESP8266 // Select for an ESP8266 using the DEFAULT AT COMMAND FIRMWARE +// #define TINY_GSM_MODEM_XBEE // Select for Digi brand WiFi or Cellular XBee's #include @@ -77,4 +83,3 @@ void loop() { modem.networkDisconnect(); #endif } - From 5d3cc777b466ddc1b030889f92e09a1eb996ed31 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Mon, 10 Sep 2018 15:34:04 -0400 Subject: [PATCH 3/9] Fix compiler errors --- src/TinyGsmClientA6.h | 3 ++- src/TinyGsmClientESP8266.h | 3 ++- src/TinyGsmClientUBLOX.h | 3 ++- src/TinyGsmCommon.h | 2 -- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index e0b8122..11a08f8 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -289,7 +289,8 @@ public: bool radioOff() TINY_GSM_ATTR_NOT_IMPLEMENTED; - bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool sleepEnable(bool enable = true) { return false; } + // TINY_GSM_ATTR_NOT_IMPLEMENTED; /* * SIM card functions diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 0e12c57..2cf8b19 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -302,7 +302,8 @@ public: bool radioOff() TINY_GSM_ATTR_NOT_IMPLEMENTED; - bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool sleepEnable(bool enable = true) { return false; } + // TINY_GSM_ATTR_NOT_IMPLEMENTED; /* * SIM card functions diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 6024409..98e0b13 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -320,7 +320,8 @@ public: return true; } - bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool sleepEnable(bool enable = true) { return false; } + // TINY_GSM_ATTR_NOT_IMPLEMENTED; /* * SIM card functions diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index e65fd9a..241d79d 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -250,8 +250,6 @@ public: */ virtual bool restart() = 0; - virtual bool poweroff() { return false; } - virtual bool radioOff() { return false; } virtual bool sleepEnable(bool enable = true) { return false; } /* From 78cd41f8e20c4db32a4cd4e2c845a97a6494ba59 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Mon, 10 Sep 2018 15:51:15 -0400 Subject: [PATCH 4/9] Rename --- src/TinyGsmClientA6.h | 4 ++-- src/TinyGsmClientBG96.h | 4 ++-- src/TinyGsmClientESP8266.h | 4 ++-- src/TinyGsmClientM590.h | 4 ++-- src/TinyGsmClientM95.h | 4 ++-- src/TinyGsmClientMC60.h | 4 ++-- src/TinyGsmClientSIM800.h | 4 ++-- src/TinyGsmClientUBLOX.h | 4 ++-- src/TinyGsmClientXBee.h | 4 ++-- src/TinyGsmCommon.h | 8 ++++---- tools/test_build/test_build.ino | 7 +------ 11 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 11a08f8..6add7f8 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -39,7 +39,7 @@ enum RegStatus { }; -class TinyGsmA6 : public TinyGsmMasterModem +class TinyGsmA6 : public TinyGsmModem { public: @@ -182,7 +182,7 @@ public: #else TinyGsmA6(Stream& stream) #endif - : TinyGsmMasterModem(stream), stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 2550cd0..fda73e5 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmBG96 : public TinyGsmMasterModem +class TinyGsmBG96 : public TinyGsmModem { public: @@ -206,7 +206,7 @@ public: #else TinyGsmBG96(Stream& stream) #endif - : TinyGsmMasterModem(stream), stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 2cf8b19..c9375d8 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -39,7 +39,7 @@ enum RegStatus { -class TinyGsmESP8266 : public TinyGsmMasterModem +class TinyGsmESP8266 : public TinyGsmModem { public: @@ -198,7 +198,7 @@ public: #else TinyGsmESP8266(Stream& stream) #endif - : TinyGsmMasterModem(stream), stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index c6cffd0..ff35681 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -39,7 +39,7 @@ enum RegStatus { }; -class TinyGsmM590 : public TinyGsmMasterModem +class TinyGsmM590 : public TinyGsmModem { public: @@ -179,7 +179,7 @@ public: #else TinyGsmM590(Stream& stream) #endif - : TinyGsmMasterModem(stream), stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 37ff4dc..1b84ff7 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmM95 : public TinyGsmMasterModem +class TinyGsmM95 : public TinyGsmModem { public: @@ -186,7 +186,7 @@ public: #else TinyGsmM95(Stream& stream) #endif - : TinyGsmMasterModem(stream), stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 4324f31..a6a93e7 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -44,7 +44,7 @@ enum RegStatus { }; -class TinyGsmMC60 : public TinyGsmMasterModem +class TinyGsmMC60 : public TinyGsmModem { public: @@ -213,7 +213,7 @@ public: #else TinyGsmMC60(Stream& stream) #endif - : TinyGsmMasterModem(stream), stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 5071504..d1dc1ed 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -46,7 +46,7 @@ enum RegStatus { //============================================================================// -class TinyGsmSim800 : public TinyGsmMasterModem +class TinyGsmSim800 : public TinyGsmModem { //============================================================================// @@ -228,7 +228,7 @@ public: #else TinyGsmSim800(Stream& stream) #endif - : TinyGsmMasterModem(stream), stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 98e0b13..a89bcff 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmUBLOX : public TinyGsmMasterModem +class TinyGsmUBLOX : public TinyGsmModem { public: @@ -205,7 +205,7 @@ public: #else TinyGsmUBLOX(Stream& stream) #endif - : TinyGsmMasterModem(stream), stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index d99ba8d..01d4576 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -45,7 +45,7 @@ enum XBeeType { }; -class TinyGsmXBee : public TinyGsmMasterModem +class TinyGsmXBee : public TinyGsmModem { public: @@ -211,7 +211,7 @@ public: #else TinyGsmXBee(Stream& stream) #endif - : TinyGsmMasterModem(stream), stream(stream) + : TinyGsmModem(stream), stream(stream) {} /* diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 241d79d..6c0943b 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -197,23 +197,23 @@ String TinyGsmDecodeHex16bit(String &instr) { -class TinyGsmMasterModem +class TinyGsmModem { public: class GsmClient : public Client { - friend class TinyGsmMasterModem; + friend class TinyGsmModem; }; public: #ifdef GSM_DEFAULT_STREAM - TinyGsmMasterModem(Stream& stream = GSM_DEFAULT_STREAM) + TinyGsmModem(Stream& stream = GSM_DEFAULT_STREAM) #else - TinyGsmMasterModem(Stream& stream) + TinyGsmModem(Stream& stream) #endif : stream(stream) {} diff --git a/tools/test_build/test_build.ino b/tools/test_build/test_build.ino index 34d2ae9..0086c2a 100644 --- a/tools/test_build/test_build.ino +++ b/tools/test_build/test_build.ino @@ -3,12 +3,7 @@ * DO NOT USE THIS - this is just a compilation test! * **************************************************************/ -// #define TINY_GSM_MODEM_SIM800 // Select for a SIM800, SIM900, or variant thereof -// #define TINY_GSM_MODEM_A6 // Select for a AI-Thinker A6 or A7 chip -// #define TINY_GSM_MODEM_M590 // Select for a Neoway M590 -// #define TINY_GSM_MODEM_UBLOX // Select for most u-blox cellular modems -// #define TINY_GSM_MODEM_ESP8266 // Select for an ESP8266 using the DEFAULT AT COMMAND FIRMWARE -// #define TINY_GSM_MODEM_XBEE // Select for Digi brand WiFi or Cellular XBee's +#define TINY_GSM_MODEM_SIM800 #include From 844d59aeab0899914bffc77377e2261d42ee004b Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 11 Sep 2018 13:10:31 -0400 Subject: [PATCH 5/9] Made class not-purely-virtual Made all default functions return 0/false and print an error message. --- src/TinyGsmCommon.h | 114 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 91 insertions(+), 23 deletions(-) diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 6c0943b..8486ec5 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -69,6 +69,7 @@ namespace { } } #else + #define DBG_PLAIN(...) #define DBG(...) #endif @@ -223,52 +224,104 @@ public: */ // Prepare the modem for further functionality - virtual bool init(const char* pin = NULL) = 0; + virtual bool init(const char* pin = NULL) { + DBG_PLAIN("init function not implemented"); + return false; + } // Begin is redundant with init virtual bool begin(const char* pin = NULL) { return init(pin); } // Returns a string with the chip name - virtual String getModemName() = 0; + virtual String getModemName() { + DBG_PLAIN("getModemName function not implemented"); + return ""; + } // Sets the serial communication baud rate - virtual void setBaud(unsigned long baud) = 0; + virtual void setBaud(unsigned long baud) { + DBG_PLAIN("setBaud function not implemented"); + } // Checks that the modem is responding to standard AT commands - virtual bool testAT(unsigned long timeout = 10000L) = 0; + virtual bool testAT(unsigned long timeout = 10000L) { + DBG_PLAIN("testAT function not implemented"); + return false; + } // Holds open communication with the modem waiting for data to come in - virtual void maintain() = 0; + virtual void maintain() { + DBG_PLAIN("maintain function not implemented"); + } // Resets all modem chip settings to factor defaults - virtual bool factoryDefault() = 0; + virtual bool factoryDefault() { + DBG_PLAIN("factoryDefault function not implemented"); + return false; + } // Returns the response to a get info request. The format varies by modem. - virtual String getModemInfo() = 0; + virtual String getModemInfo() { + DBG_PLAIN("getModemInfo function not implemented"); + return ""; + } // Answers whether secure communication is available on this modem - virtual bool hasSSL() = 0; - virtual bool hasWifi() = 0; - virtual bool hasGPRS() = 0; + virtual bool hasSSL() { + DBG_PLAIN("hasSSL function not implemented"); + return false; + } + virtual bool hasWifi() { + DBG_PLAIN("hasWifi function not implemented"); + return false; + } + virtual bool hasGPRS() { + DBG_PLAIN("hasGPRS function not implemented"); + return false; + } /* * Power functions */ - virtual bool restart() = 0; - virtual bool sleepEnable(bool enable = true) { return false; } + virtual bool restart() { + DBG_PLAIN("restart function not implemented"); + return false; + } + virtual bool sleepEnable(bool enable = true) { + DBG_PLAIN("sleepEnable function not implemented"); + return false; + } /* * SIM card functions */ - virtual bool simUnlock(const char *pin) { return false; } - virtual String getSimCCID() { return ""; } - virtual String getIMEI() { return ""; } - virtual String getOperator() { return ""; } + virtual bool simUnlock(const char *pin) { + DBG_PLAIN("simUnlock function not implemented"); + return false; + } + virtual String getSimCCID() { + DBG_PLAIN("getSimCCID function not implemented"); + return ""; + } + virtual String getIMEI() { + DBG_PLAIN("getIMEI function not implemented"); + return ""; + } + virtual String getOperator() { + DBG_PLAIN("getOperator function not implemented"); + return ""; + } /* * Generic network functions */ - virtual int getSignalQuality() = 0; + virtual int getSignalQuality() { + DBG_PLAIN("getSignalQuality function not implemented"); + return 0; + } // NOTE: this returns whether the modem is registered on the cellular or WiFi // network NOT whether GPRS or other internet connections are available - virtual bool isNetworkConnected() = 0; + virtual bool isNetworkConnected() { + DBG_PLAIN("isNetworkConnected function not implemented"); + return false; + } virtual bool waitForNetwork(unsigned long timeout = 60000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { if (isNetworkConnected()) { @@ -283,21 +336,36 @@ public: * WiFi functions */ - virtual bool networkConnect(const char* ssid, const char* pwd) { return false; } - virtual bool networkDisconnect() { return false; } + virtual bool networkConnect(const char* ssid, const char* pwd) { + DBG_PLAIN("networkConnect function not implemented"); + return false; + } + virtual bool networkDisconnect() { + DBG_PLAIN("networkDisconnect function not implemented"); + return false; + } /* * GPRS functions */ - virtual bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) { return false; } - virtual bool gprsDisconnect() { return false; } + virtual bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) { + DBG_PLAIN("gprsConnect function not implemented"); + return false; + } + virtual bool gprsDisconnect() { + DBG_PLAIN("gprsDisconnect function not implemented"); + return false; + } /* * IP Address functions */ - virtual String getLocalIP() = 0; + virtual String getLocalIP() { + DBG_PLAIN("getLocalIP function not implemented"); + return ""; + } virtual IPAddress localIP() { return TinyGsmIpFromString(getLocalIP()); } From 34104d18fecabdd0532f0ff68df93cefb13892fd Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 12 Sep 2018 14:49:38 -0400 Subject: [PATCH 6/9] Removed default stream --- src/TinyGsmClientA6.h | 4 ---- src/TinyGsmClientBG96.h | 4 ---- src/TinyGsmClientESP8266.h | 4 ---- src/TinyGsmClientM590.h | 4 ---- src/TinyGsmClientM95.h | 4 ---- src/TinyGsmClientMC60.h | 4 ---- src/TinyGsmClientSIM800.h | 4 ---- src/TinyGsmClientUBLOX.h | 4 ---- src/TinyGsmClientXBee.h | 4 ---- src/TinyGsmCommon.h | 12 ------------ 10 files changed, 48 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 6add7f8..b1574ec 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -177,11 +177,7 @@ private: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmA6(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmA6(Stream& stream) -#endif : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index fda73e5..3edbf8a 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -201,11 +201,7 @@ public: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmBG96(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmBG96(Stream& stream) -#endif : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index c9375d8..240fab4 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -193,11 +193,7 @@ public: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmESP8266(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmESP8266(Stream& stream) -#endif : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index ff35681..8f0093d 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -174,11 +174,7 @@ private: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmM590(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmM590(Stream& stream) -#endif : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 1b84ff7..a459d93 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -181,11 +181,7 @@ private: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmM95(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmM95(Stream& stream) -#endif : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index a6a93e7..910190c 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -208,11 +208,7 @@ public: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmMC60(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmMC60(Stream& stream) -#endif : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index d1dc1ed..42380d9 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -223,11 +223,7 @@ public: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmSim800(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmSim800(Stream& stream) -#endif : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index a89bcff..9a61b60 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -200,11 +200,7 @@ public: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmUBLOX(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmUBLOX(Stream& stream) -#endif : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 01d4576..f05e64c 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -206,11 +206,7 @@ public: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmXBee(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmXBee(Stream& stream) -#endif : TinyGsmModem(stream), stream(stream) {} diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 8486ec5..fb53f32 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -203,19 +203,7 @@ class TinyGsmModem public: -class GsmClient : public Client -{ - friend class TinyGsmModem; -}; - - -public: - -#ifdef GSM_DEFAULT_STREAM - TinyGsmModem(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmModem(Stream& stream) -#endif : stream(stream) {} From 115b6c1a4a3c81be4bfa1815b076947c4333b372 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 12 Sep 2018 15:43:04 -0400 Subject: [PATCH 7/9] Extra comment blocks removed from SIM800 --- src/TinyGsmClientSIM800.h | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 42380d9..346701e 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -39,23 +39,9 @@ enum RegStatus { REG_UNKNOWN = 4, }; -//============================================================================// -//============================================================================// -// Declaration of the TinyGsmSim800 Class -//============================================================================// -//============================================================================// - - class TinyGsmSim800 : public TinyGsmModem { -//============================================================================// -//============================================================================// -// The Internal SIM800 Client Class -//============================================================================// -//============================================================================// - - public: class GsmClient : public Client From 2876deb028cec4ad246921547157a6742f94c6bd Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 12 Sep 2018 15:43:54 -0400 Subject: [PATCH 8/9] Fix setup vs enable sleep in XBee --- src/TinyGsmClientXBee.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index f05e64c..5b4b13e 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -332,6 +332,7 @@ public: case XBEE3_LTE1_ATT: return "Digi XBee3™ Cellular LTE CAT 1"; case XBEE3_LTEM_ATT: return "Digi XBee3™ Cellular LTE-M"; case XBEE3_LTENB: return "Digi XBee3™ Cellular NB-IoT"; + default: return "Digi XBee®"; } } @@ -367,8 +368,8 @@ public: return false; } - bool sleepEnable(bool maintainAssociation = false) { - if (!commandMode()) return false; // Return immediately + void setupPinSleep(bool maintainAssociation = false) { + if (!commandMode()) return; // Return immediately sendAT(GF("SM"),1); // Pin sleep waitResponse(); if (beeType == XBEE_S6B_WIFI && !maintainAssociation) { @@ -382,13 +383,14 @@ public: } writeChanges(); exitCommand(); - return true; } bool poweroff() TINY_GSM_ATTR_NOT_IMPLEMENTED; bool radioOff() TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * SIM card functions */ From c5c3cd2af58c3a53ccafbfcbb1e3523d433448e5 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 12 Sep 2018 15:44:59 -0400 Subject: [PATCH 9/9] Back to virtual super class --- src/TinyGsmClientA6.h | 3 +- src/TinyGsmClientESP8266.h | 3 +- src/TinyGsmClientUBLOX.h | 3 +- src/TinyGsmCommon.h | 116 ++++++++----------------------------- 4 files changed, 28 insertions(+), 97 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index b1574ec..5f720e2 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -285,8 +285,7 @@ public: bool radioOff() TINY_GSM_ATTR_NOT_IMPLEMENTED; - bool sleepEnable(bool enable = true) { return false; } - // TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; /* * SIM card functions diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 240fab4..a87432e 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -298,8 +298,7 @@ public: bool radioOff() TINY_GSM_ATTR_NOT_IMPLEMENTED; - bool sleepEnable(bool enable = true) { return false; } - // TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; /* * SIM card functions diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 9a61b60..42c736a 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -316,8 +316,7 @@ public: return true; } - bool sleepEnable(bool enable = true) { return false; } - // TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; /* * SIM card functions diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index fb53f32..d46ede1 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -212,104 +212,51 @@ public: */ // Prepare the modem for further functionality - virtual bool init(const char* pin = NULL) { - DBG_PLAIN("init function not implemented"); - return false; - } + virtual bool init(const char* pin = NULL) = 0; // Begin is redundant with init virtual bool begin(const char* pin = NULL) { return init(pin); } // Returns a string with the chip name - virtual String getModemName() { - DBG_PLAIN("getModemName function not implemented"); - return ""; - } + virtual String getModemName() = 0; // Sets the serial communication baud rate - virtual void setBaud(unsigned long baud) { - DBG_PLAIN("setBaud function not implemented"); - } + virtual void setBaud(unsigned long baud) = 0; // Checks that the modem is responding to standard AT commands - virtual bool testAT(unsigned long timeout = 10000L) { - DBG_PLAIN("testAT function not implemented"); - return false; - } + virtual bool testAT(unsigned long timeout = 10000L) = 0; // Holds open communication with the modem waiting for data to come in - virtual void maintain() { - DBG_PLAIN("maintain function not implemented"); - } + virtual void maintain() = 0; // Resets all modem chip settings to factor defaults - virtual bool factoryDefault() { - DBG_PLAIN("factoryDefault function not implemented"); - return false; - } + virtual bool factoryDefault() = 0; // Returns the response to a get info request. The format varies by modem. - virtual String getModemInfo() { - DBG_PLAIN("getModemInfo function not implemented"); - return ""; - } - // Answers whether secure communication is available on this modem - virtual bool hasSSL() { - DBG_PLAIN("hasSSL function not implemented"); - return false; - } - virtual bool hasWifi() { - DBG_PLAIN("hasWifi function not implemented"); - return false; - } - virtual bool hasGPRS() { - DBG_PLAIN("hasGPRS function not implemented"); - return false; - } + virtual String getModemInfo() = 0; + // Answers whether types of communication are available on this modem + virtual bool hasSSL() = 0; + virtual bool hasWifi() = 0; + virtual bool hasGPRS() = 0; /* * Power functions */ - virtual bool restart() { - DBG_PLAIN("restart function not implemented"); - return false; - } - virtual bool sleepEnable(bool enable = true) { - DBG_PLAIN("sleepEnable function not implemented"); - return false; - } + virtual bool restart() = 0; /* - * SIM card functions + * SIM card functions - only apply to cellular modems */ - virtual bool simUnlock(const char *pin) { - DBG_PLAIN("simUnlock function not implemented"); - return false; - } - virtual String getSimCCID() { - DBG_PLAIN("getSimCCID function not implemented"); - return ""; - } - virtual String getIMEI() { - DBG_PLAIN("getIMEI function not implemented"); - return ""; - } - virtual String getOperator() { - DBG_PLAIN("getOperator function not implemented"); - return ""; - } + virtual bool simUnlock(const char *pin) { return false; } + virtual String getSimCCID() { return ""; } + virtual String getIMEI() { return ""; } + virtual String getOperator() { return ""; } /* * Generic network functions */ - virtual int getSignalQuality() { - DBG_PLAIN("getSignalQuality function not implemented"); - return 0; - } + virtual int getSignalQuality() = 0; // NOTE: this returns whether the modem is registered on the cellular or WiFi // network NOT whether GPRS or other internet connections are available - virtual bool isNetworkConnected() { - DBG_PLAIN("isNetworkConnected function not implemented"); - return false; - } + virtual bool isNetworkConnected() = 0; virtual bool waitForNetwork(unsigned long timeout = 60000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { if (isNetworkConnected()) { @@ -321,39 +268,26 @@ public: } /* - * WiFi functions + * WiFi functions - only apply to WiFi modems */ - virtual bool networkConnect(const char* ssid, const char* pwd) { - DBG_PLAIN("networkConnect function not implemented"); - return false; - } - virtual bool networkDisconnect() { - DBG_PLAIN("networkDisconnect function not implemented"); - return false; - } + virtual bool networkConnect(const char* ssid, const char* pwd) { return false; } + virtual bool networkDisconnect() { return false; } /* - * GPRS functions + * GPRS functions - only apply to cellular modems */ virtual bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) { - DBG_PLAIN("gprsConnect function not implemented"); - return false; - } - virtual bool gprsDisconnect() { - DBG_PLAIN("gprsDisconnect function not implemented"); return false; } + virtual bool gprsDisconnect() { return false; } /* * IP Address functions */ - virtual String getLocalIP() { - DBG_PLAIN("getLocalIP function not implemented"); - return ""; - } + virtual String getLocalIP() = 0; virtual IPAddress localIP() { return TinyGsmIpFromString(getLocalIP()); }