Add TinyGsmIpFromString(str)
This commit is contained in:
@@ -397,20 +397,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
IPAddress localIP() {
|
IPAddress localIP() {
|
||||||
String strIP = getLocalIP();
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
int Parts[4] = {0,0,0,0};
|
|
||||||
int Part = 0;
|
|
||||||
for (uint8_t 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -292,20 +292,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
IPAddress localIP() {
|
IPAddress localIP() {
|
||||||
String strIP = getLocalIP();
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
int Parts[4] = {0,0,0,0};
|
|
||||||
int Part = 0;
|
|
||||||
for (uint8_t 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -413,20 +413,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
IPAddress localIP() {
|
IPAddress localIP() {
|
||||||
String strIP = getLocalIP();
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
int Parts[4] = {0,0,0,0};
|
|
||||||
int Part = 0;
|
|
||||||
for (uint8_t 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -545,20 +545,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
IPAddress localIP() {
|
IPAddress localIP() {
|
||||||
String strIP = getLocalIP();
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
int Parts[4] = {0,0,0,0};
|
|
||||||
int Part = 0;
|
|
||||||
for (uint8_t 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -392,20 +392,7 @@ fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
IPAddress localIP() {
|
IPAddress localIP() {
|
||||||
String strIP = getLocalIP();
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
int Parts[4] = {0,0,0,0};
|
|
||||||
int Part = 0;
|
|
||||||
for (uint8_t 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -459,19 +446,8 @@ private:
|
|||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
while (stream.available() < 8 && millis() - startMillis < 30000) {};
|
while (stream.available() < 8 && millis() - startMillis < 30000) {};
|
||||||
strIP = streamReadUntil('\r'); // read result
|
strIP = streamReadUntil('\r'); // read result
|
||||||
int Parts[4] = {0,0,0,0};
|
IPAddress ip = TinyGsmIpFromString(IPaddr);
|
||||||
int Part = 0;
|
return modemConnect(ip, port);
|
||||||
for (uint8_t 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 = 0) {
|
int modemConnect(IPAddress ip, uint16_t port, uint8_t mux = 0) {
|
||||||
|
@@ -93,4 +93,19 @@ uint32_t TinyGsmAutoBaud(T& SerialAT)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IPAddress TinyGsmIpFromString(const String& strIP) {
|
||||||
|
int Parts[4] = {0,0,0,0};
|
||||||
|
int Part = 0;
|
||||||
|
for (uint8_t i=0; i<strIP.length(); i++) {
|
||||||
|
char c = strIP[i];
|
||||||
|
if (c == '.') {
|
||||||
|
Part++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Parts[Part] *= 10;
|
||||||
|
Parts[Part] += c - '0';
|
||||||
|
}
|
||||||
|
return IPAddress(Parts[0], Parts[1], Parts[2], Parts[3]);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user