Skip to content

Instantly share code, notes, and snippets.

@kanehekili
Last active June 11, 2025 23:55
Show Gist options
  • Select an option

  • Save kanehekili/b889ce0b37438be3bc59e07d27186d18 to your computer and use it in GitHub Desktop.

Select an option

Save kanehekili/b889ce0b37438be3bc59e07d27186d18 to your computer and use it in GitHub Desktop.

Revisions

  1. kanehekili revised this gist Jun 11, 2025. 1 changed file with 0 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -39,9 +39,3 @@ 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){

    **Recommendation:**
    Use this hybrid approach for 100% reliability...

    **Recommendation:**
    Use this hybrid approach for 100% reliability...
  2. kanehekili revised this gist Jun 11, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ void onConnected(const WiFiEventStationModeGotIP& event) {
    digitalWrite(LED_BUILTIN, HIGH); // LED off (connected)
    }

    defineed in setup() by:
    defined in setup() by:
    static WiFiEventHandler onGotIPHandler = WiFi.onStationModeGotIP(&onConnected);

    Do not rely on onStationModeDisconnected -> won't work on the second disconnection.
  3. kanehekili created this gist Jun 11, 2025.
    47 changes: 47 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    ## 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)
    }

    defineed 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){

    **Recommendation:**
    Use this hybrid approach for 100% reliability...

    **Recommendation:**
    Use this hybrid approach for 100% reliability...