From 7213e25d35ac490d168bf9e42cd546b5755d25cd Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Tue, 5 Sep 2017 16:45:28 +0300 Subject: [PATCH] Fix A6 <> Blynk operation --- TinyGsmClientA6.h | 61 ++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/TinyGsmClientA6.h b/TinyGsmClientA6.h index 53c4244..c15f2fd 100644 --- a/TinyGsmClientA6.h +++ b/TinyGsmClientA6.h @@ -42,11 +42,6 @@ enum RegStatus { class TinyGsm { -public: - TinyGsm(Stream& stream) - : stream(stream) - {} - public: class GsmClient : public Client @@ -166,6 +161,12 @@ private: public: + TinyGsm(Stream& stream) + : stream(stream) + { + memset(sockets, 0, sizeof(sockets)); + } + /* * Basic functions */ @@ -226,6 +227,11 @@ public: return init(); } + bool poweroff() { + sendAT(GF("+CPOF")); + return waitResponse() == 1; + } + /* * SIM card functions */ @@ -298,9 +304,9 @@ public: return res; } - /* - * Generic network functions - */ + /* + * Generic network functions + */ int getSignalQuality() { sendAT(GF("+CSQ")); @@ -351,12 +357,14 @@ public: return false; } - /*sendAT(GF("+CIFSR")); + /* + sendAT(GF("+CIFSR")); String data; if (waitResponse(10000L, data) != 1) { data.replace(GSM_NL, ""); return false; - }*/ + } + */ return true; } @@ -370,6 +378,8 @@ public: * Phone Call functions */ + bool setGsmBusy(bool busy = true) TINY_GSM_ATTR_NOT_AVAILABLE; + bool callAnswer() { sendAT(GF("A")); return waitResponse() == 1; @@ -380,6 +390,11 @@ public: return waitResponse() == 1; } + void callRedial() { + sendAT(GF("DLST")); + return waitResponse() == 1; + } + bool callHangup(const String& number) { sendAT(GF("H"), number); return waitResponse() == 1; @@ -389,9 +404,7 @@ public: * Messaging functions */ - // TODO - void sendUSSD() { - } + void sendUSSD() TINY_GSM_ATTR_NOT_IMPLEMENTED; bool sendSMS(const String& number, const String& text) { sendAT(GF("+CMGF=1")); @@ -411,8 +424,7 @@ public: * Location functions */ - void getGsmLocation() { - } + String getGsmLocation() TINY_GSM_ATTR_NOT_AVAILABLE; /* * Battery functions @@ -442,7 +454,7 @@ private: int modemSend(const void* buff, size_t len, uint8_t mux) { sendAT(GF("+CIPSEND="), mux, ',', len); - if (waitResponse(10000L, GF(GSM_NL ">")) != 1) { + if (waitResponse(2000L, GF(GSM_NL ">")) != 1) { return -1; } stream.write((uint8_t*)buff, len); @@ -460,7 +472,10 @@ private: return 1 == res; } +public: + /* Utilities */ + template void streamWrite(T last) { stream.print(last); @@ -472,8 +487,6 @@ private: streamWrite(tail...); } - int streamRead() { return stream.read(); } - bool streamSkipUntil(char c) { //TODO: timeout while (true) { while (!stream.available()) { TINY_GSM_YIELD(); } @@ -508,7 +521,7 @@ private: do { TINY_GSM_YIELD(); while (stream.available() > 0) { - int a = streamRead(); + int a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += (char)a; if (r1 && data.endsWith(r1)) { @@ -539,9 +552,8 @@ private: sockets[mux]->rx.put(stream.read()); } data = ""; - return index; } else if (data.endsWith(GF("+TCPCLOSED:"))) { - int mux = stream.readStringUntil('\n').toInt(); // TODO: No comma? + int mux = stream.readStringUntil('\n').toInt(); sockets[mux]->sock_connected = false; data = ""; } @@ -551,12 +563,7 @@ finish: if (!index) { data.trim(); if (data.length()) { - if (data.endsWith(GF("+TCPCLOSED:"))) { - int mux = stream.readStringUntil('\n').toInt(); - sockets[mux]->sock_connected = false; - } else { - DBG("### Unhandled:", data); - } + DBG("### Unhandled:", data); } data = ""; }