diff --git a/library.json b/library.json index 906750b..91b9eaa 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TinyGSM", - "version": "0.6.2", + "version": "0.7.0", "description": "A small Arduino library for GPRS modules, that just works. Includes examples for Blynk, MQTT, File Download, and Web Client. Supports many GSM, LTE, and WiFi modules with AT command interfaces.", "keywords": "GSM, AT commands, AT, SIM800, SIM900, A6, A7, M590, ESP8266, SIM7000, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900A, SIM900D, SIM908, SIM968, M95, MC60, MC60E, BG96, ublox, Quectel, SIMCOM, AI Thinker, LTE, LTE-M", "authors": diff --git a/library.properties b/library.properties index b1423a1..2a9c4d3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TinyGSM -version=0.6.2 +version=0.7.0 author=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy sentence=A small Arduino library for GPRS modules, that just works. diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index b90d1c2..afb0f21 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -36,7 +36,7 @@ enum RegStatus { }; -class TinyGsmA6 : public TinyGsmModem +class TinyGsmA6 { public: @@ -180,7 +180,7 @@ private: public: TinyGsmA6(Stream& stream) - : TinyGsmModem(stream), stream(stream) + : stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -207,6 +207,10 @@ public: return true; } + bool begin(const char* pin = NULL) { + return init(pin); + } + String getModemName() { #if defined(TINY_GSM_MODEM_A6) return "AI-Thinker A6"; @@ -380,6 +384,16 @@ 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; + } + /* * GPRS functions */ @@ -454,6 +468,10 @@ public: return res; } + IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + /* * Phone Call functions */ @@ -655,6 +673,17 @@ public: Utilities */ + template + void streamWrite(T last) { + stream.print(last); + } + + template + void streamWrite(T head, Args... tail) { + stream.print(head); + streamWrite(tail...); + } + template void sendAT(Args... cmd) { streamWrite("AT", cmd..., GSM_NL); @@ -663,6 +692,19 @@ public: //DBG("### AT:", cmd...); } + bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) { + while (millis() - startMillis < timeout && !stream.available()) { + TINY_GSM_YIELD(); + } + if (stream.read() == c) { + return true; + } + } + return false; + } + // TODO: Optimize this! uint8_t waitResponse(uint32_t timeout, String& data, GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 281689c..6352c81 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -37,7 +37,7 @@ enum RegStatus { }; -class TinyGsmBG96 : public TinyGsmModem +class TinyGsmBG96 { public: @@ -216,7 +216,7 @@ private: public: TinyGsmBG96(Stream& stream) - : TinyGsmModem(stream), stream(stream) + : stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -239,6 +239,10 @@ public: return true; } + bool begin(const char* pin = NULL) { + return init(pin); + } + String getModemName() { return "Quectel BG96"; } @@ -424,6 +428,16 @@ 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; + } + /* * GPRS functions */ @@ -486,6 +500,10 @@ public: return res; } + IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + /* * Phone Call functions */ @@ -705,6 +723,17 @@ public: Utilities */ + template + void streamWrite(T last) { + stream.print(last); + } + + template + void streamWrite(T head, Args... tail) { + stream.print(head); + streamWrite(tail...); + } + template void sendAT(Args... cmd) { streamWrite("AT", cmd..., GSM_NL); @@ -713,6 +742,19 @@ public: //DBG("### AT:", cmd...); } + bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) { + while (millis() - startMillis < timeout && !stream.available()) { + TINY_GSM_YIELD(); + } + if (stream.read() == c) { + return true; + } + } + return false; + } + // TODO: Optimize this! uint8_t waitResponse(uint32_t timeout, String& data, GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 9f8e333..c9ba8cb 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -36,7 +36,7 @@ enum RegStatus { -class TinyGsmESP8266 : public TinyGsmModem +class TinyGsmESP8266 { public: @@ -201,7 +201,7 @@ public: public: TinyGsmESP8266(Stream& stream) - : TinyGsmModem(stream), stream(stream) + : stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -231,6 +231,10 @@ public: return true; } + bool begin(const char* pin = NULL) { + return init(pin); + } + String getModemName() { return "ESP8266"; } @@ -395,6 +399,10 @@ public: return res2; } + IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + /* * Client related functions */ @@ -440,6 +448,17 @@ public: Utilities */ + template + void streamWrite(T last) { + stream.print(last); + } + + template + void streamWrite(T head, Args... tail) { + stream.print(head); + streamWrite(tail...); + } + template void sendAT(Args... cmd) { streamWrite("AT", cmd..., GSM_NL); @@ -448,6 +467,19 @@ public: //DBG("### AT:", cmd...); } + bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) { + while (millis() - startMillis < timeout && !stream.available()) { + TINY_GSM_YIELD(); + } + if (stream.read() == c) { + return true; + } + } + return false; + } + // TODO: Optimize this! uint8_t waitResponse(uint32_t timeout, String& data, GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index c16b9c0..fde7f87 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -36,7 +36,7 @@ enum RegStatus { }; -class TinyGsmM590 : public TinyGsmModem +class TinyGsmM590 { public: @@ -177,7 +177,7 @@ private: public: TinyGsmM590(Stream& stream) - : TinyGsmModem(stream), stream(stream) + : stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -204,6 +204,10 @@ public: return true; } + bool begin(const char* pin = NULL) { + return init(pin); + } + String getModemName() { return "Neoway M590"; } @@ -384,6 +388,16 @@ 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; + } + /* * GPRS functions */ @@ -456,6 +470,10 @@ public: return res; } + IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + /* * Phone Call functions */ @@ -596,6 +614,17 @@ public: Utilities */ + template + void streamWrite(T last) { + stream.print(last); + } + + template + void streamWrite(T head, Args... tail) { + stream.print(head); + streamWrite(tail...); + } + template void sendAT(Args... cmd) { streamWrite("AT", cmd..., GSM_NL); @@ -604,6 +633,19 @@ public: //DBG("### AT:", cmd...); } + bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) { + while (millis() - startMillis < timeout && !stream.available()) { + TINY_GSM_YIELD(); + } + if (stream.read() == c) { + return true; + } + } + return false; + } + // TODO: Optimize this! uint8_t waitResponse(uint32_t timeout, String& data, GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 9027215..1f30240 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -37,7 +37,7 @@ enum RegStatus { }; -class TinyGsmM95 : public TinyGsmModem +class TinyGsmM95 { public: @@ -216,7 +216,7 @@ private: public: TinyGsmM95(Stream& stream) - : TinyGsmModem(stream), stream(stream) + : stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -243,6 +243,10 @@ public: return true; } + bool begin(const char* pin = NULL) { + return init(pin); + } + String getModemName() { return "Quectel M95"; } @@ -441,6 +445,16 @@ public: waitResponse(); } + bool waitForNetwork(unsigned long timeout = 60000L) { + for (unsigned long start = millis(); millis() - start < timeout; ) { + if (isNetworkConnected()) { + return true; + } + delay(250); + } + return false; + } + /* * GPRS functions */ @@ -522,6 +536,10 @@ public: return res; } + IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + /* * Messaging functions */ @@ -760,6 +778,17 @@ public: Utilities */ + template + void streamWrite(T last) { + stream.print(last); + } + + template + void streamWrite(T head, Args... tail) { + stream.print(head); + streamWrite(tail...); + } + template void sendAT(Args... cmd) { streamWrite("AT", cmd..., GSM_NL); @@ -768,6 +797,19 @@ public: //DBG("### AT:", cmd...); } + bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) { + while (millis() - startMillis < timeout && !stream.available()) { + TINY_GSM_YIELD(); + } + if (stream.read() == c) { + return true; + } + } + return false; + } + // TODO: Optimize this! uint8_t waitResponse(uint32_t timeout, String& data, GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 591355a..f2283fb 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -41,7 +41,7 @@ enum RegStatus { }; -class TinyGsmMC60 : public TinyGsmModem +class TinyGsmMC60 { public: @@ -220,7 +220,7 @@ private: public: TinyGsmMC60(Stream& stream) - : TinyGsmModem(stream), stream(stream) + : stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -245,6 +245,10 @@ public: return true; } + bool begin(const char* pin = NULL) { + return init(pin); + } + String getModemName() { #if defined(TINY_GSM_MODEM_MC60) return "Quectel MC60"; @@ -456,6 +460,16 @@ 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; + } + /* * GPRS functions */ @@ -550,6 +564,10 @@ public: return res; } + IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + /* * Messaging functions */ @@ -789,6 +807,17 @@ public: Utilities */ + template + void streamWrite(T last) { + stream.print(last); + } + + template + void streamWrite(T head, Args... tail) { + stream.print(head); + streamWrite(tail...); + } + template void sendAT(Args... cmd) { streamWrite("AT", cmd..., GSM_NL); @@ -797,6 +826,19 @@ public: //DBG("### AT:", cmd...); } + bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) { + while (millis() - startMillis < timeout && !stream.available()) { + TINY_GSM_YIELD(); + } + if (stream.read() == c) { + return true; + } + } + return false; + } + // TODO: Optimize this! uint8_t waitResponse(uint32_t timeout, String& data, GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index fd0cbd6..8f8024a 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -45,7 +45,7 @@ enum TinyGSMDateTimeFormat { DATE_DATE = 2 }; -class TinyGsmSim7000 : public TinyGsmModem +class TinyGsmSim7000 { public: @@ -245,7 +245,7 @@ public: public: TinyGsmSim7000(Stream& stream) - : TinyGsmModem(stream), stream(stream) + : stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -268,6 +268,10 @@ public: return true; } + bool begin(const char* pin = NULL) { + return init(pin); + } + String getModemName() { return "SIMCom SIM7000"; } @@ -480,6 +484,16 @@ public: return res; } + bool waitForNetwork(unsigned long timeout = 60000L) { + for (unsigned long start = millis(); millis() - start < timeout; ) { + if (isNetworkConnected()) { + return true; + } + delay(250); + } + return false; + } + String setNetworkMode(uint8_t mode) { sendAT(GF("+CNMP="), mode); if (waitResponse(GF(GSM_NL "+CNMP:")) != 1) { @@ -641,6 +655,10 @@ public: return res; } + IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + /* * Phone Call functions @@ -1019,6 +1037,17 @@ public: Utilities */ + template + void streamWrite(T last) { + stream.print(last); + } + + template + void streamWrite(T head, Args... tail) { + stream.print(head); + streamWrite(tail...); + } + template void sendAT(Args... cmd) { streamWrite("AT", cmd..., GSM_NL); @@ -1027,6 +1056,19 @@ public: //DBG("### AT:", cmd...); } + bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) { + while (millis() - startMillis < timeout && !stream.available()) { + TINY_GSM_YIELD(); + } + if (stream.read() == c) { + return true; + } + } + return false; + } + // TODO: Optimize this! uint8_t waitResponse(uint32_t timeout, String& data, GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index e613d0d..e05c97a 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -42,7 +42,7 @@ enum TinyGSMDateTimeFormat { DATE_DATE = 2 }; -class TinyGsmSim800 : public TinyGsmModem +class TinyGsmSim800 { public: @@ -240,7 +240,7 @@ public: public: TinyGsmSim800(Stream& stream) - : TinyGsmModem(stream), stream(stream) + : stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -265,6 +265,10 @@ public: return true; } + bool begin(const char* pin = NULL) { + return init(pin); + } + String getModemName() { #if defined(TINY_GSM_MODEM_SIM800) return "SIMCom SIM800"; @@ -495,6 +499,16 @@ 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; + } + /* * GPRS functions */ @@ -632,6 +646,10 @@ public: return res; } + IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + /* * Phone Call functions @@ -941,6 +959,17 @@ public: Utilities */ + template + void streamWrite(T last) { + stream.print(last); + } + + template + void streamWrite(T head, Args... tail) { + stream.print(head); + streamWrite(tail...); + } + template void sendAT(Args... cmd) { streamWrite("AT", cmd..., GSM_NL); @@ -949,6 +978,19 @@ public: //DBG("### AT:", cmd...); } + bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) { + while (millis() - startMillis < timeout && !stream.available()) { + TINY_GSM_YIELD(); + } + if (stream.read() == c) { + return true; + } + } + return false; + } + // TODO: Optimize this! uint8_t waitResponse(uint32_t timeout, String& data, GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index 02cd12b..26f0b31 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -20,7 +20,7 @@ #include -#define GSM_NL "\r\n" +#define GSM_NL "\r" static const char GSM_OK[] TINY_GSM_PROGMEM = "OK" GSM_NL; static const char GSM_ERROR[] TINY_GSM_PROGMEM = "ERROR" GSM_NL; @@ -251,11 +251,8 @@ public: /* * Basic functions */ - bool begin() { - return init(); - } - bool init() { + bool init(const char* pin = NULL) { DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION); if (!testAT()) { return false; @@ -268,6 +265,10 @@ public: return true; } + bool begin(const char* pin = NULL) { + return init(pin); + } + void setBaud(unsigned long baud) { sendAT(GF("+IPR="), baud); } @@ -710,11 +711,6 @@ public: /* Utilities */ - bool commandMode(int retries = 2) { - streamWrite(GF("+++")); // enter command mode - return true; - } - template void streamWrite(T last) { stream.print(last); @@ -726,21 +722,25 @@ public: streamWrite(tail...); } - bool streamSkipUntil(char c) { //TODO: timeout - while (true) { - while (!stream.available()) { TINY_GSM_YIELD(); } - if (stream.read() == c) - return true; - } - return false; - } - template void sendAT(Args... cmd) { - streamWrite("AT", cmd..., '\r'); + streamWrite("AT", cmd..., GSM_NL); stream.flush(); TINY_GSM_YIELD(); - DBG("### AT:", cmd...); + //DBG("### AT:", cmd...); + } + + bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) { + while (millis() - startMillis < timeout && !stream.available()) { + TINY_GSM_YIELD(); + } + if (stream.read() == c) { + return true; + } + } + return false; } // TODO: Optimize this! diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index c54c60c..63caa35 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -37,7 +37,7 @@ enum RegStatus { }; -class TinyGsmUBLOX : public TinyGsmModem +class TinyGsmUBLOX { public: @@ -249,7 +249,7 @@ public: public: TinyGsmUBLOX(Stream& stream) - : TinyGsmModem(stream), stream(stream) + : stream(stream) { memset(sockets, 0, sizeof(sockets)); isCatM = false; // For SARA R4 and N4 series @@ -296,6 +296,10 @@ public: } } + bool begin(const char* pin = NULL) { + return init(pin); + } + String getModemName() { sendAT(GF("+CGMI")); String res1; @@ -521,6 +525,16 @@ public: else return false; } + bool waitForNetwork(unsigned long timeout = 60000L) { + for (unsigned long start = millis(); millis() - start < timeout; ) { + if (isNetworkConnected()) { + return true; + } + delay(250); + } + return false; + } + bool setURAT( uint8_t urat ) { // AT+URAT=[,[,<2ndPreferredAct>]] @@ -677,6 +691,10 @@ public: } } + IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + /* * Phone Call functions */ @@ -893,6 +911,17 @@ public: Utilities */ + template + void streamWrite(T last) { + stream.print(last); + } + + template + void streamWrite(T head, Args... tail) { + stream.print(head); + streamWrite(tail...); + } + template void sendAT(Args... cmd) { streamWrite("AT", cmd..., GSM_NL); @@ -901,6 +930,19 @@ public: //DBG("### AT:", cmd...); } + bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) { + while (millis() - startMillis < timeout && !stream.available()) { + TINY_GSM_YIELD(); + } + if (stream.read() == c) { + return true; + } + } + return false; + } + // TODO: Optimize this! uint8_t waitResponse(uint32_t timeout, String& data, GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 4d9efa8..4cd0605 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -49,7 +49,7 @@ enum XBeeType { }; -class TinyGsmXBee : public TinyGsmModem +class TinyGsmXBee { public: @@ -255,7 +255,7 @@ public: public: TinyGsmXBee(Stream& stream) - : TinyGsmModem(stream), stream(stream) + : stream(stream) { beeType = XBEE_UNKNOWN; // Start not knowing what kind of bee it is guardTime = TINY_GSM_XBEE_GUARD_TIME; // Start with the default guard time of 1 second @@ -267,7 +267,7 @@ public: } TinyGsmXBee(Stream& stream, int8_t resetPin) - : TinyGsmModem(stream), stream(stream) + : stream(stream) { beeType = XBEE_UNKNOWN; // Start not knowing what kind of bee it is guardTime = TINY_GSM_XBEE_GUARD_TIME; // Start with the default guard time of 1 second @@ -307,6 +307,10 @@ public: return ret_val; } + bool begin(const char* pin = NULL) { + return init(pin); + } + String getModemName() { return getBeeName(); } @@ -719,6 +723,10 @@ public: return IPaddr; } + IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + /* * GPRS functions */ @@ -925,6 +933,17 @@ public: } } + template + void streamWrite(T last) { + stream.print(last); + } + + template + void streamWrite(T head, Args... tail) { + stream.print(head); + streamWrite(tail...); + } + template void sendAT(Args... cmd) { streamWrite("AT", cmd..., GSM_NL); @@ -933,6 +952,19 @@ public: //DBG("### AT:", cmd...); } + bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) { + while (millis() - startMillis < timeout && !stream.available()) { + TINY_GSM_YIELD(); + } + if (stream.read() == c) { + return true; + } + } + return false; + } + // TODO: Optimize this! // NOTE: This function is used while INSIDE command mode, so we're only // waiting for requested responses. The XBee has no unsoliliced responses diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index 68bf900..3247dac 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -10,7 +10,7 @@ #define TinyGsmCommon_h // The current library version number -#define TINYGSM_VERSION "0.6.2" +#define TINYGSM_VERSION "0.7.0" #if defined(SPARK) || defined(PARTICLE) #include "Particle.h" @@ -202,135 +202,4 @@ 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; - virtual bool poweroff() = 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 int16_t 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; } - virtual bool isGprsConnected() { return false; } - - /* - * IP Address functions - */ - - virtual String getLocalIP() = 0; - virtual IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - - /* - Utilities - */ - - template - void streamWrite(T last) { - stream.print(last); - } - - template - void streamWrite(T head, Args... tail) { - stream.print(head); - streamWrite(tail...); - } - - bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { - unsigned long startMillis = millis(); - while (millis() - startMillis < timeout) { - while (millis() - startMillis < timeout && !stream.available()) { - TINY_GSM_YIELD(); - } - if (stream.read() == c) - return true; - } - return false; - } - -public: - Stream& stream; -}; - - - - #endif