From 144a9c371e15e2c4b449c2facb9a3c5cfe1f0a0c Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Tue, 12 Sep 2017 13:32:34 +0300 Subject: [PATCH] Integrate SIM808 nicely --- TinyGsmClient.h | 18 ++++++++++++++++-- TinyGsmClientA6.h | 2 -- TinyGsmClientESP8266.h | 2 -- TinyGsmClientM590.h | 2 -- TinyGsmClientSIM800.h | 21 +++++++++------------ TinyGsmClientSIM808.h | 4 ++-- examples/AllFunctions/AllFunctions.ino | 12 ++++++++++-- 7 files changed, 37 insertions(+), 24 deletions(-) diff --git a/TinyGsmClient.h b/TinyGsmClient.h index 040e9b2..36cc919 100644 --- a/TinyGsmClient.h +++ b/TinyGsmClient.h @@ -11,14 +11,28 @@ #if defined(TINY_GSM_MODEM_SIM800) || defined(TINY_GSM_MODEM_SIM900) #include -#elif defined(TINY_GSM_MODEM_SIM808) -#include + typedef TinyGsmSim800 TinyGsm; + typedef TinyGsmSim800::GsmClient TinyGsmClient; + typedef TinyGsmSim800::GsmClientSecure TinyGsmClientSecure; + +#elif defined(TINY_GSM_MODEM_SIM808) || defined(TINY_GSM_MODEM_SIM868) + #include + typedef TinyGsmSim808 TinyGsm; + typedef TinyGsmSim808::GsmClient TinyGsmClient; + typedef TinyGsmSim808::GsmClientSecure TinyGsmClientSecure; + #elif defined(TINY_GSM_MODEM_A6) || defined(TINY_GSM_MODEM_A7) #include + typedef TinyGsm::GsmClient TinyGsmClient; + #elif defined(TINY_GSM_MODEM_M590) #include + typedef TinyGsm::GsmClient TinyGsmClient; + #elif defined(TINY_GSM_MODEM_ESP8266) #include + typedef TinyGsm::GsmClient TinyGsmClient; + #else #error "Please define GSM modem model" #endif diff --git a/TinyGsmClientA6.h b/TinyGsmClientA6.h index 9af5bb6..c8c0db0 100644 --- a/TinyGsmClientA6.h +++ b/TinyGsmClientA6.h @@ -714,6 +714,4 @@ private: GsmClient* sockets[TINY_GSM_MUX_COUNT]; }; -typedef TinyGsm::GsmClient TinyGsmClient; - #endif diff --git a/TinyGsmClientESP8266.h b/TinyGsmClientESP8266.h index 41e1dc8..b15a70e 100644 --- a/TinyGsmClientESP8266.h +++ b/TinyGsmClientESP8266.h @@ -396,6 +396,4 @@ private: GsmClient* sockets[TINY_GSM_MUX_COUNT]; }; -typedef TinyGsm::GsmClient TinyGsmClient; - #endif diff --git a/TinyGsmClientM590.h b/TinyGsmClientM590.h index 35ee3c4..d6a4e4c 100644 --- a/TinyGsmClientM590.h +++ b/TinyGsmClientM590.h @@ -702,6 +702,4 @@ private: GsmClient* sockets[TINY_GSM_MUX_COUNT]; }; -typedef TinyGsm::GsmClient TinyGsmClient; - #endif diff --git a/TinyGsmClientSIM800.h b/TinyGsmClientSIM800.h index 72a5b78..b437719 100644 --- a/TinyGsmClientSIM800.h +++ b/TinyGsmClientSIM800.h @@ -40,24 +40,24 @@ enum RegStatus { }; -class TinyGsm +class TinyGsmSim800 { public: class GsmClient : public Client { - friend class TinyGsm; + friend class TinyGsmSim800; typedef TinyGsmFifo RxFifo; public: GsmClient() {} - GsmClient(TinyGsm& modem, uint8_t mux = 1) { + GsmClient(TinyGsmSim800& modem, uint8_t mux = 1) { init(&modem, mux); } - bool init(TinyGsm* modem, uint8_t mux = 1) { + bool init(TinyGsmSim800* modem, uint8_t mux = 1) { this->at = modem; this->mux = mux; sock_available = 0; @@ -171,7 +171,7 @@ public: String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED; private: - TinyGsm* at; + TinyGsmSim800* at; uint8_t mux; uint16_t sock_available; uint32_t prev_check; @@ -185,7 +185,7 @@ class GsmClientSecure : public GsmClient public: GsmClientSecure() {} - GsmClientSecure(TinyGsm& modem, uint8_t mux = 1) + GsmClientSecure(TinyGsmSim800& modem, uint8_t mux = 1) : GsmClient(modem, mux) {} @@ -200,7 +200,7 @@ public: public: - TinyGsm(Stream& stream) + TinyGsmSim800(Stream& stream) : stream(stream) { memset(sockets, 0, sizeof(sockets)); @@ -672,7 +672,7 @@ public: return res; } -private: +protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false) { sendAT(GF("+CIPSSL="), ssl); @@ -904,12 +904,9 @@ finish: return waitResponse(1000, r1, r2, r3, r4, r5); } -private: +protected: Stream& stream; GsmClient* sockets[TINY_GSM_MUX_COUNT]; }; -typedef TinyGsm::GsmClient TinyGsmClient; -typedef TinyGsm::GsmClientSecure TinyGsmClientSecure; - #endif diff --git a/TinyGsmClientSIM808.h b/TinyGsmClientSIM808.h index aea2324..2b9c49a 100644 --- a/TinyGsmClientSIM808.h +++ b/TinyGsmClientSIM808.h @@ -11,13 +11,13 @@ #include -class TinyGsmSim808: public TinyGsm +class TinyGsmSim808: public TinyGsmSim800 { public: TinyGsmSim808(Stream& stream) - : TinyGsm(stream) + : TinyGsmSim800(stream) {} /* diff --git a/examples/AllFunctions/AllFunctions.ino b/examples/AllFunctions/AllFunctions.ino index b3a8c62..0dd80bd 100644 --- a/examples/AllFunctions/AllFunctions.ino +++ b/examples/AllFunctions/AllFunctions.ino @@ -11,6 +11,7 @@ // Select your modem: #define TINY_GSM_MODEM_SIM800 +// #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM900 // #define TINY_GSM_MODEM_A6 // #define TINY_GSM_MODEM_A7 @@ -125,7 +126,14 @@ void loop() { String ussd_phone_num = modem.sendUSSD("*161#"); DBG("Phone number (USSD):", ussd_phone_num); -#ifdef SMS_TARGET +#if defined(TINY_GSM_MODEM_SIM808) + modem.enableGPS(); + String gps_raw = modem.getGPSraw(); + modem.disableGPS(); + DBG("GPS raw data:", gps_raw); +#endif + +#if defined(SMS_TARGET) res = modem.sendSMS(SMS_TARGET, String("Hello from ") + imei); DBG("SMS:", res ? "OK" : "fail"); @@ -134,7 +142,7 @@ void loop() { DBG("UTF16 SMS:", res ? "OK" : "fail"); #endif -#ifdef CALL_TARGET +#if defined(CALL_TARGET) DBG("Calling:", CALL_TARGET); // This is NOT supported on M590