From 282d89119b9ec82998b974608f18d094bd187254 Mon Sep 17 00:00:00 2001 From: SRGDamia1 Date: Sun, 9 Apr 2017 12:04:01 -0400 Subject: [PATCH] Unified interface a bit more --- TinyGsmClientA6.h | 11 +++++++++++ TinyGsmClientESP8266.h | 11 +++++++++++ TinyGsmClientM590.h | 12 +++++++++++- TinyGsmClientSIM800.h | 22 ++++++++++++++++------ TinyGsmClientXBee.h | 40 ++++++++++++++++++++-------------------- 5 files changed, 69 insertions(+), 27 deletions(-) diff --git a/TinyGsmClientA6.h b/TinyGsmClientA6.h index 4c4aa6f..4b9e80e 100644 --- a/TinyGsmClientA6.h +++ b/TinyGsmClientA6.h @@ -315,6 +315,17 @@ public: return false; } + /* + * WiFi functions + */ + bool networkConnect(const char* ssid, const char* pwd) { + return false; + } + + bool networkDisconnect() { + return false; + } + /* * GPRS functions */ diff --git a/TinyGsmClientESP8266.h b/TinyGsmClientESP8266.h index 7d51d5a..d6dad03 100644 --- a/TinyGsmClientESP8266.h +++ b/TinyGsmClientESP8266.h @@ -233,6 +233,17 @@ public: return waitResponse(10000L) == 1; } + /* + * GPRS functions + */ + bool gprsConnect(const char* apn, const char* user, const char* pwd) { + return false; + } + + bool gprsDisconnect() { + return false; + } + /* Public Utilities */ template void sendAT(Args... cmd) { diff --git a/TinyGsmClientM590.h b/TinyGsmClientM590.h index 670e550..7cee3fe 100644 --- a/TinyGsmClientM590.h +++ b/TinyGsmClientM590.h @@ -324,6 +324,17 @@ public: return false; } + /* + * WiFi functions + */ + bool networkConnect(const char* ssid, const char* pwd) { + return false; + } + + bool networkDisconnect() { + return false; + } + /* * GPRS functions */ @@ -529,7 +540,6 @@ private: } int modemConnect(const char* host, uint16_t port, uint8_t mux) { - int rsp = 0; for (int i=0; i<3; i++) { String ip = dnsIpQuery(host); diff --git a/TinyGsmClientSIM800.h b/TinyGsmClientSIM800.h index 046483a..8a65522 100644 --- a/TinyGsmClientSIM800.h +++ b/TinyGsmClientSIM800.h @@ -331,6 +331,17 @@ public: return false; } + /* + * WiFi functions + */ + bool networkConnect(const char* ssid, const char* pwd) { + return false; + } + + bool networkDisconnect() { + return false; + } + /* * GPRS functions */ @@ -570,21 +581,21 @@ public: index = 5; goto finish; } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { + index = 6; String mode = streamReadUntil(','); if (mode.toInt() == 1) { mux = streamReadUntil('\n').toInt(); gotData = true; - data = ""; } else { data += mode; } } else if (data.endsWith(GF("CLOSED" GSM_NL))) { + index = 7; int nl = data.lastIndexOf(GSM_NL, data.length()-8); int coma = data.indexOf(',', nl+2); mux = data.substring(nl+2, coma).toInt(); if (mux) { sockets[mux]->sock_connected = false; - data = ""; } } } @@ -595,7 +606,6 @@ public: if (data.length()) { DBG("### Unhandled:", data); } - data = ""; } else { data.trim(); @@ -604,11 +614,11 @@ public: if (data.length()) { DBG(GSM_NL, "<<< ", data); } - data = ""; } if (gotData) { sockets[mux]->sock_available = modemGetAvailable(mux); } + data = ""; return index; } @@ -674,11 +684,11 @@ private: buf[0] = streamRead(); buf[1] = streamRead(); char c = strtol(buf, NULL, 16); - // DBG(c); + DBG(c); #else while (!stream.available()) {} char c = streamRead(); - // DBG(c); + DBG(c); #endif sockets[mux]->rx.put(c); } diff --git a/TinyGsmClientXBee.h b/TinyGsmClientXBee.h index 69f9ff4..2d926ba 100644 --- a/TinyGsmClientXBee.h +++ b/TinyGsmClientXBee.h @@ -323,7 +323,7 @@ public: /* * GPRS functions */ - bool gprsConnect(const char* apn) { + bool gprsConnect(const char* apn, const char* user = "", const char* pw = "") { commandMode(); @@ -380,25 +380,6 @@ public: DBG(GSM_NL, ">>> AT:", cmd...); } - bool commandMode(void){ - delay(1000); // cannot send anything for 1 second before entering command mode - streamWrite("+++"); // enter command mode - waitResponse(1100); - return 1 == waitResponse(1100); // wait another second for an "OK\r" - } - - void writeChanges(void){ - streamWrite("ATWR", GSM_NL); // Write changes to flash - waitResponse(); - streamWrite("ATAC", GSM_NL); // Apply changes - waitResponse(); - } - - void exitCommand(void){ - streamWrite("ATCN", GSM_NL); // Exit command mode - waitResponse(); - } - // TODO: Optimize this! uint8_t waitResponse(uint32_t timeout, String& data, GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR), @@ -541,6 +522,25 @@ private: return return_string; } + bool commandMode(void){ + delay(1000); // cannot send anything for 1 second before entering command mode + streamWrite(GF("+++")); // enter command mode + waitResponse(1100); + return 1 == waitResponse(1100); // wait another second for an "OK\r" + } + + void writeChanges(void){ + sendAT(GF("WR")); // Write changes to flash + waitResponse(); + sendAT(GF("AC")); // Apply changes + waitResponse(); + } + + void exitCommand(void){ + sendAT(GF("CN")); // Exit command mode + waitResponse(); + } + private: Stream& stream; GsmClient* sockets[1];