Skip to content

Cannot turn off WIFi #4700

Closed
Closed
@philbowles

Description

@philbowles

Core 1.0.4, multiple different boards.

I'm trying to determine what state the WiFi is in immediately after boot
Calling printDiag first thing causes guru meditation

Decoding 10 results
0x400d1c99: Print::write(char const*) at C:\Users\phil\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Print.cpp line 234
0x400d1ce1: Print::print(char const*) at C:\Users\phil\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Print.cpp line 234
:  (inlined by) Print::println(char const*) at C:\Users\phil\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/Print.cpp line 182
0x400d0f73: WiFiClass::printDiag(Print&) at C:\Users\phil\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi\src/WiFi.cpp line 60
0x400d0e75: setup() at C:\Users\phil\Desktop\ESP32_WIFI_BUG/ESP32_WIFI_BUG.ino line 9
0x400d21df: loopTask(void*) at C:\Users\phil\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32/main.cpp line 14
0x40088b7d: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 355 (discriminator 1)

Q1 why has #1088 never been fixed?

Q2 Both getMode() and SSID() report incorrect values if called first thing. What is the "correct" way to determine intial state / settings without first calling some API that will change them, e.g. WiFi.mode(...) or WiFi.disconnect?

Q3 What is the "correct" way to turn off WiFi? WiFi.softAPdisconnect(true) does not do it*, WiFi.mode(WIFI_OFF) does not do it*

Q4 What is the "correct" way to clear any stored credentials as in the ESP8266 equivalent of ESP.eraseConfig()? I want to do a full "factory reset" and the IDE does not have "total flash erase" tools options for either of my two boards: WEMOS LOLIN32 and ESP32 Dev Module

MVCE

#include <WiFi.h>
void setup()
{
    Serial.begin(115200);
    // WiFi.printDiag(Serial); // guru meditation
    Serial.printf("INITIAL MODE=%d\n",WiFi.getMode()); // always reports 0
    Serial.printf("STORED  SSID=%s\n",WiFi.SSID().c_str()); // not true
    WiFi.softAP("BOGUS");
    Serial.printf("\nAfter softAP\n");
    WiFi.printDiag(Serial); // now shows ACTUAL stored SSID
    // keywords is missing softAPdisconnect: not syntax colored
    WiFi.softAPdisconnect(true); // true -> does NOT turn off WiFi!
    Serial.printf("\nAfter softAPdisconnect(true)\n");
    WiFi.printDiag(Serial);
    WiFi.mode(WIFI_OFF);
    Serial.printf("\nAfter WiFi.mode(WIFI_OFF)\n");
    WiFi.printDiag(Serial);
}
void loop(){}

Output WEMOS LOLIN32 (no diag options available)

14:53:45.283 -> ets Jun  8 2016 00:22:57
14:53:45.283 -> 
14:53:45.283 -> rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
14:53:45.283 -> configsip: 0, SPIWP:0xee
14:53:45.283 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
14:53:45.283 -> mode:DIO, clock div:1
14:53:45.283 -> load:0x3fff0018,len:4
14:53:45.283 -> load:0x3fff001c,len:1044
14:53:45.283 -> load:0x40078000,len:8896
14:53:45.283 -> load:0x40080400,len:5816
14:53:45.283 -> entry 0x400806ac
14:53:45.520 -> INITIAL MODE=0
14:53:45.520 -> STORED  SSID=
14:53:45.621 -> 
14:53:45.621 -> After softAP
14:53:45.621 -> Mode: AP
14:53:45.621 -> Channel: 1
14:53:45.621 -> SSID (8): XXXXXXXX
14:53:45.621 -> Passphrase (8): XXXXXXXX
14:53:45.621 -> BSSID set: 0
14:53:45.655 -> 
14:53:45.655 -> After softAPdisconnect(true)
14:53:45.655 -> Mode: AP
14:53:45.655 -> Channel: 1
14:53:45.655 -> SSID (8): XXXXXXXX
14:53:45.655 -> Passphrase (8): XXXXXXXX
14:53:45.655 -> BSSID set: 0
14:53:45.655 -> 
14:53:45.655 -> After WiFi.mode(WIFI_OFF)
14:53:45.655 -> Mode: AP
14:53:45.655 -> Channel: 1
14:53:45.655 -> SSID (8): XXXXXXXX
14:53:45.655 -> Passphrase (8): XXXXXXXX
14:53:45.655 -> BSSID set: 0

ESP32 Dev Board diag=verbose

15:01:50.857 -> ets Jun  8 2016 00:22:57
15:01:50.857 -> 
15:01:50.857 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
15:01:50.857 -> configsip: 0, SPIWP:0xee
15:01:50.857 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
15:01:50.857 -> mode:DIO, clock div:1
15:01:50.857 -> load:0x3fff0018,len:4
15:01:50.892 -> load:0x3fff001c,len:1216
15:01:50.892 -> ho 0 tail 12 room 4
15:01:50.892 -> load:0x40078000,len:9720
15:01:50.892 -> ho 0 tail 12 room 4
15:01:50.892 -> load:0x40080400,len:6352
15:01:50.892 -> entry 0x400806b8
15:01:51.101 -> INITIAL MODE=0
15:01:51.101 -> STORED  SSID=
15:01:51.196 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 0 - WIFI_READY
15:01:51.196 -> 
15:01:51.196 -> After softAP
15:01:51.196 -> Mode: AP
15:01:51.196 -> Channel: 1
15:01:51.196 -> SSID (8): XXXXXXXX
15:01:51.196 -> Passphrase (8): XXXXXXXX
15:01:51.243 -> BSSID set: 0
15:01:51.243 -> 
15:01:51.243 -> After softAPdisconnect(true)
15:01:51.243 -> Mode: AP
15:01:51.243 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 15 - AP_STACONNECTED
15:01:51.243 -> Channel: 1
15:01:51.243 -> SSID ([D][WiFiGeneric.cpp:337] _eventCallback(): Event: 14 - AP_STOP
15:01:51.243 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 15 - AP_STACONNECTED
15:01:51.243 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 15 - AP_STACONNECTED
15:01:51.243 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 15 - AP_STACONNECTED
15:01:51.243 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 15 - AP_STACONNECTED
15:01:51.290 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 15 - AP_STACONNECTED
15:01:51.290 -> 
15:01:51.290 -> BSSID set: 0
15:01:51.290 -> 
15:01:51.290 -> After WiFi.mode(WIFI_OFF)
15:01:51.290 -> Mode: AP
15:01:51.290 -> Channel: 1
15:01:51.290 -> SSID (8): XXXXXXXX
15:01:51.290 -> Passphrase (8): XXXXXXXX
15:01:51.290 -> BSSID set: 0

Looking at that event trace - maybe this is why printDiag fails - because some background has not yet started WiFi ? Maybe all users need to monitor WiFi events and not call anything until after event 0? I'm guessing this is also why getmode and ssid report incorrect values... Is there anything in the docs I have missed that make this clear? Also does the WiFi have to be in a certain state before any of the OFF methods work? What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions