Browse Source

Work-around for boards missing the ip.fromString() method

v_master
SRGDamia1 7 years ago
parent
commit
ff574d69ef
8 changed files with 185 additions and 31 deletions
  1. +5
    -5
      .travis.yml
  2. +19
    -9
      TinyGsmClientA6.h
  3. +2
    -1
      TinyGsmClientESP8266.h
  4. +16
    -3
      TinyGsmClientM590.h
  5. +13
    -3
      TinyGsmClientSIM800.h
  6. +45
    -5
      TinyGsmClientXBee.h
  7. +79
    -0
      tools/test_build/test_build.ino
  8. +6
    -5
      tools/test_buildA6/test_build.ino

+ 5
- 5
.travis.yml View File

@ -18,11 +18,11 @@ env:
- PLATFORMIO_CI_SRC=tools/FactoryReset - PLATFORMIO_CI_SRC=tools/FactoryReset
# Arduino test # Arduino test
- PLATFORMIO_CI_SRC=tools/test_buildA6 PLATFORMIO_CI_ARGS="--project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=uno_pic32 --board=esp01 --board=nodemcuv2 --board=esp32dev --board=mayfly"
- PLATFORMIO_CI_SRC=tools/test_buildESP8266 PLATFORMIO_CI_ARGS="--project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=uno_pic32 --board=esp01 --board=nodemcuv2 --board=esp32dev --board=mayfly"
- PLATFORMIO_CI_SRC=tools/test_buildM590 PLATFORMIO_CI_ARGS="--project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=uno_pic32 --board=esp01 --board=nodemcuv2 --board=esp32dev --board=mayfly"
- PLATFORMIO_CI_SRC=tools/test_buildSIM800 PLATFORMIO_CI_ARGS="--project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=uno_pic32 --board=esp01 --board=nodemcuv2 --board=esp32dev --board=mayfly"
- PLATFORMIO_CI_SRC=tools/test_buildXBee PLATFORMIO_CI_ARGS="--project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=uno_pic32 --board=esp01 --board=nodemcuv2 --board=esp32dev --board=mayfly"
- PLATFORMIO_CI_SRC=tools/test_build PLATFORMIO_CI_ARGS="--project-option='build_flags=-D TINY_GSM_MODEM_SIM800' --project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=uno_pic32 --board=esp01 --board=nodemcuv2 --board=esp32dev --board=mayfly"
- PLATFORMIO_CI_SRC=tools/test_build PLATFORMIO_CI_ARGS="--project-option='build_flags=-D TINY_GSM_MODEM_A6' --project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=uno_pic32 --board=esp01 --board=nodemcuv2 --board=esp32dev --board=mayfly"
- PLATFORMIO_CI_SRC=tools/test_build PLATFORMIO_CI_ARGS="--project-option='build_flags=-D TINY_GSM_MODEM_M590' --project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=uno_pic32 --board=esp01 --board=nodemcuv2 --board=esp32dev --board=mayfly"
- PLATFORMIO_CI_SRC=tools/test_build PLATFORMIO_CI_ARGS="--project-option='build_flags=-D TINY_GSM_MODEM_ESP8266' --project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=uno_pic32 --board=esp01 --board=nodemcuv2 --board=esp32dev --board=mayfly"
- PLATFORMIO_CI_SRC=tools/test_build PLATFORMIO_CI_ARGS="--project-option='build_flags=-D TINY_GSM_MODEM_XBEE' --project-option='framework=arduino' --board=uno --board=leonardo --board=yun --board=megaatmega2560 --board=genuino101 --board=mkr1000USB --board=zero --board=teensy31 --board=bluepill_f103c8 --board=uno_pic32 --board=esp01 --board=nodemcuv2 --board=esp32dev --board=mayfly"
# Energia test # Energia test
- PLATFORMIO_CI_SRC=tools/test_buildA6 PLATFORMIO_CI_ARGS="--project-option='framework=energia' --board=lplm4f120h5qr" - PLATFORMIO_CI_SRC=tools/test_buildA6 PLATFORMIO_CI_ARGS="--project-option='framework=energia' --board=lplm4f120h5qr"


+ 19
- 9
TinyGsmClientA6.h View File

