Skip to content

Commit ceb9585

Browse files
committed
added API to get IPs: Locap Ip, GatewayIP and subnetMAsk
Former-commit-id: 69cb644
1 parent 229a9b6 commit ceb9585

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

libraries/WiFiS3/src/WiFi.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,39 @@ int8_t CWifi::scanNetworks() {
176176
return (int8_t)access_points.size();
177177
}
178178

179-
/* -------------------------------------------------------------------------- */
179+
/* -------------------------------------------------------------------------- */
180180
IPAddress CWifi::localIP() {
181-
/* -------------------------------------------------------------------------- */
182-
return IPAddress(0,0,0,0);
181+
/* -------------------------------------------------------------------------- */
182+
string res = "";
183+
if(modem.write(string(PROMPT(_IPSTA)),res, "%s%d\r\n" , CMD_WRITE(_IPSTA), IP_ADDR)) {
184+
IPAddress local_IP;
185+
local_IP.fromString(res.c_str());
186+
return local_IP;
187+
}
188+
return IPAddress(0,0,0,0);
183189
}
184190

185191
/* -------------------------------------------------------------------------- */
186192
IPAddress CWifi::subnetMask() {
187-
/* -------------------------------------------------------------------------- */
188-
return IPAddress(0,0,0,0);
193+
/* -------------------------------------------------------------------------- */
194+
string res = "";
195+
if(modem.write(string(PROMPT(_IPSTA)),res, "%s%d\r\n" , CMD_WRITE(_IPSTA), NETMASK_ADDR)) {
196+
IPAddress subnetMask;
197+
subnetMask.fromString(res.c_str());
198+
return subnetMask;
199+
}
200+
return IPAddress(0,0,0,0);
189201
}
190202

191203
/* -------------------------------------------------------------------------- */
192204
IPAddress CWifi::gatewayIP() {
193-
/* -------------------------------------------------------------------------- */
205+
/* -------------------------------------------------------------------------- */
206+
string res = "";
207+
if(modem.write(string(PROMPT(_IPSTA)),res, "%s%d\r\n" , CMD_WRITE(_IPSTA), GATEWAY_ADDR)) {
208+
IPAddress gateway_IP;
209+
gateway_IP.fromString(res.c_str());
210+
return gateway_IP;
211+
}
194212
return IPAddress(0,0,0,0);
195213
}
196214

libraries/WiFiS3/src/WiFi.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ class CAccessPoint {
2323
string encryption_mode;
2424
};
2525

26-
26+
enum{
27+
IP_ADDR = 0,
28+
GATEWAY_ADDR,
29+
NETMASK_ADDR
30+
} ip_type;
2731

2832

2933
class CWifi {

0 commit comments

Comments
 (0)