Browse Source

Unified interface a bit more

v_master
SRGDamia1 7 years ago
parent
commit
282d89119b
5 changed files with 69 additions and 27 deletions
  1. +11
    -0
      TinyGsmClientA6.h
  2. +11
    -0
      TinyGsmClientESP8266.h
  3. +11
    -1
      TinyGsmClientM590.h
  4. +16
    -6
      TinyGsmClientSIM800.h
  5. +20
    -20
      TinyGsmClientXBee.h

+ 11
- 0
TinyGsmClientA6.h View File

@ -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
*/


+ 11
- 0
TinyGsmClientESP8266.h View File

@ -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<typename... Args>
void sendAT(Args... cmd) {


+ 11
- 1
TinyGsmClientM590.h View File

@ -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);


+ 16
- 6
TinyGsmClientSIM800.h View File

@ -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);
}


+ 20
- 20
TinyGsmClientXBee.h View File

@ -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];


Loading…
Cancel
Save