@ -267,6 +267,7 @@ public:
} }
String res = stream.readStringUntil('\n'); String res = stream.readStringUntil('\n');
waitResponse(); waitResponse();
res.trim();
return res; return res;
} }
@ -277,6 +278,7 @@ public:
} }
String res = stream.readStringUntil('\n'); String res = stream.readStringUntil('\n');
waitResponse(); waitResponse();
res.trim();
return res; return res;
} }
@ -406,8 +408,19 @@ public:
} }
IPAddress localIP() { IPAddress localIP() {
IPAddress res;
res.fromString(getLocalIP());
String strIP = getLocalIP();
int Parts[4] = {0,0,0,0};
int Part = 0;
for ( int i=0; i<strIP.length(); i++ ) {
char c = strIP[i];
if ( c == '.' ) {
Part++;
continue;
}
Parts[Part] *= 10;
Parts[Part] += c - '0';
}
IPAddress res( Parts[0], Parts[1], Parts[2], Parts[3] );
return res; return res;
} }
@ -629,10 +642,10 @@ public:
template<typename... Args> template<typename... Args>
void sendAT(Args... cmd) { void sendAT(Args... cmd) {
streamWrite("AT", cmd..., GSM_NL);
stream.flush();
TINY_GSM_YIELD();
// DBG("### AT:", cmd...);
streamWrite("AT", cmd..., GSM_NL);
stream.flush();
TINY_GSM_YIELD();
// DBG("### AT:", cmd...);
} }
// TODO: Optimize this! // TODO: Optimize this!
@ -647,9 +660,6 @@ public:
String r5s(r5); r5s.trim(); String r5s(r5); r5s.trim();
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/ DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
data.reserve(64); data.reserve(64);
bool gotData = false;
int mux = -1;
int len = 0;
int index = 0; int index = 0;
unsigned long startMillis = millis(); unsigned long startMillis = millis();
do { do {


+ 2
- 1
TinyGsmClientESP8266.h View File

@ -358,7 +358,7 @@ public:
streamWrite("AT", cmd..., GSM_NL); streamWrite("AT", cmd..., GSM_NL);
stream.flush(); stream.flush();
TINY_GSM_YIELD(); TINY_GSM_YIELD();
// DBG("### AT", cmd...);
// DBG("### AT:", cmd...);
} }
// TODO: Optimize this! // TODO: Optimize this!
@ -425,6 +425,7 @@ public:
if (data.length()) { if (data.length()) {
DBG("### Unhandled:", data); DBG("### Unhandled:", data);
} }
data = "";
} }
return index; return index;
} }


+ 16
- 3
TinyGsmClientM590.h View File

@ -276,6 +276,7 @@ public:
} }
String res = stream.readStringUntil('\n'); String res = stream.readStringUntil('\n');
waitResponse(); waitResponse();
res.trim();
return res; return res;
} }
@ -286,6 +287,7 @@ public:
} }
String res = stream.readStringUntil('\n'); String res = stream.readStringUntil('\n');
waitResponse(); waitResponse();
res.trim();
return res; return res;
} }
@ -422,8 +424,19 @@ public:
} }
IPAddress localIP() { IPAddress localIP() {
IPAddress res;
res.fromString(getLocalIP());
String strIP = getLocalIP();
int Parts[4] = {0,0,0,0};
int Part = 0;
for ( int i=0; i<strIP.length(); i++ ) {
char c = strIP[i];
if ( c == '.' ) {
Part++;
continue;
}
Parts[Part] *= 10;
Parts[Part] += c - '0';
}
IPAddress res( Parts[0], Parts[1], Parts[2], Parts[3] );
return res; return res;
} }
@ -619,7 +632,7 @@ public:
streamWrite("AT", cmd..., GSM_NL); streamWrite("AT", cmd..., GSM_NL);
stream.flush(); stream.flush();
TINY_GSM_YIELD(); TINY_GSM_YIELD();
DBG("### AT:", cmd...);
// DBG("### AT:", cmd...);
} }
// TODO: Optimize this! // TODO: Optimize this!


+ 13
- 3
TinyGsmClientSIM800.h View File

@ -528,8 +528,19 @@ public:
} }
IPAddress localIP() { IPAddress localIP() {
IPAddress res;
res.fromString(getLocalIP());
String strIP = getLocalIP();
int Parts[4] = {0,0,0,0};
int Part = 0;
for ( int i=0; i<strIP.length(); i++ ) {
char c = strIP[i];
if ( c == '.' ) {
Part++;
continue;
}
Parts[Part] *= 10;
Parts[Part] += c - '0';
}
IPAddress res( Parts[0], Parts[1], Parts[2], Parts[3] );
return res; return res;
} }
@ -737,7 +748,6 @@ protected:
buf[0] = stream.read(); buf[0] = stream.read();
buf[1] = stream.read(); buf[1] = stream.read();
char c = strtol(buf, NULL, 16); char c = strtol(buf, NULL, 16);
DBG(c);
#else #else
while (!stream.available()) { TINY_GSM_YIELD(); } while (!stream.available()) { TINY_GSM_YIELD(); }
char c = stream.read(); char c = stream.read();


+ 45
- 5
TinyGsmClientXBee.h View File

