Skip to content

Commit 0b6b113

Browse files
committed
WiFiC3/CNetIf - added config method to apply new static IP settings
in CWifi::_config netif_set_address call was missing. new CNetIf.config does the static IP change.
1 parent 05feca5 commit 0b6b113

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Diff for: libraries/WiFi/src/WiFi.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ void CWifi::_config(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
9898
/* -------------------------------------------------------------------------- */
9999
_useStaticIp = local_ip != INADDR_NONE;
100100
if(ni != nullptr) {
101-
ni->DhcpStop();
102-
ni->DhcpNotUsed();
103-
IP_ADDR4(&ni->ip, local_ip[0], local_ip[1], local_ip[2], local_ip[3]);
104-
IP_ADDR4(&ni->gw, gateway[0], gateway[1], gateway[2], gateway[3]);
105-
IP_ADDR4(&ni->nm, subnet[0], subnet[1], subnet[2], subnet[3]);
101+
ni->config(local_ip, gateway, subnet);
106102
}
107103
else {
108104
CNetIf::default_ip = local_ip;

Diff for: libraries/lwIpWrapper/src/CNetIf.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,19 @@ void CNetIf::setLinkDown()
12681268
netif_set_down(&ni);
12691269
}
12701270

1271+
/* -------------------------------------------------------------------------- */
1272+
void CNetIf::config(IPAddress _ip, IPAddress _gw, IPAddress _nm)
1273+
{
1274+
DhcpStop();
1275+
DhcpNotUsed();
1276+
1277+
IP_ADDR4(&ip, _ip[0], _ip[1], _ip[2], _ip[3]);
1278+
IP_ADDR4(&nm, _nm[0], _nm[1], _nm[2], _nm[3]);
1279+
IP_ADDR4(&gw, _gw[0], _gw[1], _gw[2], _gw[3]);
1280+
1281+
netif_set_addr(&ni, &ip, &nm, &gw);
1282+
}
1283+
12711284
/* ########################################################################## */
12721285
/* ETHERNET NETWORK INTERFACE CLASS */
12731286
/* ########################################################################## */

Diff for: libraries/lwIpWrapper/src/CNetIf.h

+2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ class CNetIf {
189189
uint32_t getNmAdd() { return ip4_addr_get_u32(&(ni.netmask)); }
190190
uint32_t getGwAdd() { return ip4_addr_get_u32(&(ni.gw)); }
191191

192+
void config(IPAddress _ip, IPAddress _gw, IPAddress _nm);
193+
192194
void setHostname(const char* name)
193195
{
194196
memset(hostname, 0x00, MAX_HOSTNAME_DIM);

0 commit comments

Comments
 (0)