Browse Source

Add getModemInfo() and initial SSL support for ESP8266

v_master
Volodymyr Shymanskyy 7 years ago
parent
commit
0e17c6529e
2 changed files with 48 additions and 5 deletions
  1. +2
    -1
      TinyGsmClient.h
  2. +46
    -4
      TinyGsmClientESP8266.h

+ 2
- 1
TinyGsmClient.h View File

@ -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 <TinyGsmClientESP8266.h>
typedef TinyGsm::GsmClient TinyGsmClient;
typedef TinyGsm::GsmClientSecure TinyGsmClientSecure;
#elif defined(TINY_GSM_MODEM_XBEE)
#define TINY_GSM_MODEM_HAS_GPRS


+ 46
- 4
TinyGsmClientESP8266.h View File

@ -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];
};


Loading…
Cancel
Save