Work-around for boards missing the ip.fromString() method
This commit is contained in:
10
.travis.yml
10
.travis.yml
@@ -18,11 +18,11 @@ env:
|
||||
- PLATFORMIO_CI_SRC=tools/FactoryReset
|
||||
|
||||
# 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
|
||||
- PLATFORMIO_CI_SRC=tools/test_buildA6 PLATFORMIO_CI_ARGS="--project-option='framework=energia' --board=lplm4f120h5qr"
|
||||
|
@@ -267,6 +267,7 @@ public:
|
||||
}
|
||||
String res = stream.readStringUntil('\n');
|
||||
waitResponse();
|
||||
res.trim();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -277,6 +278,7 @@ public:
|
||||
}
|
||||
String res = stream.readStringUntil('\n');
|
||||
waitResponse();
|
||||
res.trim();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -406,8 +408,19 @@ public:
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -629,10 +642,10 @@ public:
|
||||
|
||||
template<typename... Args>
|
||||
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!
|
||||
@@ -647,9 +660,6 @@ public:
|
||||
String r5s(r5); r5s.trim();
|
||||
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
|
||||
data.reserve(64);
|
||||
bool gotData = false;
|
||||
int mux = -1;
|
||||
int len = 0;
|
||||
int index = 0;
|
||||
unsigned long startMillis = millis();
|
||||
do {
|
||||
|
@@ -358,7 +358,7 @@ public:
|
||||
streamWrite("AT", cmd..., GSM_NL);
|
||||
stream.flush();
|
||||
TINY_GSM_YIELD();
|
||||
// DBG("### AT", cmd...);
|
||||
// DBG("### AT:", cmd...);
|
||||
}
|
||||
|
||||
// TODO: Optimize this!
|
||||
@@ -425,6 +425,7 @@ public:
|
||||
if (data.length()) {
|
||||
DBG("### Unhandled:", data);
|
||||
}
|
||||
data = "";
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
@@ -276,6 +276,7 @@ public:
|
||||
}
|
||||
String res = stream.readStringUntil('\n');
|
||||
waitResponse();
|
||||
res.trim();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -286,6 +287,7 @@ public:
|
||||
}
|
||||
String res = stream.readStringUntil('\n');
|
||||
waitResponse();
|
||||
res.trim();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -422,8 +424,19 @@ public:
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -619,7 +632,7 @@ public:
|
||||
streamWrite("AT", cmd..., GSM_NL);
|
||||
stream.flush();
|
||||
TINY_GSM_YIELD();
|
||||
DBG("### AT:", cmd...);
|
||||
// DBG("### AT:", cmd...);
|
||||
}
|
||||
|
||||
// TODO: Optimize this!
|
||||
|
@@ -528,8 +528,19 @@ public:
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -737,7 +748,6 @@ protected:
|
||||
buf[0] = stream.read();
|
||||
buf[1] = stream.read();
|
||||
char c = strtol(buf, NULL, 16);
|
||||
DBG(c);
|
||||
#else
|
||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
||||
char c = stream.read();
|
||||
|
@@ -367,6 +367,36 @@ public:
|
||||
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
|
||||
*/
|
||||
@@ -412,14 +442,24 @@ public:
|
||||
private:
|
||||
int modemConnect(const char* host, uint16_t port, uint8_t mux = 1) {
|
||||
sendAT(GF("LA"), host);
|
||||
String IPaddr; IPaddr.reserve(16);
|
||||
String strIP; strIP.reserve(16);
|
||||
// wait for the response
|
||||
unsigned long startMillis = millis();
|
||||
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) {
|
||||
|
79
tools/test_build/test_build.ino
Normal file
79
tools/test_build/test_build.ino
Normal 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
|
||||
}
|
@@ -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>
|
||||
|
||||
|
Reference in New Issue
Block a user