Closing down WiFi to save power

wevets
Posts: 75
Joined: Sat Mar 09, 2019 2:56 am

Closing down WiFi to save power

Postby wevets » Fri Feb 07, 2020 10:37 pm

Not having received a reply in the IoT forum, I thought I'd try this one.

I have an application in which I want to very occasionally start up wifi to POST some data to a remote server. I can get things going and POST the message, but am having trouble with the tear-down phase. As I read the docs, the right steps and the order in which they should be called is:
  1. esp_http_client_cleanup( client ); // dismiss the TCP stack
  2. esp_wifi_disconnect();            // break connection to AP
  3. esp_wifi_stop();                 // shut down the wifi radio
  4. esp_wifi_deinit();              // release wifi resources
When I run this, I get an error from the system apparently during the call to esp_wifi_stop() that says:

"wifi: esp_wifi_connect 1145 wifi not start"

Interestingly, while I can find a declaration of esp_wifi_stop() in a header file, I can not find that function in an executable (.c) file, so I can't dig into the code myself.

Can someone can tell me the correct way to tear down tcp and wifi stacks and dismiss all the resources with no memory leaks without throwing an error? That is, what functions to call and in what order?

ESP_igrr
Posts: 1592
Joined: Tue Dec 01, 2015 8:37 am

Re: Closing down WiFi to save power

Postby ESP_igrr » Sat Feb 08, 2020 8:38 pm

The sequence of calls looks okay... Given that the error message contains "esp_wifi_connect", i would venture a guess that you have a "Wi-Fi disconnected" event handler in your application, which calls esp_wifi_connect whenever disconnection occurs. In this case you need to disable this event handler, or pass some flag to it so that it doesn't try to reconnect when you actually want to disable Wi-Fi.

All that said, the message is likely harmless, and Wi-Fi does end up getting disabled.

wevets
Posts: 75
Joined: Sat Mar 09, 2019 2:56 am

Re: Closing down WiFi to save power

Postby wevets » Sun Feb 09, 2020 7:18 am

Thanks,

That seems to have been the problem. I just added a flag, WiFiShuttingDown, that I set pdFALSE when I initialized the WiFi stack, and set pdTRUE when I wanted to tear it down, and a conditional in the WiFi event handler that allowed calling esp_wifi_connect() only when WiFiShuttingDown was false.

Who is online

Users browsing this forum: No registered users and 26 guests