|
@ -42,11 +42,6 @@ enum RegStatus { |
|
|
class TinyGsm |
|
|
class TinyGsm |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
public: |
|
|
|
|
|
TinyGsm(Stream& stream) |
|
|
|
|
|
: stream(stream) |
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
class GsmClient : public Client |
|
|
class GsmClient : public Client |
|
@ -110,7 +105,7 @@ public: |
|
|
|
|
|
|
|
|
virtual int available() { |
|
|
virtual int available() { |
|
|
TINY_GSM_YIELD(); |
|
|
TINY_GSM_YIELD(); |
|
|
if (!rx.size()) { |
|
|
|
|
|
|
|
|
if (!rx.size() && sock_connected) { |
|
|
at->maintain(); |
|
|
at->maintain(); |
|
|
} |
|
|
} |
|
|
return rx.size(); |
|
|
return rx.size(); |
|
@ -163,6 +158,12 @@ private: |
|
|
|
|
|
|
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
TinyGsm(Stream& stream) |
|
|
|
|
|
: stream(stream) |
|
|
|
|
|
{ |
|
|
|
|
|
memset(sockets, 0, sizeof(sockets)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Basic functions |
|
|
* Basic functions |
|
|
*/ |
|
|
*/ |
|
@ -235,6 +236,8 @@ public: |
|
|
return init(); |
|
|
return init(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool poweroff() TINY_GSM_ATTR_NOT_IMPLEMENTED; |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* SIM card functions |
|
|
* SIM card functions |
|
|
*/ |
|
|
*/ |
|
@ -307,9 +310,9 @@ public: |
|
|
return res; |
|
|
return res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* Generic network functions |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* Generic network functions |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
int getSignalQuality() { |
|
|
int getSignalQuality() { |
|
|
sendAT(GF("+CSQ")); |
|
|
sendAT(GF("+CSQ")); |
|
@ -357,13 +360,15 @@ public: |
|
|
sendAT(GF("+XIIC?")); |
|
|
sendAT(GF("+XIIC?")); |
|
|
waitResponse(); |
|
|
waitResponse(); |
|
|
|
|
|
|
|
|
/*sendAT(GF("+DNSSERVER=1,8.8.8.8")); |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
sendAT(GF("+DNSSERVER=1,8.8.8.8")); |
|
|
waitResponse(); |
|
|
waitResponse(); |
|
|
|
|
|
|
|
|
sendAT(GF("+DNSSERVER=2,8.8.4.4")); |
|
|
sendAT(GF("+DNSSERVER=2,8.8.4.4")); |
|
|
if (waitResponse() != 1) { |
|
|
if (waitResponse() != 1) { |
|
|
return false; |
|
|
return false; |
|
|
}*/ |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
@ -377,6 +382,8 @@ public: |
|
|
* Phone Call functions |
|
|
* Phone Call functions |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
bool setGsmBusy(bool busy = true) TINY_GSM_ATTR_NOT_AVAILABLE; |
|
|
|
|
|
|
|
|
bool callAnswer() { |
|
|
bool callAnswer() { |
|
|
sendAT(GF("A")); |
|
|
sendAT(GF("A")); |
|
|
return waitResponse() == 1; |
|
|
return waitResponse() == 1; |
|
@ -387,6 +394,8 @@ public: |
|
|
return waitResponse() == 1; |
|
|
return waitResponse() == 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void callRedial() TINY_GSM_ATTR_NOT_AVAILABLE; |
|
|
|
|
|
|
|
|
bool callHangup(const String& number) { |
|
|
bool callHangup(const String& number) { |
|
|
sendAT(GF("H"), number); |
|
|
sendAT(GF("H"), number); |
|
|
return waitResponse() == 1; |
|
|
return waitResponse() == 1; |
|
@ -396,9 +405,7 @@ public: |
|
|
* Messaging functions |
|
|
* Messaging functions |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
// TODO |
|
|
|
|
|
void sendUSSD() { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void sendUSSD() TINY_GSM_ATTR_NOT_IMPLEMENTED; |
|
|
|
|
|
|
|
|
bool sendSMS(const String& number, const String& text) { |
|
|
bool sendSMS(const String& number, const String& text) { |
|
|
sendAT(GF("+CSCS=\"gsm\"")); |
|
|
sendAT(GF("+CSCS=\"gsm\"")); |
|
@ -420,27 +427,16 @@ public: |
|
|
* Location functions |
|
|
* Location functions |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
void getGsmLocation() { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
String getGsmLocation() TINY_GSM_ATTR_NOT_AVAILABLE; |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Battery functions |
|
|
* Battery functions |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
String dnsIpQuery(const char* host) { |
|
|
|
|
|
sendAT(GF("+DNS=\""), host, GF("\"")); |
|
|
|
|
|
if (waitResponse(10000L, GF(GSM_NL "+DNS:")) != 1) { |
|
|
|
|
|
return ""; |
|
|
|
|
|
} |
|
|
|
|
|
String res = stream.readStringUntil('\n'); |
|
|
|
|
|
waitResponse(GF("+DNS:OK" GSM_NL)); |
|
|
|
|
|
res.trim(); |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int modemConnect(const char* host, uint16_t port, uint8_t mux) { |
|
|
int modemConnect(const char* host, uint16_t port, uint8_t mux) { |
|
|
for (int i=0; i<3; i++) { |
|
|
|
|
|
|
|
|
for (int i=0; i<3; i++) { // TODO: no need for loop? |
|
|
String ip = dnsIpQuery(host); |
|
|
String ip = dnsIpQuery(host); |
|
|
|
|
|
|
|
|
sendAT(GF("+TCPSETUP="), mux, GF(","), ip, GF(","), port); |
|
|
sendAT(GF("+TCPSETUP="), mux, GF(","), ip, GF(","), port); |
|
@ -481,7 +477,21 @@ private: |
|
|
return 1 == res; |
|
|
return 1 == res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String dnsIpQuery(const char* host) { |
|
|
|
|
|
sendAT(GF("+DNS=\""), host, GF("\"")); |
|
|
|
|
|
if (waitResponse(10000L, GF(GSM_NL "+DNS:")) != 1) { |
|
|
|
|
|
return ""; |
|
|
|
|
|
} |
|
|
|
|
|
String res = stream.readStringUntil('\n'); |
|
|
|
|
|
waitResponse(GF("+DNS:OK" GSM_NL)); |
|
|
|
|
|
res.trim(); |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
|
/* Utilities */ |
|
|
/* Utilities */ |
|
|
|
|
|
|
|
|
template<typename T> |
|
|
template<typename T> |
|
|
void streamWrite(T last) { |
|
|
void streamWrite(T last) { |
|
|
stream.print(last); |
|
|
stream.print(last); |
|
@ -493,8 +503,6 @@ private: |
|
|
streamWrite(tail...); |
|
|
streamWrite(tail...); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int streamRead() { return stream.read(); } |
|
|
|
|
|
|
|
|
|
|
|
bool streamSkipUntil(char c) { //TODO: timeout |
|
|
bool streamSkipUntil(char c) { //TODO: timeout |
|
|
while (true) { |
|
|
while (true) { |
|
|
while (!stream.available()) { TINY_GSM_YIELD(); } |
|
|
while (!stream.available()) { TINY_GSM_YIELD(); } |
|
@ -529,7 +537,7 @@ private: |
|
|
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 |
|
|
data += (char)a; |
|
|
data += (char)a; |
|
|
if (r1 && data.endsWith(r1)) { |
|
|
if (r1 && data.endsWith(r1)) { |
|
|