mirror of
https://github.com/KevinMidboe/TinyGSM.git
synced 2025-10-29 18:00:18 +00:00
Implement more functions
This commit is contained in:
@@ -61,7 +61,6 @@ public:
|
|||||||
this->at = modem;
|
this->at = modem;
|
||||||
this->mux = mux;
|
this->mux = mux;
|
||||||
sock_available = 0;
|
sock_available = 0;
|
||||||
prev_check = 0;
|
|
||||||
sock_connected = false;
|
sock_connected = false;
|
||||||
got_data = false;
|
got_data = false;
|
||||||
|
|
||||||
@@ -169,7 +168,6 @@ private:
|
|||||||
TinyGsmBG96* at;
|
TinyGsmBG96* at;
|
||||||
uint8_t mux;
|
uint8_t mux;
|
||||||
uint16_t sock_available;
|
uint16_t sock_available;
|
||||||
uint32_t prev_check;
|
|
||||||
bool sock_connected;
|
bool sock_connected;
|
||||||
bool got_data;
|
bool got_data;
|
||||||
RxFifo rx;
|
RxFifo rx;
|
||||||
@@ -283,12 +281,8 @@ public:
|
|||||||
if (!testAT()) {
|
if (!testAT()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sendAT(GF("+CFUN=0"));
|
|
||||||
if (waitResponse(10000L) != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
sendAT(GF("+CFUN=1,1"));
|
sendAT(GF("+CFUN=1,1"));
|
||||||
if (waitResponse(10000L) != 1) {
|
if (waitResponse(60000L, GF("POWERED DOWN")) != 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
delay(3000);
|
delay(3000);
|
||||||
@@ -297,7 +291,7 @@ public:
|
|||||||
|
|
||||||
bool poweroff() {
|
bool poweroff() {
|
||||||
sendAT(GF("+QPOWD"));
|
sendAT(GF("+QPOWD"));
|
||||||
return waitResponse(GF("NORMAL POWER DOWN")) == 1; // TODO
|
return waitResponse(GF("POWERED DOWN")) == 1; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
bool radioOff() {
|
bool radioOff() {
|
||||||
@@ -426,8 +420,6 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Wait for QIACT?
|
|
||||||
|
|
||||||
sendAT(GF("+CGATT=1"));
|
sendAT(GF("+CGATT=1"));
|
||||||
if (waitResponse(60000L) != 1) {
|
if (waitResponse(60000L) != 1) {
|
||||||
return false;
|
return false;
|
||||||
@@ -455,12 +447,21 @@ public:
|
|||||||
if (res != 1)
|
if (res != 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// TODO: use AT+CGPADDR
|
return localIP() != 0;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLocalIP() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
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() {
|
IPAddress localIP() {
|
||||||
return TinyGsmIpFromString(getLocalIP());
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
@@ -470,7 +471,7 @@ public:
|
|||||||
* Phone Call functions
|
* Phone Call functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool setGsmBusy(bool busy = true) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
bool setGsmBusy(bool busy = true) TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||||
|
|
||||||
bool callAnswer() {
|
bool callAnswer() {
|
||||||
sendAT(GF("A"));
|
sendAT(GF("A"));
|
||||||
@@ -486,7 +487,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 0-9,*,#,A,B,C,D
|
// 0-9,*,#,A,B,C,D
|
||||||
bool dtmfSend(char cmd, int duration_ms = 100) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
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
|
||||||
@@ -494,14 +503,53 @@ public:
|
|||||||
|
|
||||||
String sendUSSD(const String& code) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
String sendUSSD(const String& code) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
bool sendSMS(const String& number, const String& text) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
bool sendSMS(const String& number, const String& text) {
|
||||||
|
sendAT(GF("+CMGF=1"));
|
||||||
|
waitResponse();
|
||||||
|
//Set GSM 7 bit default alphabet (3GPP TS 23.038)
|
||||||
|
sendAT(GF("+CSCS=\"GSM\""));
|
||||||
|
waitResponse();
|
||||||
|
sendAT(GF("+CMGS=\""), number, GF("\""));
|
||||||
|
if (waitResponse(GF(">")) != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
stream.print(text);
|
||||||
|
stream.write((char)0x1A);
|
||||||
|
stream.flush();
|
||||||
|
return waitResponse(60000L) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
|
||||||
|
sendAT(GF("+CMGF=1"));
|
||||||
|
waitResponse();
|
||||||
|
sendAT(GF("+CSMP=17,167,0,8"));
|
||||||
|
waitResponse();
|
||||||
|
|
||||||
|
sendAT(GF("+CMGS=\""), number, GF("\""));
|
||||||
|
if (waitResponse(GF(">")) != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t* t = (uint16_t*)text;
|
||||||
|
for (size_t i=0; i<len; i++) {
|
||||||
|
uint8_t c = t[i] >> 8;
|
||||||
|
if (c < 0x10) { stream.print('0'); }
|
||||||
|
stream.print(c, HEX);
|
||||||
|
c = t[i] & 0xFF;
|
||||||
|
if (c < 0x10) { stream.print('0'); }
|
||||||
|
stream.print(c, HEX);
|
||||||
|
}
|
||||||
|
stream.write((char)0x1A);
|
||||||
|
stream.flush();
|
||||||
|
return waitResponse(60000L) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Location functions
|
* Location functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String getGsmLocation() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
String getGsmLocation() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Battery functions
|
* Battery functions
|
||||||
@@ -552,10 +600,8 @@ protected:
|
|||||||
size_t len = stream.readStringUntil('\n').toInt();
|
size_t len = stream.readStringUntil('\n').toInt();
|
||||||
|
|
||||||
for (size_t i=0; i<len; i++) {
|
for (size_t i=0; i<len; i++) {
|
||||||
|
|
||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
while (!stream.available()) { TINY_GSM_YIELD(); }
|
||||||
char c = stream.read();
|
char c = stream.read();
|
||||||
|
|
||||||
sockets[mux]->rx.put(c);
|
sockets[mux]->rx.put(c);
|
||||||
}
|
}
|
||||||
waitResponse();
|
waitResponse();
|
||||||
@@ -579,11 +625,24 @@ protected:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool modemGetConnected(uint8_t mux) { // TODO
|
bool modemGetConnected(uint8_t mux) {
|
||||||
//sendAT(GF("+QISTATUS="), 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"
|
||||||
//waitResponse();
|
|
||||||
return true;
|
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();
|
||||||
|
|
||||||
|
// 0 Initial, 1 Opening, 2 Connected, 3 Listening, 4 Closing
|
||||||
|
return 2 == res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user