Last active
June 11, 2025 23:55
-
-
Save kanehekili/b889ce0b37438be3bc59e07d27186d18 to your computer and use it in GitHub Desktop.
Wifi events on ESP8266
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Verified ESP8266 WiFi Event Behavior | |
**Test Setup:** | |
- D1 Mini (ESP-12F) | |
- Arduino Core 3.1.2 | |
- 50+ reboot cycles | |
**Reliable:** | |
✅ `onStationModeGotIP` (when stored statically) | |
**Broken:** | |
❌ `onStationModeDisconnected` (fails after 1st trigger/ESP.reboot) | |
**Test Code:** | |
## Verified ESP8266 WiFi Event Behavior | |
**Test Setup:** | |
- D1 Mini (ESP-12F) | |
- Arduino Core 3.1.2 | |
- 50+ reboot cycles | |
**Reliable:** | |
✅ `onStationModeGotIP` (when stored statically) | |
**Broken:** | |
❌ `onStationModeDisconnected` (fails after 1st trigger) | |
**Full Test Code:** | |
// ===== WiFi Event Handlers ===== // | |
void onConnected(const WiFiEventStationModeGotIP& event) { | |
//Serial.println("WiFi connected!"); | |
Serial.printf("Wifi connected. IP: %s \n", WiFi.localIP().toString().c_str()); | |
setmDNS(); | |
digitalWrite(LED_BUILTIN, HIGH); // LED off (connected) | |
} | |
defined in setup() by: | |
static WiFiEventHandler onGotIPHandler = WiFi.onStationModeGotIP(&onConnected); | |
Do not rely on onStationModeDisconnected -> won't work on the second disconnection. | |
Always use while (WiFi.status() != WL_CONNECTED){ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment