Browse Source

Fix localIP() on A6

v_master
Volodymyr Shymanskyy 7 years ago
parent
commit
de601105d4
2 changed files with 11 additions and 3 deletions
  1. +2
    -0
      TinyGsmClientA6.h
  2. +9
    -3
      TinyGsmCommon.h

+ 2
- 0
TinyGsmClientA6.h View File

@ -425,6 +425,8 @@ public:
if (waitResponse(10000L, res) != 1) { if (waitResponse(10000L, res) != 1) {
return ""; return "";
} }
res.replace(GSM_NL "OK" GSM_NL, "");
res.replace(GSM_NL, "");
res.trim(); res.trim();
return res; return res;
} }


+ 9
- 3
TinyGsmCommon.h View File

@ -97,16 +97,22 @@ uint32_t TinyGsmAutoBaud(T& SerialAT, uint32_t minimum = 9600, uint32_t maximum
static inline static inline
IPAddress TinyGsmIpFromString(const String& strIP) { IPAddress TinyGsmIpFromString(const String& strIP) {
int Parts[4] = {0,0,0,0};
int Parts[4] = {0, };
int Part = 0; int Part = 0;
for (uint8_t i=0; i<strIP.length(); i++) { for (uint8_t i=0; i<strIP.length(); i++) {
char c = strIP[i]; char c = strIP[i];
if (c == '.') { if (c == '.') {
Part++; Part++;
if (Part > 3) {
return IPAddress(0,0,0,0);
}
continue; continue;
} else if (c >= '0' && c <= '9') {
Parts[Part] *= 10;
Parts[Part] += c - '0';
} else {
if (Part == 3) break;
} }
Parts[Part] *= 10;
Parts[Part] += c - '0';
} }
return IPAddress(Parts[0], Parts[1], Parts[2], Parts[3]); return IPAddress(Parts[0], Parts[1], Parts[2], Parts[3]);
} }


Loading…
Cancel
Save