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

Proper way of restarting WiFi after WiFi.mode(WIFI_OFF); #3794

Closed
thezenox opened this issue Mar 6, 2020 · 6 comments
Closed

Proper way of restarting WiFi after WiFi.mode(WIFI_OFF); #3794

thezenox opened this issue Mar 6, 2020 · 6 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@thezenox
Copy link

thezenox commented Mar 6, 2020

I am running an Upload Task connecting to a WiFiAP (doing a scan and select the best Network) and uploading stuff. If finished uploading, wifi is turned off and the task is deleted.
If I want to upload again, the task ist created again, but I get:
E (345591) wifi: esp_wifi_scan_start 1245 wifi not start

So what is the proper way of turning WiFi off completly (reduce power consumption) and enabeling it again? I already tried different things but can't get it working.

Currently I am doing this:
Start WiFi (only relevant code):

WiFi.mode(WIFI_MODE_STA); // calls esp_wifi_set_mode(WIFI_MODE_STA); and esp_wifi_start();
WiFi.enableSTA(true);
scanResult = WiFi.scanNetworks(); // doing scan
if(scanResult > 0){
 WiFi.begin(ssid, pw); // connecting the best network I have the key for
}

End WiFi:

WiFi.disconnect(true); // calls esp_wifi_disconnect(); and WiFi.enableSTA(false);
WiFi.mode(WIFI_OFF); // calls esp_wifi_stop(); and wifiLowLevelDeinit(); in espWiFiStop();, while wifiLowLevelDeinit is doing nothing, yet https://github.com/espressif/arduino-esp32/blob/2f13a960acd1baf1599d855385c64a2716708f85/libraries/WiFi/src/WiFiGeneric.cpp#L128

Debug results for wifi start (only on first call, nothing if recreating the task):

[D][WiFiGeneric.cpp:332] _eventCallback(): Event: 2 - STA_START
[D][WiFiGeneric.cpp:332] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:332] _eventCallback(): Event: 1 - SCAN_DONE

Wifi end gives

[D][WiFiGeneric.cpp:332] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:348] _eventCallback(): Reason: 8 - ASSOC_LEAVE
[D][WiFiGeneric.cpp:332] _eventCallback(): Event: 3 - STA_STOP

When ending wifi task again because of timeout, I get:
E (505690) wifi: esp_wifi_disconnect 1153 wifi not start

Any Idea what is happening here and how to restart wifi again?

@maribeiro
Copy link

There seems to be a bug on the WifiGeneric class
See #3522

@stale
Copy link

stale bot commented May 5, 2020

[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 May 5, 2020
@stale
Copy link

stale bot commented May 19, 2020

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

@stale stale bot closed this as completed May 19, 2020
@NOUSHADO
Copy link

NOUSHADO commented Mar 26, 2021

Dear i am having facing the issue of esp32 Nod mcu going offline i have tried many but , it was suitable your code
i was used in expalexa program exactly working fine
but i am not able to add this code in blynk esp32 program code it was getting error
for this can you suggest me how to use it
any way thanking you very much

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
void setup()
WiFi.mode(WIFI_MODE_STA); // calls esp_wifi_set_mode(WIFI_MODE_STA); and esp_wifi_start();
WiFi.enableSTA(true);
scanResult = WiFi.scanNetworks(); // doing scan
if(scanResult > 0){
WiFi.begin(ssid, pw); // connecting the best network I have the key for
}

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

void setup()
{
// Debug console
Serial.begin(9600);

Blynk.begin(auth, ssid, pass);
}

void loop()
{
Blynk.run();
}

@NOUSHADO
Copy link

this is the error

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "WeMos WiFi&Bluetooth Battery, 80MHz, 921600, None"

BlynkESP32googleamazone26-03-2021-1:40:1: error: expected initializer before 'WiFi'

WiFi.mode(WIFI_MODE_STA); // calls esp_wifi_set_mode(WIFI_MODE_STA); and esp_wifi_start();

^

BlynkESP32googleamazone26-03-2021-1:41:1: error: 'WiFi' does not name a type

WiFi.enableSTA(true);

^

BlynkESP32googleamazone26-03-2021-1:42:1: error: 'scanResult' does not name a type

scanResult = WiFi.scanNetworks(); // doing scan

^

BlynkESP32googleamazone26-03-2021-1:43:1: error: expected unqualified-id before 'if'

if(scanResult > 0){

^

Multiple libraries were found for "WiFi.h"

Used: C:\Users\noush\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.5\libraries\WiFi

Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\libraries\WiFi

exit status 1

expected initializer before 'WiFi'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

@YordanYanakiev
Copy link

YordanYanakiev commented Jun 29, 2021

static bool wifiLowLevelDeinit(){
    //deinit not working yet!
    //esp_wifi_deinit();
    return true;
}

found this inside the WiFiGeneric.cpp .. (line 148)

so.. the deinit is not going to do anything...

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

4 participants