diff --git a/TinyGsmClient.h b/TinyGsmClient.h index 5f07600..32f3c23 100644 --- a/TinyGsmClient.h +++ b/TinyGsmClient.h @@ -9,7 +9,7 @@ #ifndef TinyGsmClient_h #define TinyGsmClient_h -#if defined(TINY_GSM_MODEM_SIM800) || defined(TINY_GSM_MODEM_SIM868) || defined(TINY_GSM_MODEM_U201) +#if defined(TINY_GSM_MODEM_SIM800) || defined(TINY_GSM_MODEM_SIM868) || defined(TINY_GSM_MODEM_U201) || defined(TINY_GSM_MODEM_ESP8266) #define TINY_GSM_MODEM_HAS_SSL #endif @@ -52,6 +52,7 @@ #define TINY_GSM_MODEM_HAS_WIFI #include typedef TinyGsm::GsmClient TinyGsmClient; + typedef TinyGsm::GsmClientSecure TinyGsmClientSecure; #elif defined(TINY_GSM_MODEM_XBEE) #define TINY_GSM_MODEM_HAS_GPRS diff --git a/TinyGsmClientESP8266.h b/TinyGsmClientESP8266.h index a74f360..100803c 100644 --- a/TinyGsmClientESP8266.h +++ b/TinyGsmClientESP8266.h @@ -148,6 +148,24 @@ private: RxFifo rx; }; +class GsmClientSecure : public GsmClient +{ +public: + GsmClientSecure() {} + + GsmClientSecure(TinyGsm& modem, uint8_t mux = 1) + : GsmClient(modem, mux) + {} + +public: + virtual int connect(const char *host, uint16_t port) { + TINY_GSM_YIELD(); + rx.clear(); + sock_connected = at->modemConnect(host, port, mux, true); + return sock_connected; + } +}; + public: TinyGsm(Stream& stream) @@ -201,6 +219,22 @@ public: return waitResponse() == 1; } + String getModemInfo() { + sendAT(GF("+GMR")); + String res; + if (waitResponse(1000L, res) != 1) { + return ""; + } + res.replace(GSM_NL "OK" GSM_NL, ""); + res.replace(GSM_NL, " "); + res.trim(); + return res; + } + + bool hasSSL() { + return true; + } + /* * Power functions */ @@ -241,6 +275,10 @@ public: return res2; } + bool isNetworkConnected() { + return true; // TODO + } + bool waitForNetwork(unsigned long timeout = 60000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { sendAT(GF("+CIPSTATUS")); @@ -303,10 +341,14 @@ public: return TinyGsmIpFromString(getLocalIP()); } -private: +protected: - int modemConnect(const char* host, uint16_t port, uint8_t mux) { - sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port, GF(","), TINY_GSM_TCP_KEEP_ALIVE); + bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false) { + if (ssl) { + sendAT(GF("+CIPSSLSIZE=4096")); + waitResponse(); + } + sendAT(GF("+CIPSTART="), mux, ',', ssl ? GF("\"SSL") : GF("\"TCP"), GF("\",\""), host, GF("\","), port, GF(","), TINY_GSM_TCP_KEEP_ALIVE); int rsp = waitResponse(75000L, GFP(GSM_OK), GFP(GSM_ERROR), @@ -450,7 +492,7 @@ finish: return waitResponse(1000, r1, r2, r3, r4, r5); } -private: +protected: Stream& stream; GsmClient* sockets[TINY_GSM_MUX_COUNT]; };