Skip to content
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

ESP32 can not disable and enable Wifi #4810

Closed
seackone opened this issue Feb 15, 2021 · 2 comments
Closed

ESP32 can not disable and enable Wifi #4810

seackone opened this issue Feb 15, 2021 · 2 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@seackone
Copy link

Hi,
I have the same issue as explained in this post:
https://github.com/espressif/arduino-esp32/issues/4421

If im trying to disable and enable wifi, I always get this message:

WiFiGeneric.cpp:983] mode(): Could not set mode! 12289

I wrote a simple code for my loop function:

void loop() {
  WiFi.mode(WIFI_MODE_STA);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) 
  {
     delay(1000);
     Serial.println("Connecting to Wifi..");
  }
  Serial.println("Wifi Connected!");
  
  delay(10000);

  WiFi.disconnect(true);
  Serial.println("Wifi disconnected");
  
  WiFi.mode(WIFI_OFF);
  Serial.println("Wifi OFF");
  
  delay(15000);
}

I found two solutions but they did not work for me so far. Here is number one:
https://github.com/espressif/arduino-esp32/issues/3522

There is described, what have to be edit in the WiFiGeneric.cpp to accomplish a wifi disable/enable routine.

{     
    if(!_esp_wifi_started){
    return WIFI_MODE_NULL;
    }
}

I wouldn't say that it does not work. It actually does in a way... There are a lot of delays in my code above on purpose and my cell phone is my access point for this example. I can see how the ESP32 connects to my phone but after disconnecting and disabling wifi, the connection still exists just before the loop repeats. I can see that the ESP32 disconnects very short and reconnect again. I also did power measurements and there are no changes between WIFI_OFF and the new loop.

The second solution I found is here:
https://github.com/espressif/arduino-esp32/commit/80e9e42c3b7a8ad646cd8803c9f4f84e35c9ebb1

I changed the WiFiGeneric.cpp as described and this will cause an other problem. I dont get the error as mentioned at the beginning anymore. The wifi connection will be disabled immediately after the function is called (I can see at my phone). The power consumption decreases, it seems wifi is truly off. But im not able to reconnect again:

15:24:07.451 -> Connecting to WiFi..
15:24:07.451 -> Connected!
15:24:17.473 -> Wifi disconnected
15:24:17.473 -> Wifi OFF
15:24:33.462 -> Connecting to WiFi..
15:24:34.469 -> Connecting to WiFi..
15:24:35.478 -> Connecting to WiFi..
15:24:36.457 -> Connecting to WiFi..
15:24:37.465 -> Connecting to WiFi..

Any ideas?

@stale
Copy link

stale bot commented Jun 20, 2021

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Jun 20, 2021
@stale
Copy link

stale bot commented Jul 8, 2021

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

1 participant