From 39b563fc1f42822a1e0cfd9299e566733ba02f2a Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Tue, 17 Jan 2017 15:41:29 +0200 Subject: [PATCH] Fix #3, Fix #2 --- TinyGsmClientM590.h | 48 +++++++++++++++++++++++ TinyGsmClientSIM800.h | 91 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 138 insertions(+), 1 deletion(-) diff --git a/TinyGsmClientM590.h b/TinyGsmClientM590.h index 4fe438e..48afd51 100644 --- a/TinyGsmClientM590.h +++ b/TinyGsmClientM590.h @@ -253,6 +253,54 @@ public: return res; } + String getIMEI() { + sendAT(GF("+GSN")); + if (waitResponse(GF(GSM_NL)) != 1) { + return ""; + } + String res = stream.readStringUntil('\n'); + waitResponse(); + res.trim(); + return res; + } + + int getSignalQuality() { + sendAT(GF("+CSQ")); + if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) { + return 99; + } + int res = stream.readStringUntil(',').toInt(); + waitResponse(); + return res; + } + + bool callAnswer() { + sendAT(GF("A")); + return waitResponse() == 1; + } + + bool callNumber(const String& number) { + sendAT(GF("D"), number); + return waitResponse() == 1; + } + + bool callHangup(const String& number) { + sendAT(GF("H"), number); + return waitResponse() == 1; + } + + bool sendSMS(const String& number, const String& text) { + sendAT(GF("+CMGF=1")); + waitResponse(); + sendAT(GF("+CMGS=\""), number, GF("\"")); + if (waitResponse(GF(">")) != 1) { + return false; + } + stream.print(text); + stream.write((char)0x1A); + return waitResponse(60000L) == 1; + } + SimStatus getSimStatus(unsigned long timeout = 10000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { sendAT(GF("+CPIN?")); diff --git a/TinyGsmClientSIM800.h b/TinyGsmClientSIM800.h index d92697b..904041a 100644 --- a/TinyGsmClientSIM800.h +++ b/TinyGsmClientSIM800.h @@ -54,7 +54,6 @@ class GsmClient : public Client typedef TinyGsmFifo RxFifo; public: - GsmClient() {} GsmClient(TinyGsm& modem, uint8_t mux = 1) { @@ -260,6 +259,96 @@ public: return res; } + String getIMEI() { + sendAT(GF("+GSN")); + if (waitResponse(GF(GSM_NL)) != 1) { + return ""; + } + String res = stream.readStringUntil('\n'); + waitResponse(); + res.trim(); + 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 getGsmLocation() { + sendAT(GF("+CIPGSMLOC=1,1")); + if (waitResponse(GF(GSM_NL "+CIPGSMLOC:")) != 1) { + return ""; + } + String res = stream.readStringUntil('\n'); + waitResponse(); + res.trim(); + return res; + } + + bool setGsmBusy(bool busy = true) { + sendAT(GF("+GSMBUSY="), busy ? 1 : 0); + return waitResponse() == 1; + } + + bool callAnswer() { + sendAT(GF("A")); + return waitResponse() == 1; + } + + bool callNumber(const String& number) { + sendAT(GF("D"), number); + return waitResponse() == 1; + } + + bool callHangup(const String& number) { + sendAT(GF("H"), number); + return waitResponse() == 1; + } + + bool sendSMS(const String& number, const String& text) { + sendAT(GF("+CMGF=1")); + waitResponse(); + sendAT(GF("+CMGS=\""), number, GF("\"")); + if (waitResponse(GF(">")) != 1) { + return false; + } + stream.print(text); + stream.write((char)0x1A); + return waitResponse(60000L) == 1; + } + + bool sendSMS_UTF16(const String& number, const void* text, size_t len) { + sendAT(GF("+CMGF=1")); + waitResponse(); + sendAT(GF("+CSCS=\"HEX\"")); + 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> 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); + return waitResponse(60000L) == 1; + } + SimStatus getSimStatus(unsigned long timeout = 10000L) { for (unsigned long start = millis(); millis() - start < timeout; ) { sendAT(GF("+CPIN?"));