Skip to content

Commit 80dc14f

Browse files
committed
Ensure that Static IP configuration for network interfaces is kept until STOP
1 parent 7b29bac commit 80dc14f

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

libraries/Ethernet/src/ETH.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void ETHClass::_onEthEvent(int32_t event_id, void* event_data){
107107
} else if (event_id == ETHERNET_EVENT_STOP) {
108108
log_v("%s Stopped", desc());
109109
arduino_event.event_id = ARDUINO_EVENT_ETH_STOP;
110-
clearStatusBits(ESP_NETIF_STARTED_BIT | ESP_NETIF_CONNECTED_BIT | ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_LOCAL_IP6_BIT | ESP_NETIF_HAS_GLOBAL_IP6_BIT);
110+
clearStatusBits(ESP_NETIF_STARTED_BIT | ESP_NETIF_CONNECTED_BIT | ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_LOCAL_IP6_BIT | ESP_NETIF_HAS_GLOBAL_IP6_BIT | ESP_NETIF_HAS_STATIC_IP_BIT);
111111
}
112112

113113
if(arduino_event.event_id < ARDUINO_EVENT_MAX){

libraries/Network/src/NetworkInterface.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ bool NetworkInterface::connected() const {
281281
}
282282

283283
bool NetworkInterface::hasIP() const {
284-
return (getStatusBits() & ESP_NETIF_HAS_IP_BIT) != 0;
284+
return (getStatusBits() & (ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_STATIC_IP_BIT)) != 0;
285285
}
286286

287287
bool NetworkInterface::hasLinkLocalIPv6() const {
@@ -451,7 +451,7 @@ bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress s
451451
return false;
452452
}
453453

454-
clearStatusBits(ESP_NETIF_HAS_IP_BIT);
454+
clearStatusBits(ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_STATIC_IP_BIT);
455455

456456
// Set IPv4, Netmask, Gateway
457457
err = esp_netif_set_ip_info(_esp_netif, &info);
@@ -473,7 +473,7 @@ bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress s
473473
return false;
474474
}
475475
} else {
476-
setStatusBits(ESP_NETIF_HAS_IP_BIT);
476+
setStatusBits(ESP_NETIF_HAS_STATIC_IP_BIT);
477477
}
478478
}
479479

libraries/Network/src/NetworkInterface.h

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static const int ESP_NETIF_HAS_IP_BIT = BIT2;
2727
static const int ESP_NETIF_HAS_LOCAL_IP6_BIT = BIT3;
2828
static const int ESP_NETIF_HAS_GLOBAL_IP6_BIT = BIT4;
2929
static const int ESP_NETIF_WANT_IP6_BIT = BIT5;
30+
static const int ESP_NETIF_HAS_STATIC_IP_BIT = BIT6;
3031

3132
#define ESP_NETIF_ID_ETH ESP_NETIF_ID_ETH0
3233

libraries/WiFi/src/STA.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void STAClass::_onStaEvent(int32_t event_id, void* event_data){
213213
} else if (event_id == WIFI_EVENT_STA_STOP) {
214214
log_v("STA Stopped");
215215
arduino_event.event_id = ARDUINO_EVENT_WIFI_STA_STOP;
216-
clearStatusBits(ESP_NETIF_STARTED_BIT | ESP_NETIF_CONNECTED_BIT | ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_LOCAL_IP6_BIT | ESP_NETIF_HAS_GLOBAL_IP6_BIT);
216+
clearStatusBits(ESP_NETIF_STARTED_BIT | ESP_NETIF_CONNECTED_BIT | ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_LOCAL_IP6_BIT | ESP_NETIF_HAS_GLOBAL_IP6_BIT | ESP_NETIF_HAS_STATIC_IP_BIT);
217217
} else if (event_id == WIFI_EVENT_STA_AUTHMODE_CHANGE) {
218218
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
219219
wifi_event_sta_authmode_change_t * event = (wifi_event_sta_authmode_change_t*)event_data;
@@ -351,7 +351,7 @@ bool STAClass::connect(){
351351
return false;
352352
}
353353

354-
if((getStatusBits() & ESP_NETIF_HAS_IP_BIT) == 0 && !config()){
354+
if((getStatusBits() & ESP_NETIF_HAS_STATIC_IP_BIT) == 0 && !config()){
355355
log_e("STA failed to configure dynamic IP!");
356356
return false;
357357
}
@@ -422,7 +422,7 @@ bool STAClass::connect(const char* ssid, const char *passphrase, int32_t channel
422422
return false;
423423
}
424424

425-
if((getStatusBits() & ESP_NETIF_HAS_IP_BIT) == 0 && !config()){
425+
if((getStatusBits() & ESP_NETIF_HAS_STATIC_IP_BIT) == 0 && !config()){
426426
log_e("STA failed to configure dynamic IP!");
427427
return false;
428428
}

libraries/WiFi/src/WiFiSTA.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ bool WiFiSTAClass::eraseAP(void) {
169169
*/
170170
bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)
171171
{
172-
return STA.config(local_ip, gateway, subnet, dns1, dns2);
172+
return STA.begin() && STA.config(local_ip, gateway, subnet, dns1, dns2);
173173
}
174174

175175
/**
@@ -179,10 +179,7 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne
179179
*/
180180
bool WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2)
181181
{
182-
if(!STA.started()){
183-
return false;
184-
}
185-
return STA.dnsIP(0, dns1) && STA.dnsIP(1, dns2);
182+
return STA.begin() && STA.dnsIP(0, dns1) && STA.dnsIP(1, dns2);
186183
}
187184

188185
/**

0 commit comments

Comments
 (0)