@ -367,6 +367,36 @@ public:
return false; // Doesn't support disconnecting return false; // Doesn't support disconnecting
} }
String getLocalIP() {
commandMode();
sendAT(GF("LA"), host);
String IPaddr; IPaddr.reserve(16);
// wait for the response
unsigned long startMillis = millis();
while (stream.available() < 8 && millis() - startMillis < 30000) {};
IPaddr = streamReadUntil('\r'); // read result
return IPaddr;
}
IPAddress localIP() {
String strIP = getLocalIP();
int Parts[4] = {0,0,0,0};
int Part = 0;
for ( int i=0; i<strIP.length(); i++ )
{
char c = strIP[i];
if ( c == '.' )
{
Part++;
continue;
}
Parts[Part] *= 10;
Parts[Part] += c - '0';
}
IPAddress res( Parts[0], Parts[1], Parts[2], Parts[3] );
return res;
}
/* /*
* GPRS functions * GPRS functions
*/ */
@ -412,14 +442,24 @@ public:
private: private:
int modemConnect(const char* host, uint16_t port, uint8_t mux = 1) { int modemConnect(const char* host, uint16_t port, uint8_t mux = 1) {
sendAT(GF("LA"), host); sendAT(GF("LA"), host);
String IPaddr; IPaddr.reserve(16);
String strIP; strIP.reserve(16);
// wait for the response // wait for the response
unsigned long startMillis = millis(); unsigned long startMillis = millis();
while (stream.available() < 8 && millis() - startMillis < 30000) {}; while (stream.available() < 8 && millis() - startMillis < 30000) {};
IPaddr = streamReadUntil('\r'); // read result
IPAddress ip;
ip.fromString(IPaddr);
return modemConnect(ip, port);
strIP = streamReadUntil('\r'); // read result
int Parts[4] = {0,0,0,0};
int Part = 0;
for ( int i=0; i<strIP.length(); i++ ) {
char c = strIP[i];
if ( c == '.' ) {
Part++;
continue;
}
Parts[Part] *= 10;
Parts[Part] += c - '0';
}
IPAddress res( Parts[0], Parts[1], Parts[2], Parts[3] );
return modemConnect(res, port);
} }
int modemConnect(IPAddress ip, uint16_t port, uint8_t mux = 1) { int modemConnect(IPAddress ip, uint16_t port, uint8_t mux = 1) {


+ 79
- 0
tools/test_build/test_build.ino View File

@ -0,0 +1,79 @@
/**************************************************************
*
* DO NOT USE THIS - this is just a compilation test!
*
**************************************************************/
// #define TINY_GSM_MODEM_SIM800
#define TINY_GSM_MODEM_A6
// #define TINY_GSM_MODEM_M590
// #define TINY_GSM_MODEM_ESP8266
// #define TINY_GSM_MODEM_XBEE
#include <TinyGsmClient.h>
TinyGsm modem(Serial);
TinyGsmClient client(modem);
char server[] = "somewhere";
char resource[] = "something";
void setup() {
Serial.begin(115200);
delay(3000);
modem.restart();
}
void loop() {
// Test the start/restart functions
modem.restart();
modem.begin();
modem.autoBaud();
modem.factoryDefault();
// Test the SIM card functions
#if defined(TINY_GSM_MODEM_SIM800) || defined(TINY_GSM_MODEM_A6) || defined(TINY_GSM_MODEM_M590) || defined(TINY_GSM_MODEM_XBEE)
modem.getSimCCID();
modem.getIMEI();
modem.getSimStatus();
modem.getRegistrationStatus();
modem.getOperator();
#endif
// Test the Networking functions
modem.getSignalQuality();
#if defined(TINY_GSM_MODEM_SIM800) || defined(TINY_GSM_MODEM_A6) || defined(TINY_GSM_MODEM_M590)
modem.waitForNetwork();
modem.gprsConnect("YourAPN", "", "");
#else
modem.networkConnect("YourSSID", "YourPWD");
modem.waitForNetwork();
#endif
client.connect(server, 80);
// Make a HTTP GET request:
client.print(String("GET ") + resource + " HTTP/1.0\r\n");
client.print(String("Host: ") + server + "\r\n");
client.print("Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.connected() && millis() - timeout < 10000L) {
while (client.available()) {
client.read();
timeout = millis();
}
}
client.stop();
#if defined(TINY_GSM_MODEM_SIM800) || defined(TINY_GSM_MODEM_A6) || defined(TINY_GSM_MODEM_M590)
modem.gprsDisconnect();
#else
modem.networkDisconnect();
#endif
}

+ 6
- 5
tools/test_buildA6/test_build.ino View File

@ -4,11 +4,12 @@
* *
**************************************************************/ **************************************************************/
// #define TINY_GSM_MODEM_SIM800
#define TINY_GSM_MODEM_A6
// #define TINY_GSM_MODEM_M590
// #define TINY_GSM_MODEM_ESP8266
// #define TINY_GSM_MODEM_XBEE
// #define TINY_GSM_MODEM_SIM800
// #define TINY_GSM_MODEM_SIM808
// #define TINY_GSM_MODEM_A6
// #define TINY_GSM_MODEM_M590
// #define TINY_GSM_MODEM_ESP8266
// #define TINY_GSM_MODEM_XBEE
#include <TinyGsmClient.h> #include <TinyGsmClient.h>


Loading…
Cancel
Save