Unverified Commit e4a57854 authored by Me No Dev's avatar Me No Dev Committed by GitHub

Ensure that Static IP configuration for network interfaces is kept until STOP (#9445)

parent 3c1885f8
...@@ -107,7 +107,7 @@ void ETHClass::_onEthEvent(int32_t event_id, void* event_data){ ...@@ -107,7 +107,7 @@ void ETHClass::_onEthEvent(int32_t event_id, void* event_data){
} else if (event_id == ETHERNET_EVENT_STOP) { } else if (event_id == ETHERNET_EVENT_STOP) {
log_v("%s Stopped", desc()); log_v("%s Stopped", desc());
arduino_event.event_id = ARDUINO_EVENT_ETH_STOP; arduino_event.event_id = ARDUINO_EVENT_ETH_STOP;
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); 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);
} }
if(arduino_event.event_id < ARDUINO_EVENT_MAX){ if(arduino_event.event_id < ARDUINO_EVENT_MAX){
......
...@@ -281,7 +281,7 @@ bool NetworkInterface::connected() const { ...@@ -281,7 +281,7 @@ bool NetworkInterface::connected() const {
} }
bool NetworkInterface::hasIP() const { bool NetworkInterface::hasIP() const {
return (getStatusBits() & ESP_NETIF_HAS_IP_BIT) != 0; return (getStatusBits() & (ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_STATIC_IP_BIT)) != 0;
} }
bool NetworkInterface::hasLinkLocalIPv6() const { bool NetworkInterface::hasLinkLocalIPv6() const {
...@@ -451,7 +451,7 @@ bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress s ...@@ -451,7 +451,7 @@ bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress s
return false; return false;
} }
clearStatusBits(ESP_NETIF_HAS_IP_BIT); clearStatusBits(ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_STATIC_IP_BIT);
// Set IPv4, Netmask, Gateway // Set IPv4, Netmask, Gateway
err = esp_netif_set_ip_info(_esp_netif, &info); err = esp_netif_set_ip_info(_esp_netif, &info);
...@@ -473,7 +473,7 @@ bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress s ...@@ -473,7 +473,7 @@ bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress s
return false; return false;
} }
} else { } else {
setStatusBits(ESP_NETIF_HAS_IP_BIT); setStatusBits(ESP_NETIF_HAS_STATIC_IP_BIT);
} }
} }
......
...@@ -27,6 +27,7 @@ static const int ESP_NETIF_HAS_IP_BIT = BIT2; ...@@ -27,6 +27,7 @@ static const int ESP_NETIF_HAS_IP_BIT = BIT2;
static const int ESP_NETIF_HAS_LOCAL_IP6_BIT = BIT3; static const int ESP_NETIF_HAS_LOCAL_IP6_BIT = BIT3;
static const int ESP_NETIF_HAS_GLOBAL_IP6_BIT = BIT4; static const int ESP_NETIF_HAS_GLOBAL_IP6_BIT = BIT4;
static const int ESP_NETIF_WANT_IP6_BIT = BIT5; static const int ESP_NETIF_WANT_IP6_BIT = BIT5;
static const int ESP_NETIF_HAS_STATIC_IP_BIT = BIT6;
#define ESP_NETIF_ID_ETH ESP_NETIF_ID_ETH0 #define ESP_NETIF_ID_ETH ESP_NETIF_ID_ETH0
......
...@@ -213,7 +213,7 @@ void STAClass::_onStaEvent(int32_t event_id, void* event_data){ ...@@ -213,7 +213,7 @@ void STAClass::_onStaEvent(int32_t event_id, void* event_data){
} else if (event_id == WIFI_EVENT_STA_STOP) { } else if (event_id == WIFI_EVENT_STA_STOP) {
log_v("STA Stopped"); log_v("STA Stopped");
arduino_event.event_id = ARDUINO_EVENT_WIFI_STA_STOP; arduino_event.event_id = ARDUINO_EVENT_WIFI_STA_STOP;
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); 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);
} else if (event_id == WIFI_EVENT_STA_AUTHMODE_CHANGE) { } else if (event_id == WIFI_EVENT_STA_AUTHMODE_CHANGE) {
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
wifi_event_sta_authmode_change_t * event = (wifi_event_sta_authmode_change_t*)event_data; wifi_event_sta_authmode_change_t * event = (wifi_event_sta_authmode_change_t*)event_data;
...@@ -355,7 +355,7 @@ bool STAClass::connect(){ ...@@ -355,7 +355,7 @@ bool STAClass::connect(){
return false; return false;
} }
if((getStatusBits() & ESP_NETIF_HAS_IP_BIT) == 0 && !config()){ if((getStatusBits() & ESP_NETIF_HAS_STATIC_IP_BIT) == 0 && !config()){
log_e("STA failed to configure dynamic IP!"); log_e("STA failed to configure dynamic IP!");
return false; return false;
} }
...@@ -426,7 +426,7 @@ bool STAClass::connect(const char* ssid, const char *passphrase, int32_t channel ...@@ -426,7 +426,7 @@ bool STAClass::connect(const char* ssid, const char *passphrase, int32_t channel
return false; return false;
} }
if((getStatusBits() & ESP_NETIF_HAS_IP_BIT) == 0 && !config()){ if((getStatusBits() & ESP_NETIF_HAS_STATIC_IP_BIT) == 0 && !config()){
log_e("STA failed to configure dynamic IP!"); log_e("STA failed to configure dynamic IP!");
return false; return false;
} }
......
...@@ -177,7 +177,7 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne ...@@ -177,7 +177,7 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne
subnet = (tmp != INADDR_NONE) ? tmp : IPAddress(255, 255, 255, 0); subnet = (tmp != INADDR_NONE) ? tmp : IPAddress(255, 255, 255, 0);
} }
return STA.config(local_ip, gateway, subnet, dns1, dns2); return STA.begin() && STA.config(local_ip, gateway, subnet, dns1, dns2);
} }
bool WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) { bool WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) {
...@@ -205,10 +205,7 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) { ...@@ -205,10 +205,7 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) {
*/ */
bool WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2) bool WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2)
{ {
if(!STA.started()){ return STA.begin() && STA.dnsIP(0, dns1) && STA.dnsIP(1, dns2);
return false;
}
return STA.dnsIP(0, dns1) && STA.dnsIP(1, dns2);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment