Skip to content

Commit e4a5785

Browse files
authored
Ensure that Static IP configuration for network interfaces is kept until STOP (espressif#9445)
1 parent 3c1885f commit e4a5785

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;
@@ -355,7 +355,7 @@ bool STAClass::connect(){
355355
return false;
356356
}
357357

358-
if((getStatusBits() & ESP_NETIF_HAS_IP_BIT) == 0 && !config()){
358+
if((getStatusBits() & ESP_NETIF_HAS_STATIC_IP_BIT) == 0 && !config()){
359359
log_e("STA failed to configure dynamic IP!");
360360
return false;
361361
}
@@ -426,7 +426,7 @@ bool STAClass::connect(const char* ssid, const char *passphrase, int32_t channel
426426
return false;
427427
}
428428

429-
if((getStatusBits() & ESP_NETIF_HAS_IP_BIT) == 0 && !config()){
429+
if((getStatusBits() & ESP_NETIF_HAS_STATIC_IP_BIT) == 0 && !config()){
430430
log_e("STA failed to configure dynamic IP!");
431431
return false;
432432
}

libraries/WiFi/src/WiFiSTA.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne
177177
subnet = (tmp != INADDR_NONE) ? tmp : IPAddress(255, 255, 255, 0);
178178
}
179179

180-
return STA.config(local_ip, gateway, subnet, dns1, dns2);
180+
return STA.begin() && STA.config(local_ip, gateway, subnet, dns1, dns2);
181181
}
182182

183183
bool WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) {
@@ -205,10 +205,7 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) {
205205
*/
206206
bool WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2)
207207
{
208-
if(!STA.started()){
209-
return false;
210-
}
211-
return STA.dnsIP(0, dns1) && STA.dnsIP(1, dns2);
208+
return STA.begin() && STA.dnsIP(0, dns1) && STA.dnsIP(1, dns2);
212209
}
213210

214211
/**

0 commit comments

Comments
 (0)