diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 6ad2752..5f720e2 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -39,7 +39,7 @@ enum RegStatus { }; -class TinyGsmA6 +class TinyGsmA6 : public TinyGsmModem { public: @@ -177,12 +177,8 @@ private: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmA6(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmA6(Stream& stream) -#endif - : stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -190,11 +186,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -212,6 +205,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 +257,14 @@ public: return false; } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -371,22 +381,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 */ @@ -445,6 +439,10 @@ public: return (res == 1); } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIFSR")); String res; @@ -457,10 +455,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 566ad3d..3edbf8a 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmBG96 +class TinyGsmBG96 : public TinyGsmModem { public: @@ -201,12 +201,8 @@ public: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmBG96(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmBG96(Stream& stream) -#endif - : stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -214,11 +210,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -230,6 +223,10 @@ public: return true; } + String getModemName() { + return "Quectel BG96"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -284,6 +281,14 @@ public: return false; // TODO: For now } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -405,22 +410,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 */ @@ -467,6 +456,10 @@ public: return localIP() != 0; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CGPADDR=1")); if (waitResponse(10000L, GF(GSM_NL "+CGPADDR:")) != 1) { @@ -480,10 +473,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 1a990ad..a87432e 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -39,7 +39,7 @@ enum RegStatus { -class TinyGsmESP8266 +class TinyGsmESP8266 : public TinyGsmModem { public: @@ -193,12 +193,8 @@ public: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmESP8266(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmESP8266(Stream& stream) -#endif - : stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -206,11 +202,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -229,6 +222,10 @@ public: return true; } + String getModemName() { + return "ESP8266"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -270,6 +267,14 @@ public: return true; } + bool hasWifi() { + return true; + } + + bool hasGPRS() { + return false; + } + /* * Power functions */ @@ -366,6 +371,10 @@ public: return retVal; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIPSTA_CUR??")); int res1 = waitResponse(GF("ERROR"), GF("+CWJAP_CUR:")); @@ -377,34 +386,6 @@ public: return res2; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - - /* - * 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 5c085ae..8f0093d 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -39,7 +39,7 @@ enum RegStatus { }; -class TinyGsmM590 +class TinyGsmM590 : public TinyGsmModem { public: @@ -174,12 +174,8 @@ private: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmM590(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmM590(Stream& stream) -#endif - : stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -187,11 +183,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -208,6 +201,10 @@ public: return true; } + String getModemName() { + return "Neoway M590"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -259,6 +256,14 @@ public: return false; } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -379,22 +384,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 */ @@ -451,6 +440,10 @@ public: return res == 1; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+XIIC?")); if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { @@ -463,10 +456,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 808cea7..a459d93 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmM95 +class TinyGsmM95 : public TinyGsmModem { public: @@ -181,12 +181,8 @@ private: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmM95(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmM95(Stream& stream) -#endif - : stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -194,11 +190,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -215,6 +208,10 @@ public: return true; } + String getModemName() { + return "Quectel M95"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -273,6 +270,14 @@ public: return false; // TODO: For now } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -416,12 +421,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 */ @@ -470,6 +469,10 @@ public: return true; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+QILOCIP")); stream.readStringUntil('\n'); @@ -478,10 +481,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Phone Call functions */ diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 8928c41..910190c 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 TinyGsmModem { -//============================================================================// -//============================================================================// -// 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,20 +205,11 @@ public: } }; -//============================================================================// -//============================================================================// -// The MC60 Modem Functions -//============================================================================// -//============================================================================// public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmMC60(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmMC60(Stream& stream) -#endif - : stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -246,11 +217,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -264,6 +232,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; ) { @@ -319,15 +298,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 */ @@ -458,22 +447,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 */ @@ -614,6 +587,10 @@ public: return waitResponse(60000L) == 1; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIFSR;E0")); String res; @@ -624,10 +601,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index a6fd8a5..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 +class TinyGsmSim800 : public TinyGsmModem { -//============================================================================// -//============================================================================// -// The Internal SIM800 Client Class -//============================================================================// -//============================================================================// - - public: class GsmClient : public Client @@ -223,12 +209,8 @@ public: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmSim800(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmSim800(Stream& stream) -#endif - : stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -236,11 +218,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { if (!testAT()) { return false; } @@ -254,6 +233,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 +315,14 @@ public: #endif } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -466,22 +466,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 */ @@ -602,6 +586,10 @@ public: return true; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIFSR;E0")); String res; @@ -614,10 +602,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging 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 c411e63..42c736a 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmUBLOX +class TinyGsmUBLOX : public TinyGsmModem { public: @@ -200,12 +200,8 @@ public: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmUBLOX(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmUBLOX(Stream& stream) -#endif - : stream(stream) + : TinyGsmModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -213,9 +209,6 @@ public: /* * Basic functions */ - bool begin(const char* pin = NULL) { - return init(pin); - } bool init(const char* pin = NULL) { if (!testAT()) { @@ -232,6 +225,10 @@ public: return (getSimStatus() == SIM_READY); } + String getModemName() { + return "ESP8266"; + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -284,6 +281,14 @@ public: return true; } + bool hasWifi() { + return false; + } + + bool hasGPRS() { + return true; + } + /* * Power functions */ @@ -404,22 +409,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 */ @@ -485,6 +474,10 @@ public: return localIP() != 0; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+UPSND=0,0")); if (waitResponse(GF(GSM_NL "+UPSND:")) != 1) { @@ -499,10 +492,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index f297a1b..5b4b13e 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -45,7 +45,7 @@ enum XBeeType { }; -class TinyGsmXBee +class TinyGsmXBee : public TinyGsmModem { public: @@ -206,22 +206,15 @@ public: public: -#ifdef GSM_DEFAULT_STREAM - TinyGsmXBee(Stream& stream = GSM_DEFAULT_STREAM) -#else TinyGsmXBee(Stream& stream) -#endif - : stream(stream) + : TinyGsmModem(stream), stream(stream) {} /* * 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 +239,10 @@ public: return ret_val; } + String getModemName() { + return getBeeName(); + } + void setBaud(unsigned long baud) { if (!commandMode()) return; switch(baud) @@ -313,6 +310,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; } @@ -325,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®"; } } @@ -559,6 +567,10 @@ fail: return res; } + /* + * IP Address functions + */ + String getLocalIP() { if (!commandMode()) return ""; // Return immediately sendAT(GF("MY")); @@ -570,10 +582,6 @@ fail: return IPaddr; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * GPRS functions */ diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index b803651..d46ede1 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -69,6 +69,7 @@ namespace { } } #else + #define DBG_PLAIN(...) #define DBG(...) #endif @@ -194,4 +195,108 @@ String TinyGsmDecodeHex16bit(String &instr) { return result; } + + + +class TinyGsmModem +{ + +public: + + TinyGsmModem(Stream& stream) + : stream(stream) + {} + + /* + * Basic functions + */ + + // 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 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() = 0; + + /* + * SIM card functions - only apply to cellular modems + */ + + 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 - only apply to WiFi modems + */ + + virtual bool networkConnect(const char* ssid, const char* pwd) { return false; } + virtual bool networkDisconnect() { return false; } + + /* + * GPRS functions - only apply to cellular modems + */ + + virtual bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) { + return false; + } + virtual bool gprsDisconnect() { return false; } + + /* + * IP Address functions + */ + + virtual String getLocalIP() = 0; + virtual IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + +public: + Stream& stream; +}; + + + + #endif diff --git a/tools/test_build/test_build.ino b/tools/test_build/test_build.ino index 245e38a..0086c2a 100644 --- a/tools/test_build/test_build.ino +++ b/tools/test_build/test_build.ino @@ -3,6 +3,7 @@ * DO NOT USE THIS - this is just a compilation test! * **************************************************************/ +#define TINY_GSM_MODEM_SIM800 #include @@ -77,4 +78,3 @@ void loop() { modem.networkDisconnect(); #endif } -