Clean up
This commit is contained in:
BIN
extras/doc/Quectel_M95_GSM_Specification_V3.1.pdf
Normal file
BIN
extras/doc/Quectel_M95_GSM_Specification_V3.1.pdf
Normal file
Binary file not shown.
BIN
extras/doc/Quectel_M95_at_commands_manual_v1.3.pdf
Normal file
BIN
extras/doc/Quectel_M95_at_commands_manual_v1.3.pdf
Normal file
Binary file not shown.
@@ -48,20 +48,20 @@
|
|||||||
#define TINY_GSM_MODEM_HAS_GPRS
|
#define TINY_GSM_MODEM_HAS_GPRS
|
||||||
#include <TinyGsmClientA6.h>
|
#include <TinyGsmClientA6.h>
|
||||||
typedef TinyGsmA6 TinyGsm;
|
typedef TinyGsmA6 TinyGsm;
|
||||||
typedef TinyGsm::GsmClient TinyGsmClient;
|
typedef TinyGsmA6::GsmClient TinyGsmClient;
|
||||||
|
|
||||||
#elif defined(TINY_GSM_MODEM_M590)
|
#elif defined(TINY_GSM_MODEM_M590)
|
||||||
#define TINY_GSM_MODEM_HAS_GPRS
|
#define TINY_GSM_MODEM_HAS_GPRS
|
||||||
#include <TinyGsmClientM590.h>
|
#include <TinyGsmClientM590.h>
|
||||||
typedef TinyGsmM590 TinyGsm;
|
typedef TinyGsmM590 TinyGsm;
|
||||||
typedef TinyGsm::GsmClient TinyGsmClient;
|
typedef TinyGsmM590::GsmClient TinyGsmClient;
|
||||||
|
|
||||||
#elif defined(TINY_GSM_MODEM_ESP8266)
|
#elif defined(TINY_GSM_MODEM_ESP8266)
|
||||||
#define TINY_GSM_MODEM_HAS_WIFI
|
#define TINY_GSM_MODEM_HAS_WIFI
|
||||||
#include <TinyGsmClientESP8266.h>
|
#include <TinyGsmClientESP8266.h>
|
||||||
typedef TinyGsmESP8266 TinyGsm;
|
typedef TinyGsmESP8266 TinyGsm;
|
||||||
typedef TinyGsm::GsmClient TinyGsmClient;
|
typedef TinyGsmESP8266::GsmClient TinyGsmClient;
|
||||||
typedef TinyGsm::GsmClientSecure TinyGsmClientSecure;
|
typedef TinyGsmESP8266::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
|
||||||
@@ -74,7 +74,8 @@
|
|||||||
#elif defined(TINY_GSM_MODEM_M95)
|
#elif defined(TINY_GSM_MODEM_M95)
|
||||||
#define TINY_GSM_MODEM_HAS_GPRS
|
#define TINY_GSM_MODEM_HAS_GPRS
|
||||||
#include <TinyGsmClientM95.h>
|
#include <TinyGsmClientM95.h>
|
||||||
typedef TinyGsm::GsmClient TinyGsmClient;
|
typedef TinyGsmM95 TinyGsm;
|
||||||
|
typedef TinyGsmM95::GsmClient TinyGsmClient;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error "Please define GSM modem model"
|
#error "Please define GSM modem model"
|
||||||
|
|||||||
@@ -38,21 +38,15 @@ enum RegStatus {
|
|||||||
REG_UNKNOWN = 4,
|
REG_UNKNOWN = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
// Declaration of the TinyGsmA6 Class
|
// Declaration of the TinyGsmA6 Class
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TinyGsmA6
|
class TinyGsmA6
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
// The A6 Client Class
|
// The A6 Client Class
|
||||||
@@ -60,6 +54,8 @@ public:
|
|||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
class GsmClient : public Client
|
class GsmClient : public Client
|
||||||
{
|
{
|
||||||
friend class TinyGsmA6;
|
friend class TinyGsmA6;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
#define TINY_GSM_RX_BUFFER 64
|
#define TINY_GSM_RX_BUFFER 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TINY_GSM_MUX_COUNT 5
|
#define TINY_GSM_MUX_COUNT 12
|
||||||
|
|
||||||
#include <TinyGsmCommon.h>
|
#include <TinyGsmCommon.h>
|
||||||
|
|
||||||
@@ -39,10 +39,22 @@ enum RegStatus {
|
|||||||
REG_UNKNOWN = 4,
|
REG_UNKNOWN = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// Declaration of the TinyGsmBG96 Class
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
class TinyGsmBG96
|
class TinyGsmBG96
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The BG96 Client Class
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
class GsmClient : public Client
|
class GsmClient : public Client
|
||||||
@@ -173,6 +185,13 @@ private:
|
|||||||
RxFifo rx;
|
RxFifo rx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The BG96 Secure Client
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
|
|
||||||
class GsmClientSecure : public GsmClient
|
class GsmClientSecure : public GsmClient
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -192,9 +211,19 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The BG96 Modem Functions
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
#ifdef GSM_DEFAULT_STREAM
|
||||||
|
TinyGsmBG96(Stream& stream = GSM_DEFAULT_STREAM)
|
||||||
|
#else
|
||||||
TinyGsmBG96(Stream& stream)
|
TinyGsmBG96(Stream& stream)
|
||||||
|
#endif
|
||||||
: stream(stream)
|
: stream(stream)
|
||||||
{
|
{
|
||||||
memset(sockets, 0, sizeof(sockets));
|
memset(sockets, 0, sizeof(sockets));
|
||||||
@@ -353,17 +382,6 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
|
||||||
sendAT(GF("+CREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
String getOperator() {
|
||||||
sendAT(GF("+COPS?"));
|
sendAT(GF("+COPS?"));
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
||||||
@@ -379,6 +397,17 @@ public:
|
|||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
RegStatus getRegistrationStatus() {
|
||||||
|
sendAT(GF("+CREG?"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
|
||||||
|
return REG_UNKNOWN;
|
||||||
|
}
|
||||||
|
streamSkipUntil(','); // Skip format (0)
|
||||||
|
int status = stream.readStringUntil('\n').toInt();
|
||||||
|
waitResponse();
|
||||||
|
return (RegStatus)status;
|
||||||
|
}
|
||||||
|
|
||||||
int getSignalQuality() {
|
int getSignalQuality() {
|
||||||
sendAT(GF("+CSQ"));
|
sendAT(GF("+CSQ"));
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
||||||
@@ -404,6 +433,27 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getLocalIP() {
|
||||||
|
sendAT(GF("+CGPADDR=1"));
|
||||||
|
if (waitResponse(10000L, GF(GSM_NL "+CGPADDR:")) != 1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
streamSkipUntil(',');
|
||||||
|
String res = stream.readStringUntil('\n');
|
||||||
|
if (waitResponse() != 1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPAddress localIP() {
|
||||||
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WiFi functions
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
*/
|
*/
|
||||||
@@ -450,53 +500,6 @@ public:
|
|||||||
return localIP() != 0;
|
return localIP() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLocalIP() {
|
|
||||||
sendAT(GF("+CGPADDR=1"));
|
|
||||||
if (waitResponse(10000L, GF(GSM_NL "+CGPADDR:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
streamSkipUntil(',');
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
if (waitResponse() != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPAddress localIP() {
|
|
||||||
return TinyGsmIpFromString(getLocalIP());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Phone Call functions
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool setGsmBusy(bool busy = true) TINY_GSM_ATTR_NOT_AVAILABLE;
|
|
||||||
|
|
||||||
bool callAnswer() {
|
|
||||||
sendAT(GF("A"));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true on pick-up, false on error/busy
|
|
||||||
bool callNumber(const String& number) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
|
||||||
|
|
||||||
bool callHangup() {
|
|
||||||
sendAT(GF("H"));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 0-9,*,#,A,B,C,D
|
|
||||||
bool dtmfSend(char cmd, int duration_ms = 100) { // TODO: check
|
|
||||||
duration_ms = constrain(duration_ms, 100, 1000);
|
|
||||||
|
|
||||||
sendAT(GF("+VTD="), duration_ms / 100); // VTD accepts in 1/10 of a second
|
|
||||||
waitResponse();
|
|
||||||
|
|
||||||
sendAT(GF("+VTS="), cmd);
|
|
||||||
return waitResponse(10000L) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Messaging functions
|
* Messaging functions
|
||||||
*/
|
*/
|
||||||
@@ -660,9 +663,13 @@ public:
|
|||||||
streamWrite(tail...);
|
streamWrite(tail...);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool streamSkipUntil(char c) { //TODO: timeout
|
bool streamSkipUntil(char c) {
|
||||||
while (true) {
|
const unsigned long timeout = 1000L;
|
||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
unsigned long startMillis = millis();
|
||||||
|
while (millis() - startMillis < timeout) {
|
||||||
|
while (millis() - startMillis < timeout && !stream.available()) {
|
||||||
|
TINY_GSM_YIELD();
|
||||||
|
}
|
||||||
if (stream.read() == c)
|
if (stream.read() == c)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -674,7 +681,7 @@ public:
|
|||||||
streamWrite("AT", cmd..., GSM_NL);
|
streamWrite("AT", cmd..., GSM_NL);
|
||||||
stream.flush();
|
stream.flush();
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
//DBG("### AT:", cmd...);
|
DBG("### AT:", cmd...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
@@ -682,12 +689,12 @@ public:
|
|||||||
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
||||||
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
||||||
{
|
{
|
||||||
/*String r1s(r1); r1s.trim();
|
String r1s(r1); r1s.trim();
|
||||||
String r2s(r2); r2s.trim();
|
String r2s(r2); r2s.trim();
|
||||||
String r3s(r3); r3s.trim();
|
String r3s(r3); r3s.trim();
|
||||||
String r4s(r4); r4s.trim();
|
String r4s(r4); r4s.trim();
|
||||||
String r5s(r5); r5s.trim();
|
String r5s(r5); r5s.trim();
|
||||||
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
|
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);
|
||||||
data.reserve(64);
|
data.reserve(64);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
@@ -743,6 +750,7 @@ finish:
|
|||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
}
|
}
|
||||||
|
DBG('<', index, '>');
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -313,7 +313,6 @@ public:
|
|||||||
|
|
||||||
bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class TinyGsmM590
|
|||||||
//============================================================================//
|
//============================================================================//
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
class GsmClient : public Client
|
class GsmClient : public Client
|
||||||
|
|||||||
@@ -9,13 +9,15 @@
|
|||||||
#ifndef TinyGsmClientM95_h
|
#ifndef TinyGsmClientM95_h
|
||||||
#define TinyGsmClientM95_h
|
#define TinyGsmClientM95_h
|
||||||
|
|
||||||
#define TINY_GSM_DEBUG Serial
|
// #define TINY_GSM_DEBUG Serial
|
||||||
#define TINY_GSM_USE_HEX
|
// #define TINY_GSM_USE_HEX
|
||||||
|
|
||||||
#if !defined(TINY_GSM_RX_BUFFER)
|
#if !defined(TINY_GSM_RX_BUFFER)
|
||||||
#define TINY_GSM_RX_BUFFER 64
|
#define TINY_GSM_RX_BUFFER 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TINY_GSM_MUX_COUNT 6
|
||||||
|
|
||||||
#include <TinyGsmCommon.h>
|
#include <TinyGsmCommon.h>
|
||||||
|
|
||||||
#define GSM_NL "\r\n"
|
#define GSM_NL "\r\n"
|
||||||
@@ -37,35 +39,51 @@ enum RegStatus {
|
|||||||
REG_UNKNOWN = 4,
|
REG_UNKNOWN = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// Declaration of the TinyGsmM95 Class
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
|
class TinyGsmM95
|
||||||
|
{
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The M95 Client Class
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
class TinyGsm {
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TinyGsm(Stream& stream) : stream(stream) {}
|
|
||||||
|
|
||||||
class GsmClient : public Client {
|
class GsmClient : public Client
|
||||||
friend class TinyGsm;
|
{
|
||||||
|
friend class TinyGsmM95;
|
||||||
typedef TinyGsmFifo<uint8_t, TINY_GSM_RX_BUFFER> RxFifo;
|
typedef TinyGsmFifo<uint8_t, TINY_GSM_RX_BUFFER> RxFifo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GsmClient() {}
|
GsmClient() {}
|
||||||
|
|
||||||
GsmClient(TinyGsm& modem, uint8_t mux = 1) {
|
GsmClient(TinyGsmM95& modem, uint8_t mux = 1) {
|
||||||
init(&modem, mux);
|
init(&modem, mux);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init(TinyGsm* modem, uint8_t mux = 1) {
|
bool init(TinyGsmM95* modem, uint8_t mux = 1) {
|
||||||
this->at = modem;
|
this->at = modem;
|
||||||
this->mux = mux;
|
this->mux = mux;
|
||||||
sock_available = 0;
|
sock_available = 0;
|
||||||
sock_connected = false;
|
sock_connected = false;
|
||||||
|
got_data = false;
|
||||||
|
|
||||||
at->sockets[mux] = this;
|
at->sockets[mux] = this;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
virtual int connect(const char *host, uint16_t port) {
|
virtual int connect(const char *host, uint16_t port) {
|
||||||
|
stop();
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
rx.clear();
|
rx.clear();
|
||||||
sock_connected = at->modemConnect(host, port, mux);
|
sock_connected = at->modemConnect(host, port, mux);
|
||||||
@@ -86,9 +104,10 @@ public:
|
|||||||
|
|
||||||
virtual void stop() {
|
virtual void stop() {
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
at->sendAT(GF("+QICLOSE"));
|
at->sendAT(GF("+QICLOSE="), mux);
|
||||||
sock_connected = false;
|
sock_connected = false;
|
||||||
at->waitResponse(60000L, GF("CLOSED"), GF("CLOSE OK"), GF("ERROR"));
|
at->waitResponse(60000L, GF("CLOSED"), GF("CLOSE OK"), GF("ERROR"));
|
||||||
|
rx.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(const uint8_t *buf, size_t size) {
|
virtual size_t write(const uint8_t *buf, size_t size) {
|
||||||
@@ -151,21 +170,55 @@ public:
|
|||||||
}
|
}
|
||||||
virtual operator bool() { return connected(); }
|
virtual operator bool() { return connected(); }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Extended API
|
||||||
|
*/
|
||||||
|
|
||||||
|
String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TinyGsm* at;
|
TinyGsmM95* at;
|
||||||
uint8_t mux;
|
uint8_t mux;
|
||||||
uint16_t sock_available;
|
uint16_t sock_available;
|
||||||
bool sock_connected;
|
bool sock_connected;
|
||||||
|
bool got_data;
|
||||||
RxFifo rx;
|
RxFifo rx;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Basic functions
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The M95 Has No Secure Client
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
// The M95 Modem Functions
|
||||||
|
//============================================================================//
|
||||||
|
//============================================================================//
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
#ifdef GSM_DEFAULT_STREAM
|
||||||
|
TinyGsmM95(Stream& stream = GSM_DEFAULT_STREAM)
|
||||||
|
#else
|
||||||
|
TinyGsmM95(Stream& stream)
|
||||||
|
#endif
|
||||||
|
: stream(stream)
|
||||||
|
{
|
||||||
|
memset(sockets, 0, sizeof(sockets));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Basic functions
|
||||||
|
*/
|
||||||
bool begin() {
|
bool begin() {
|
||||||
return init();
|
return init();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init() {
|
bool init() {
|
||||||
if (!autoBaud()) {
|
if (!testAT()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sendAT(GF("&FZE0")); // Factory + Reset + Echo Off
|
sendAT(GF("&FZE0")); // Factory + Reset + Echo Off
|
||||||
@@ -176,7 +229,11 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool autoBaud(unsigned long timeout = 10000L) {
|
void setBaud(unsigned long baud) {
|
||||||
|
sendAT(GF("+IPR="), baud);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool testAT(unsigned long timeout = 10000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
sendAT(GF(""));
|
sendAT(GF(""));
|
||||||
if (waitResponse(200) == 1) {
|
if (waitResponse(200) == 1) {
|
||||||
@@ -189,6 +246,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void maintain() {
|
void maintain() {
|
||||||
|
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
||||||
|
GsmClient* sock = sockets[mux];
|
||||||
|
if (sock && sock->got_data) {
|
||||||
|
sock->got_data = false;
|
||||||
|
sock->sock_available = modemGetAvailable(mux);
|
||||||
|
}
|
||||||
|
}
|
||||||
while (stream.available()) {
|
while (stream.available()) {
|
||||||
waitResponse(10, NULL, NULL);
|
waitResponse(10, NULL, NULL);
|
||||||
}
|
}
|
||||||
@@ -209,10 +273,28 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Power functions
|
String getModemInfo() {
|
||||||
|
sendAT(GF("I"));
|
||||||
|
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 false; // TODO: For now
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Power functions
|
||||||
|
*/
|
||||||
|
|
||||||
bool restart() {
|
bool restart() {
|
||||||
if (!autoBaud()) {
|
if (!testAT()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sendAT(GF("+CFUN=0"));
|
sendAT(GF("+CFUN=0"));
|
||||||
@@ -226,7 +308,23 @@ public:
|
|||||||
return init();
|
return init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SIM card & Networ Operator functions
|
bool poweroff() {
|
||||||
|
sendAT(GF("+QPOWD"));
|
||||||
|
return waitResponse(GF("POWERED DOWN")) == 1; // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
bool radioOff() {
|
||||||
|
sendAT(GF("+CFUN=0"));
|
||||||
|
if (waitResponse(10000L) != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
delay(3000);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SIM card functions
|
||||||
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
bool simUnlock(const char *pin) {
|
||||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
||||||
@@ -255,27 +353,6 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSignalQuality() {
|
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getClock() {
|
|
||||||
sendAT(GF("+QLTS"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+QLTS:")) != 1) {
|
|
||||||
// Serial.println( F("No response from AT+QLTS") );
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
sendAT(GF("+CPIN?"));
|
sendAT(GF("+CPIN?"));
|
||||||
@@ -295,17 +372,6 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
|
||||||
sendAT(GF("+CREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
String getOperator() {
|
||||||
sendAT(GF("+COPS?"));
|
sendAT(GF("+COPS?"));
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
||||||
@@ -317,15 +383,42 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic network functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
RegStatus getRegistrationStatus() {
|
||||||
|
sendAT(GF("+CREG?"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
|
||||||
|
return REG_UNKNOWN;
|
||||||
|
}
|
||||||
|
streamSkipUntil(','); // Skip format (0)
|
||||||
|
int status = stream.readStringUntil('\n').toInt();
|
||||||
|
waitResponse();
|
||||||
|
return (RegStatus)status;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getSignalQuality() {
|
||||||
|
sendAT(GF("+CSQ"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
||||||
|
return 99;
|
||||||
|
}
|
||||||
|
int res = stream.readStringUntil(',').toInt();
|
||||||
|
waitResponse();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isNetworkConnected() {
|
||||||
|
RegStatus s = getRegistrationStatus();
|
||||||
|
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||||
|
}
|
||||||
|
|
||||||
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; ) {
|
||||||
RegStatus s = getRegistrationStatus();
|
if (isNetworkConnected()) {
|
||||||
if (s == REG_OK_HOME || s == REG_OK_ROAMING) {
|
|
||||||
return true;
|
return true;
|
||||||
} else if (s == REG_UNREGISTERED) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
delay(1000);
|
delay(250);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -339,18 +432,47 @@ public:
|
|||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// GPRS functions
|
String getLocalIP() {
|
||||||
bool gprsConnect(const char* apn, const char* user, const char* pwd) {
|
sendAT(GF("+CGPADDR=1"));
|
||||||
|
if (waitResponse(10000L, GF(GSM_NL "+CGPADDR:")) != 1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
streamSkipUntil(',');
|
||||||
|
String res = stream.readStringUntil('\n');
|
||||||
|
if (waitResponse() != 1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPAddress localIP() {
|
||||||
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WiFi functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GPRS functions
|
||||||
|
*/
|
||||||
|
bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) {
|
||||||
gprsDisconnect();
|
gprsDisconnect();
|
||||||
|
|
||||||
sendAT(GF("+QIFGCNT=0"));
|
sendAT(GF("+QIFGCNT=0")); // Set the forground context
|
||||||
waitResponse();
|
if (waitResponse() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
sendAT(GF("+QICSGP=1,\""), apn, GF("\",\""), user, GF("\",\""), pwd, GF("\""));
|
sendAT(GF("+QICSGP=1,\""), apn, GF("\",\""), user, GF("\",\""), pwd, GF("\""));
|
||||||
waitResponse();
|
if (waitResponse() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
sendAT(GF("+QIREGAPP"));
|
sendAT(GF("+QIREGAPP"));
|
||||||
waitResponse();
|
if (waitResponse() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
sendAT(GF("+QIACT"));
|
sendAT(GF("+QIACT"));
|
||||||
waitResponse(10000L);
|
waitResponse(10000L);
|
||||||
@@ -363,29 +485,24 @@ public:
|
|||||||
return waitResponse(60000L, GF("DEACT OK"), GF("ERROR")) == 1;
|
return waitResponse(60000L, GF("DEACT OK"), GF("ERROR")) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Phone Call functions
|
bool isGprsConnected() {
|
||||||
|
sendAT(GF("+CGATT?"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+CGATT:")) != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int res = stream.readStringUntil('\n').toInt();
|
||||||
|
waitResponse();
|
||||||
|
if (res != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
bool setGsmBusy(bool busy = true) {
|
return localIP() != 0;
|
||||||
sendAT(GF("+GSMBUSY="), busy ? 1 : 0);
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool callAnswer() {
|
/*
|
||||||
sendAT(GF("A"));
|
* Messaging functions
|
||||||
return waitResponse() == 1;
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
bool callNumber(const String& number) {
|
String sendUSSD(const String& code) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
sendAT(GF("D"), number);
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool callHangup(const String& number) {
|
|
||||||
sendAT(GF("H"), number);
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Messaging functions
|
|
||||||
|
|
||||||
bool sendSMS(const String& number, const String& text) {
|
bool sendSMS(const String& number, const String& text) {
|
||||||
sendAT(GF("+CMGF=1"));
|
sendAT(GF("+CMGF=1"));
|
||||||
@@ -396,6 +513,7 @@ public:
|
|||||||
}
|
}
|
||||||
stream.print(text);
|
stream.print(text);
|
||||||
stream.write((char)0x1A);
|
stream.write((char)0x1A);
|
||||||
|
stream.flush();
|
||||||
return waitResponse(60000L) == 1;
|
return waitResponse(60000L) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,6 +540,7 @@ public:
|
|||||||
stream.print(c, HEX);
|
stream.print(c, HEX);
|
||||||
}
|
}
|
||||||
stream.write((char)0x1A);
|
stream.write((char)0x1A);
|
||||||
|
stream.flush();
|
||||||
return waitResponse(60000L) == 1;
|
return waitResponse(60000L) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,7 +557,10 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Location functions
|
|
||||||
|
/*
|
||||||
|
* Location functions
|
||||||
|
*/
|
||||||
void getLocation() {}
|
void getLocation() {}
|
||||||
|
|
||||||
String getGsmLocation() {
|
String getGsmLocation() {
|
||||||
@@ -452,37 +574,45 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Battery functions
|
/*
|
||||||
|
* Battery functions
|
||||||
|
*/
|
||||||
|
|
||||||
// HTTP functions
|
// Use: float vBatt = modem.getBattVoltage() / 1000.0;
|
||||||
void httpGet( const char *url ) {
|
uint16_t getBattVoltage() {
|
||||||
int len = strlen( url );
|
sendAT(GF("+CBC"));
|
||||||
sendAT( GF("+QHTTPURL="), len);
|
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) {
|
||||||
delay( 500 );
|
return 0;
|
||||||
streamWrite(url, GSM_NL);
|
}
|
||||||
stream.flush();
|
streamSkipUntil(','); // Skip
|
||||||
waitResponse(5000L, GF("OK"));
|
streamSkipUntil(','); // Skip
|
||||||
|
|
||||||
sendAT( GF("+QHTTPGET"));
|
uint16_t res = stream.readStringUntil(',').toInt();
|
||||||
waitResponse(30000L);
|
waitResponse();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
String data;
|
int getBattPercent() {
|
||||||
sendAT( GF("+QHTTPREAD"));
|
sendAT(GF("+CBC"));
|
||||||
waitResponse(30000L, data);
|
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
stream.readStringUntil(',');
|
||||||
|
int res = stream.readStringUntil(',').toInt();
|
||||||
|
waitResponse();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Stream& stream;
|
|
||||||
GsmClient* sockets[5];
|
|
||||||
|
|
||||||
int modemConnect(const char* host, uint16_t port, uint8_t mux) {
|
bool modemConnect(const char* host, uint16_t port, uint8_t mux) {
|
||||||
sendAT(GF("+QIOPEN="), GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
sendAT(GF("+QIOPEN="), GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
||||||
int rsp = waitResponse(75000L,
|
int rsp = waitResponse(75000L,
|
||||||
GF("CONNECT OK" GSM_NL),
|
GF("CONNECT OK" GSM_NL),
|
||||||
GF("CONNECT FAIL" GSM_NL),
|
GF("CONNECT FAIL" GSM_NL),
|
||||||
GF("ALREADY CONNECT" GSM_NL));
|
GF("ALREADY CONNECT" GSM_NL));
|
||||||
if ( rsp != 1 ) {
|
if ( rsp != 1 ) {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
return (1 == rsp);
|
return (1 == rsp);
|
||||||
}
|
}
|
||||||
@@ -491,13 +621,14 @@ protected:
|
|||||||
sendAT(GF("+QIHEAD=1"));
|
sendAT(GF("+QIHEAD=1"));
|
||||||
waitResponse(5000L);
|
waitResponse(5000L);
|
||||||
|
|
||||||
sendAT(GF("+QISEND="),len);
|
sendAT(GF("+QISEND="), mux, ',', len);
|
||||||
if (waitResponse(GF(">")) != 1) {
|
if (waitResponse(GF(">")) != 1) {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
stream.write((uint8_t*)buff, len);
|
stream.write((uint8_t*)buff, len);
|
||||||
|
stream.flush();
|
||||||
if (waitResponse(GF(GSM_NL "SEND OK")) != 1) {
|
if (waitResponse(GF(GSM_NL "SEND OK")) != 1) {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool allAcknowledged = false;
|
bool allAcknowledged = false;
|
||||||
@@ -522,46 +653,30 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
#ifdef TINY_GSM_USE_HEX
|
sendAT(GF("+QIRD="), mux, ',', size);
|
||||||
sendAT(GF("+CIPRXGET=3,"), mux, ',', size);
|
if (waitResponse(GF("+QIRD:")) != 1) {
|
||||||
if (waitResponse(GF("+CIPRXGET:")) != 1) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
size_t len = stream.readStringUntil('\n').toInt();
|
||||||
sendAT(GF("+CIPRXGET=2,"), mux, ',', size);
|
|
||||||
if (waitResponse(GF("+CIPRXGET:")) != 1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
streamSkipUntil(','); // Skip mode 2/3
|
|
||||||
streamSkipUntil(','); // Skip mux
|
|
||||||
size_t len = stream.readStringUntil(',').toInt();
|
|
||||||
sockets[mux]->sock_available = stream.readStringUntil('\n').toInt();
|
|
||||||
|
|
||||||
for (size_t i=0; i<len; i++) {
|
for (size_t i=0; i<len; i++) {
|
||||||
#ifdef TINY_GSM_USE_HEX
|
while (!stream.available()) { TINY_GSM_YIELD(); }
|
||||||
while (stream.available() < 2) {}
|
|
||||||
char buf[4] = { 0, };
|
|
||||||
buf[0] = stream.read();
|
|
||||||
buf[1] = stream.read();
|
|
||||||
char c = strtol(buf, NULL, 16);
|
|
||||||
#else
|
|
||||||
while (!stream.available()) {}
|
|
||||||
char c = stream.read();
|
char c = stream.read();
|
||||||
#endif
|
|
||||||
sockets[mux]->rx.put(c);
|
sockets[mux]->rx.put(c);
|
||||||
}
|
}
|
||||||
waitResponse();
|
waitResponse();
|
||||||
|
DBG("### READ:", mux, ",", len);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
sendAT(GF("+CIPRXGET=4,"), mux);
|
sendAT(GF("+QIRD="), mux, GF(",0"));
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
if (waitResponse(GF("+CIPRXGET:")) == 1) {
|
if (waitResponse(GF("+QIRD:")) == 1) {
|
||||||
streamSkipUntil(','); // Skip mode 4
|
streamSkipUntil(','); // Skip total received
|
||||||
streamSkipUntil(','); // Skip mux
|
streamSkipUntil(','); // Skip have read
|
||||||
result = stream.readStringUntil('\n').toInt();
|
result = stream.readStringUntil('\n').toInt();
|
||||||
|
DBG("### STILL:", mux, "has", result);
|
||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
@@ -571,13 +686,29 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool modemGetConnected(uint8_t mux) {
|
bool modemGetConnected(uint8_t mux) {
|
||||||
sendAT(GF("+CIPSTATUS="), mux);
|
sendAT(GF("+QISTATE=1,"), mux);
|
||||||
int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), GF(",\"CLOSING\""), GF(",\"INITIAL\""));
|
//+QISTATE: 0,"TCP","151.139.237.11",80,5087,4,1,0,0,"uart1"
|
||||||
|
|
||||||
|
if (waitResponse(GF("+QISTATE:")))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
streamSkipUntil(','); // Skip mux
|
||||||
|
streamSkipUntil(','); // Skip socket type
|
||||||
|
streamSkipUntil(','); // Skip remote ip
|
||||||
|
streamSkipUntil(','); // Skip remote port
|
||||||
|
streamSkipUntil(','); // Skip local port
|
||||||
|
int res = stream.readStringUntil(',').toInt(); // socket state
|
||||||
|
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return 1 == res;
|
|
||||||
|
// 0 Initial, 1 Opening, 2 Connected, 3 Listening, 4 Closing
|
||||||
|
return 2 == res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utilities
|
public:
|
||||||
|
|
||||||
|
/* Utilities */
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void streamWrite(T last) {
|
void streamWrite(T last) {
|
||||||
stream.print(last);
|
stream.print(last);
|
||||||
@@ -589,23 +720,16 @@ protected:
|
|||||||
streamWrite(tail...);
|
streamWrite(tail...);
|
||||||
}
|
}
|
||||||
|
|
||||||
int streamRead() { return stream.read(); }
|
bool streamSkipUntil(char c) {
|
||||||
|
const unsigned long timeout = 1000L;
|
||||||
bool streamSkipUntil(char c, int timeoutInMs=1000) {
|
unsigned long startMillis = millis();
|
||||||
unsigned long startTime = millis();
|
while (millis() - startMillis < timeout) {
|
||||||
unsigned long t = millis();
|
while (millis() - startMillis < timeout && !stream.available()) {
|
||||||
while ( t < (startTime + timeoutInMs) ) {
|
TINY_GSM_YIELD();
|
||||||
while (!stream.available() && (t < (startTime + timeoutInMs)) ) {
|
|
||||||
t = millis();
|
|
||||||
delay( 250 );
|
|
||||||
}
|
}
|
||||||
if ( stream.available() ) {
|
if (stream.read() == c)
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
t = millis();
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,62 +744,58 @@ protected:
|
|||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
||||||
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) {
|
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
||||||
/* String r1s(r1); r1s.trim();
|
{
|
||||||
|
String r1s(r1); r1s.trim();
|
||||||
String r2s(r2); r2s.trim();
|
String r2s(r2); r2s.trim();
|
||||||
String r3s(r3); r3s.trim();
|
String r3s(r3); r3s.trim();
|
||||||
String r4s(r4); r4s.trim();
|
String r4s(r4); r4s.trim();
|
||||||
String r5s(r5); r5s.trim();
|
String r5s(r5); r5s.trim();
|
||||||
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s); */
|
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);
|
||||||
data.reserve(64);
|
data.reserve(64);
|
||||||
bool gotData = false;
|
|
||||||
int mux = -1;
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
do {
|
do {
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
while (stream.available() > 0) {
|
while (stream.available() > 0) {
|
||||||
int a = streamRead();
|
int a = stream.read();
|
||||||
if (a <= 0) continue; // Skip 0x00 bytes, just in case
|
if (a <= 0) continue; // Skip 0x00 bytes, just in case
|
||||||
Serial.print((char)a);
|
|
||||||
data += (char)a;
|
data += (char)a;
|
||||||
if (r1 && data.endsWith(r1)) {
|
if (r1 && data.endsWith(r1)) {
|
||||||
index = 1;
|
index = 1;
|
||||||
DBG("<<< Got1 '", String(r1), "'");
|
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (r2 && data.endsWith(r2)) {
|
} else if (r2 && data.endsWith(r2)) {
|
||||||
index = 2;
|
index = 2;
|
||||||
DBG("<<< Got2 '", String(r2), "'");
|
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (r3 && data.endsWith(r3)) {
|
} else if (r3 && data.endsWith(r3)) {
|
||||||
index = 3;
|
index = 3;
|
||||||
DBG("<<< Got3 '", String(r3), "'");
|
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (r4 && data.endsWith(r4)) {
|
} else if (r4 && data.endsWith(r4)) {
|
||||||
index = 4;
|
index = 4;
|
||||||
DBG("<<< Got4 '", String(r4), "'");
|
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (r5 && data.endsWith(r5)) {
|
} else if (r5 && data.endsWith(r5)) {
|
||||||
index = 5;
|
index = 5;
|
||||||
DBG("<<< Got5 '", String(r5), "'");
|
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
|
} else if (data.endsWith(GF(GSM_NL "+QIURC:"))) {
|
||||||
String mode = stream.readStringUntil(',');
|
stream.readStringUntil('\"');
|
||||||
if (mode.toInt() == 1) {
|
String urc = stream.readStringUntil('\"');
|
||||||
mux = stream.readStringUntil('\n').toInt();
|
stream.readStringUntil(',');
|
||||||
gotData = true;
|
if (urc == "recv") {
|
||||||
data = "";
|
int mux = stream.readStringUntil('\n').toInt();
|
||||||
} else {
|
DBG("### URC RECV:", mux);
|
||||||
data += mode;
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||||
|
sockets[mux]->got_data = true;
|
||||||
}
|
}
|
||||||
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
|
} else if (urc == "closed") {
|
||||||
int nl = data.lastIndexOf(GSM_NL, data.length()-8);
|
int mux = stream.readStringUntil('\n').toInt();
|
||||||
int coma = data.indexOf(',', nl+2);
|
DBG("### URC CLOSE:", mux);
|
||||||
mux = data.substring(nl+2, coma).toInt();
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||||
if (mux) {
|
|
||||||
sockets[mux]->sock_connected = false;
|
sockets[mux]->sock_connected = false;
|
||||||
data = "";
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
stream.readStringUntil('\n');
|
||||||
|
}
|
||||||
|
data = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (millis() - startMillis < timeout);
|
} while (millis() - startMillis < timeout);
|
||||||
@@ -687,71 +807,29 @@ protected:
|
|||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
}
|
}
|
||||||
if (gotData) {
|
DBG('<', index, '>');
|
||||||
sockets[mux]->sock_available = modemGetAvailable(mux);
|
|
||||||
}
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t waitResponse(uint32_t timeout,
|
uint8_t waitResponse(uint32_t timeout,
|
||||||
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
||||||
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) {
|
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
||||||
|
{
|
||||||
String data;
|
String data;
|
||||||
return waitResponse(timeout, data, r1, r2, r3, r4, r5);
|
return waitResponse(timeout, data, r1, r2, r3, r4, r5);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
||||||
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL) {
|
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
||||||
|
{
|
||||||
return waitResponse(1000, r1, r2, r3, r4, r5);
|
return waitResponse(1000, r1, r2, r3, r4, r5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printResponse(uint32_t timeout) {
|
public:
|
||||||
unsigned long startMillis = millis();
|
Stream& stream;
|
||||||
do {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
while (stream.available() > 0) {
|
|
||||||
int a = streamRead();
|
|
||||||
if (a <= 0) continue; // Skip 0x00 bytes, just in case
|
|
||||||
Serial.print((char)a);
|
|
||||||
}
|
|
||||||
} while (millis() - startMillis < timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t waitForHTTPResponse(uint32_t timeout, char * buffer, uint8_t bufferSize) {
|
protected:
|
||||||
unsigned long startMillis = millis();
|
GsmClient* sockets[TINY_GSM_MUX_COUNT];
|
||||||
uint8_t bufferIndex = 0;
|
|
||||||
uint16_t httpCode = 0;
|
|
||||||
do {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
while (stream.available() > 0) {
|
|
||||||
int a = streamRead();
|
|
||||||
if (a <= 0) continue; // Skip 0x00 bytes, just in case
|
|
||||||
Serial.print((char)a);
|
|
||||||
if (bufferIndex < bufferSize-1) { // leave room to null-terminate
|
|
||||||
buffer[bufferIndex] = (char)a;
|
|
||||||
bufferIndex++;
|
|
||||||
}
|
|
||||||
if ((char)a == '\n') {
|
|
||||||
// null-terminate buffer!
|
|
||||||
buffer[bufferIndex] = '\0';
|
|
||||||
if (strstr((const char *)buffer, "CLOSED") != NULL) {
|
|
||||||
return httpCode;
|
|
||||||
}
|
|
||||||
if(httpCode == 0 && strstr((const char *)buffer, "HTTP/1.") != NULL) {
|
|
||||||
strtok((char *)buffer, " "); /** Parse out HTTP/1.x */
|
|
||||||
|
|
||||||
char * codeString = strtok(NULL, " ");
|
|
||||||
httpCode = atoi((const char *)codeString);
|
|
||||||
}
|
|
||||||
bufferIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (millis() - startMillis < timeout);
|
|
||||||
|
|
||||||
return httpCode;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef TinyGsm::GsmClient TinyGsmClient;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ enum RegStatus {
|
|||||||
REG_UNKNOWN = 4,
|
REG_UNKNOWN = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
// Declaration of the TinyGsmU201 Class
|
// Declaration of the TinyGsmU201 Class
|
||||||
@@ -212,7 +211,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
// The U201 Modem Functions
|
// The U201 Modem Functions
|
||||||
@@ -521,19 +519,6 @@ public:
|
|||||||
|
|
||||||
return localIP() != 0;
|
return localIP() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Phone Call functions
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool setGsmBusy(bool busy = true) TINY_GSM_ATTR_NOT_AVAILABLE;
|
|
||||||
|
|
||||||
bool callAnswer() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
|
||||||
|
|
||||||
bool callNumber(const String& number) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
|
||||||
|
|
||||||
bool callHangup() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Messaging functions
|
* Messaging functions
|
||||||
*/
|
*/
|
||||||
@@ -721,7 +706,7 @@ public:
|
|||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
while (stream.available() > 0) {
|
while (stream.available() > 0) {
|
||||||
int a = stream.read();
|
int a = stream.read();
|
||||||
if (a < 0) continue;
|
if (a <= 0) continue; // Skip 0x00 bytes, just in case
|
||||||
data += (char)a;
|
data += (char)a;
|
||||||
if (r1 && data.endsWith(r1)) {
|
if (r1 && data.endsWith(r1)) {
|
||||||
index = 1;
|
index = 1;
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ enum XBeeType {
|
|||||||
XBEE3_LTENB = 3, // Digi XBee3™ Cellular NB-IoT -- HS unknown to SRGD
|
XBEE3_LTENB = 3, // Digi XBee3™ Cellular NB-IoT -- HS unknown to SRGD
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
//============================================================================//
|
//============================================================================//
|
||||||
// Declaration of the TinyGsmXBee Class
|
// Declaration of the TinyGsmXBee Class
|
||||||
@@ -665,8 +664,6 @@ fail:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
bool modemConnect(const char* host, uint16_t port, uint8_t mux = 0, bool ssl = false) {
|
bool modemConnect(const char* host, uint16_t port, uint8_t mux = 0, bool ssl = false) {
|
||||||
String strIP; strIP.reserve(16);
|
String strIP; strIP.reserve(16);
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
|
|||||||
Reference in New Issue
Block a user