Fix A6 <> Blynk operation
This commit is contained in:
@@ -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
|
||||||
@@ -166,6 +161,12 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
TinyGsm(Stream& stream)
|
||||||
|
: stream(stream)
|
||||||
|
{
|
||||||
|
memset(sockets, 0, sizeof(sockets));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Basic functions
|
* Basic functions
|
||||||
*/
|
*/
|
||||||
@@ -226,6 +227,11 @@ public:
|
|||||||
return init();
|
return init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool poweroff() {
|
||||||
|
sendAT(GF("+CPOF"));
|
||||||
|
return waitResponse() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
@@ -351,12 +357,14 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*sendAT(GF("+CIFSR"));
|
/*
|
||||||
|
sendAT(GF("+CIFSR"));
|
||||||
String data;
|
String data;
|
||||||
if (waitResponse(10000L, data) != 1) {
|
if (waitResponse(10000L, data) != 1) {
|
||||||
data.replace(GSM_NL, "");
|
data.replace(GSM_NL, "");
|
||||||
return false;
|
return false;
|
||||||
}*/
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -370,6 +378,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;
|
||||||
@@ -380,6 +390,11 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void callRedial() {
|
||||||
|
sendAT(GF("DLST"));
|
||||||
|
return waitResponse() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
bool callHangup(const String& number) {
|
bool callHangup(const String& number) {
|
||||||
sendAT(GF("H"), number);
|
sendAT(GF("H"), number);
|
||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
@@ -389,9 +404,7 @@ public:
|
|||||||
* Messaging functions
|
* Messaging functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO
|
void sendUSSD() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
void sendUSSD() {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendSMS(const String& number, const String& text) {
|
bool sendSMS(const String& number, const String& text) {
|
||||||
sendAT(GF("+CMGF=1"));
|
sendAT(GF("+CMGF=1"));
|
||||||
@@ -411,8 +424,7 @@ public:
|
|||||||
* Location functions
|
* Location functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void getGsmLocation() {
|
String getGsmLocation() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Battery functions
|
* Battery functions
|
||||||
@@ -442,7 +454,7 @@ private:
|
|||||||
|
|
||||||
int modemSend(const void* buff, size_t len, uint8_t mux) {
|
int modemSend(const void* buff, size_t len, uint8_t mux) {
|
||||||
sendAT(GF("+CIPSEND="), mux, ',', len);
|
sendAT(GF("+CIPSEND="), mux, ',', len);
|
||||||
if (waitResponse(10000L, GF(GSM_NL ">")) != 1) {
|
if (waitResponse(2000L, GF(GSM_NL ">")) != 1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
stream.write((uint8_t*)buff, len);
|
stream.write((uint8_t*)buff, len);
|
||||||
@@ -460,7 +472,10 @@ private:
|
|||||||
return 1 == res;
|
return 1 == res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
/* Utilities */
|
/* Utilities */
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void streamWrite(T last) {
|
void streamWrite(T last) {
|
||||||
stream.print(last);
|
stream.print(last);
|
||||||
@@ -472,8 +487,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(); }
|
||||||
@@ -508,7 +521,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)) {
|
||||||
@@ -539,9 +552,8 @@ private:
|
|||||||
sockets[mux]->rx.put(stream.read());
|
sockets[mux]->rx.put(stream.read());
|
||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
return index;
|
|
||||||
} else if (data.endsWith(GF("+TCPCLOSED:"))) {
|
} 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;
|
sockets[mux]->sock_connected = false;
|
||||||
data = "";
|
data = "";
|
||||||
}
|
}
|
||||||
@@ -551,13 +563,8 @@ finish:
|
|||||||
if (!index) {
|
if (!index) {
|
||||||
data.trim();
|
data.trim();
|
||||||
if (data.length()) {
|
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 = "";
|
data = "";
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
|
Reference in New Issue
Block a user