Add getModemInfo() and initial SSL support for ESP8266
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
#ifndef TinyGsmClient_h
|
#ifndef TinyGsmClient_h
|
||||||
#define 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
|
#define TINY_GSM_MODEM_HAS_SSL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -52,6 +52,7 @@
|
|||||||
#define TINY_GSM_MODEM_HAS_WIFI
|
#define TINY_GSM_MODEM_HAS_WIFI
|
||||||
#include <TinyGsmClientESP8266.h>
|
#include <TinyGsmClientESP8266.h>
|
||||||
typedef TinyGsm::GsmClient TinyGsmClient;
|
typedef TinyGsm::GsmClient TinyGsmClient;
|
||||||
|
typedef TinyGsm::GsmClientSecure TinyGsmClientSecure;
|
||||||
|
|
||||||
#elif defined(TINY_GSM_MODEM_XBEE)
|
#elif defined(TINY_GSM_MODEM_XBEE)
|
||||||
#define TINY_GSM_MODEM_HAS_GPRS
|
#define TINY_GSM_MODEM_HAS_GPRS
|
||||||
|
@@ -148,6 +148,24 @@ private:
|
|||||||
RxFifo rx;
|
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:
|
public:
|
||||||
|
|
||||||
TinyGsm(Stream& stream)
|
TinyGsm(Stream& stream)
|
||||||
@@ -201,6 +219,22 @@ public:
|
|||||||
return waitResponse() == 1;
|
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
|
* Power functions
|
||||||
*/
|
*/
|
||||||
@@ -241,6 +275,10 @@ public:
|
|||||||
return res2;
|
return res2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isNetworkConnected() {
|
||||||
|
return true; // TODO
|
||||||
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
bool waitForNetwork(unsigned long timeout = 60000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
sendAT(GF("+CIPSTATUS"));
|
sendAT(GF("+CIPSTATUS"));
|
||||||
@@ -303,10 +341,14 @@ public:
|
|||||||
return TinyGsmIpFromString(getLocalIP());
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
|
||||||
int modemConnect(const char* host, uint16_t port, uint8_t mux) {
|
bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false) {
|
||||||
sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port, GF(","), TINY_GSM_TCP_KEEP_ALIVE);
|
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,
|
int rsp = waitResponse(75000L,
|
||||||
GFP(GSM_OK),
|
GFP(GSM_OK),
|
||||||
GFP(GSM_ERROR),
|
GFP(GSM_ERROR),
|
||||||
@@ -450,7 +492,7 @@ finish:
|
|||||||
return waitResponse(1000, r1, r2, r3, r4, r5);
|
return waitResponse(1000, r1, r2, r3, r4, r5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
GsmClient* sockets[TINY_GSM_MUX_COUNT];
|
GsmClient* sockets[TINY_GSM_MUX_COUNT];
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user