Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/Ethernet/src/ETH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void ETHClass::_onEthEvent(int32_t event_id, void* event_data){
} else if (event_id == ETHERNET_EVENT_STOP) {
log_v("%s Stopped", desc());
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){
Expand Down
6 changes: 3 additions & 3 deletions libraries/Network/src/NetworkInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ bool NetworkInterface::connected() 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 {
Expand Down Expand Up @@ -451,7 +451,7 @@ bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress s
return false;
}

clearStatusBits(ESP_NETIF_HAS_IP_BIT);
clearStatusBits(ESP_NETIF_HAS_IP_BIT | ESP_NETIF_HAS_STATIC_IP_BIT);

// Set IPv4, Netmask, Gateway
err = esp_netif_set_ip_info(_esp_netif, &info);
Expand All @@ -473,7 +473,7 @@ bool NetworkInterface::config(IPAddress local_ip, IPAddress gateway, IPAddress s
return false;
}
} else {
setStatusBits(ESP_NETIF_HAS_IP_BIT);
setStatusBits(ESP_NETIF_HAS_STATIC_IP_BIT);
}
}

Expand Down
1 change: 1 addition & 0 deletions libraries/Network/src/NetworkInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_GLOBAL_IP6_BIT = BIT4;
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

Expand Down
6 changes: 3 additions & 3 deletions libraries/WiFi/src/STA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void STAClass::_onStaEvent(int32_t event_id, void* event_data){
} else if (event_id == WIFI_EVENT_STA_STOP) {
log_v("STA Stopped");
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) {
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
wifi_event_sta_authmode_change_t * event = (wifi_event_sta_authmode_change_t*)event_data;
Expand Down Expand Up @@ -355,7 +355,7 @@ bool STAClass::connect(){
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!");
return false;
}
Expand Down Expand Up @@ -426,7 +426,7 @@ bool STAClass::connect(const char* ssid, const char *passphrase, int32_t channel
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!");
return false;
}
Expand Down
7 changes: 2 additions & 5 deletions libraries/WiFi/src/WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ bool WiFiSTAClass::eraseAP(void) {
*/
bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)
{
return STA.config(local_ip, gateway, subnet, dns1, dns2);
return STA.begin() && STA.config(local_ip, gateway, subnet, dns1, dns2);
}

/**
Expand All @@ -179,10 +179,7 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne
*/
bool WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2)
{
if(!STA.started()){
return false;
}
return STA.dnsIP(0, dns1) && STA.dnsIP(1, dns2);
return STA.begin() && STA.dnsIP(0, dns1) && STA.dnsIP(1, dns2);
}

/**
Expand Down