You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Entries in the NetworkEvent::cbEventList are getting skipped after an entry is removed. This issue exists in all four of the removeEvent routines! Note that the entries in the vector get moved down during the erase so that there is one less in the list. As a result, the next entry must be addressed with the same index that was used for the entry that was erased. To fix this issue, decrement "i" after calling the erase function.
Sketch
// bug-NetworkEvents-removeEvent.ino
#definewifiSSID"Your_WiFi_SSID"
#definewifiPassword"Your_WiFi_Password"
#include<WiFi.h>bool RTK_CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC = false;
//----------------------------------------// System initializationvoidsetup()
{
Serial.begin(115200);
Serial.println();
Serial.println("bug-NetworkEvents-removeEvent.ino");
// Listen for wifi events
Serial.printf("Registering callback handler: %p\r\n", (void *)wifiEvent);
Network.onEvent(wifiEvent);
Network.onEvent(wifiEvent);
Network.onEvent(wifiEvent);
Network.onEvent(wifiEvent);
// Start displaying the events
Serial.println("==================== Receiving 4 events / actual event ====================");
// Start WiFi
WiFi.begin(wifiSSID, wifiPassword);
}
//----------------------------------------// Main loopvoidloop()
{
staticbool eventRemoved;
staticuint32_t lastTimeMillis;
staticbool wifiState;
uint32_t currentMillis = millis();
if ((currentMillis - lastTimeMillis) >= (10 * 1000))
{
lastTimeMillis = currentMillis;
// Toggle the Wifi state
wifiState ^= 1;
if (wifiState)
{
Serial.println("---------- WiFi.disconnect ----------");
WiFi.disconnect(true);
}
else
{
Serial.println("---------- WiFi.begin ----------");
WiFi.begin(wifiSSID, wifiPassword);
}
}
if ((!eventRemoved) && (currentMillis >= (60 * 1000)))
{
// Removing the WiFi event handler// This should remove them all!!!!!!
Network.removeEvent(wifiEvent);
eventRemoved = true;
Serial.println("==================== Removed all the WiFi Event Handlers ====================");
Serial.println("==================== No Event Output Should Be Displayed ====================");
}
}
//----------------------------------------voidwifiEvent(arduino_event_id_t event, arduino_event_info_t info)
{
char ssid[sizeof(info.wifi_sta_connected.ssid) + 1];
IPAddress ipAddress;
// Handle the eventswitch (event)
{
default:
Serial.printf("ERROR: Unknown WiFi event: %d\r\n", event);
break;
case ARDUINO_EVENT_WIFI_OFF:
Serial.println("WiFi Off");
break;
case ARDUINO_EVENT_WIFI_READY:
Serial.println("WiFi Ready");
break;
case ARDUINO_EVENT_WIFI_SCAN_DONE:
Serial.println("WiFi Scan Done");
// wifi_event_sta_scan_done_t info.wifi_scan_done;break;
case ARDUINO_EVENT_WIFI_STA_START:
Serial.println("WiFi STA Started");
break;
case ARDUINO_EVENT_WIFI_STA_STOP:
Serial.println("WiFi STA Stopped");
break;
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
memcpy(ssid, info.wifi_sta_connected.ssid, info.wifi_sta_connected.ssid_len);
ssid[info.wifi_sta_connected.ssid_len] = 0;
Serial.printf("WiFi STA connected to %s\r\n", ssid);
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
memcpy(ssid, info.wifi_sta_disconnected.ssid, info.wifi_sta_disconnected.ssid_len);
ssid[info.wifi_sta_disconnected.ssid_len] = 0;
Serial.printf("WiFi STA disconnected from %s\r\n", ssid);
// wifi_event_sta_disconnected_t info.wifi_sta_disconnected;break;
case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
Serial.println("WiFi STA Auth Mode Changed");
// wifi_event_sta_authmode_change_t info.wifi_sta_authmode_change;break;
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
ipAddress = WiFi.localIP();
Serial.print("WiFi STA Got IPv4: ");
Serial.println(ipAddress);
break;
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
Serial.print("WiFi STA Got IPv6: ");
Serial.println(ipAddress);
break;
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
Serial.println("WiFi STA Lost IP");
break;
}
}
Debug Message
None
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
I confirm I have checked existing issues, online documentation and Troubleshooting guide.
The text was updated successfully, but these errors were encountered:
Board
ESP32 Dev Module
Device Description
Using WiFi on ESP32
Hardware Configuration
Any ESP32 platform
Version
latest master (checkout manually)
IDE Name
Arduino IDE
Operating System
Linux
Flash frequency
80 MHz
PSRAM enabled
yes
Upload speed
921600
Description
Entries in the NetworkEvent::cbEventList are getting skipped after an entry is removed. This issue exists in all four of the removeEvent routines! Note that the entries in the vector get moved down during the erase so that there is one less in the list. As a result, the next entry must be addressed with the same index that was used for the entry that was erased. To fix this issue, decrement "i" after calling the erase function.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: