Good approach to disable WiFi?

Adriano
Posts: 9
Joined: Thu Aug 29, 2019 1:04 pm

Good approach to disable WiFi?

Postby Adriano » Mon Dec 19, 2022 9:02 am

Hi,
As the ATMega is always more expensive, there is no reason to use it anymore in projects. Even if you don't need WiFi or BT.

And now my question. On some projects I don't need the WiFi. I can reduce the consumption to 50mA.
I can deactivate the WiFi with:

Code: Select all

#include <WiFi.h>
void setup()
{
  WiFi.disconnect();
  WiFi.mode(WIFI_OFF);
}
But this code increase the program size [+400kB] and the dynamic memory [+25kB].

I can flash this program and then remove the WiFi lines. But if for any reason the WiFi is active again, the ESP will probably crash if I have only a 100mA power supply.

Is there a better solution to deactivate the WiFi without loosing all this memory?

Thanks.
Adriano

bidrohini
Posts: 202
Joined: Thu Oct 27, 2022 12:55 pm

Re: Good approach to disable WiFi?

Postby bidrohini » Mon Dec 19, 2022 10:16 am

Here is a thread that may help: https://esp32.com/viewtopic.php?t=25515

Adriano
Posts: 9
Joined: Thu Aug 29, 2019 1:04 pm

Re: Good approach to disable WiFi?

Postby Adriano » Thu Dec 22, 2022 3:08 pm

bidrohini wrote:
Mon Dec 19, 2022 10:16 am
Here is a thread that may help: https://esp32.com/viewtopic.php?t=25515
Do you mean, I should write a "lite" WiFi library?

I am able to disable the WiFi, but if I use the library to disable the WiFi, the sketch is much bigger and I loose also 25kb of RAM.

bidrohini
Posts: 202
Joined: Thu Oct 27, 2022 12:55 pm

Re: Good approach to disable WiFi?

Postby bidrohini » Fri Dec 23, 2022 7:48 pm

In the thread I posted above, I can see this command

Code: Select all

esp_err_t results = esp_wifi_stop();
Did you try this?

Adriano
Posts: 9
Joined: Thu Aug 29, 2019 1:04 pm

Re: Good approach to disable WiFi?

Postby Adriano » Mon Jan 09, 2023 8:21 am

No it doesn't work.
To be able to use this function, I need to use:

Code: Select all

esp_wifi_init(cfg);
With this call, I loose all the memory (400kb) on the ESP32.

I will wait for the ESP32-P4 :)

boarchuz
Posts: 599
Joined: Tue Aug 21, 2018 5:28 am

Re: Good approach to disable WiFi?

Postby boarchuz » Mon Jan 09, 2023 11:39 am

This is nuts. Don't initialise it. There's nothing to stop.

Adriano
Posts: 9
Joined: Thu Aug 29, 2019 1:04 pm

Re: Good approach to disable WiFi?

Postby Adriano » Mon Jan 09, 2023 4:06 pm

Oh yes. It seems to work.

But why return an error code if it works?

Code: Select all

#include "esp_wifi.h"
void setup()
{
  esp_wifi_set_mode(WIFI_MODE_NULL);
  ...
}
this will disable the WiFi (I lost only 85kb from the flash and 9kb of RAM).

https://github.com/espressif/esp-idf/bl ... ifi.h#L282

esp_wifi_set_mode returns ESP_ERR_WIFI_NOT_INIT. Why return an error, if we don't need to init it to disable the WiFi?

boarchuz
Posts: 599
Joined: Tue Aug 21, 2018 5:28 am

Re: Good approach to disable WiFi?

Postby boarchuz » Mon Jan 09, 2023 4:14 pm

No, don't do anything:

Code: Select all

void setup()
{
}
You don't need to disable it if you haven't enabled it.

Adriano
Posts: 9
Joined: Thu Aug 29, 2019 1:04 pm

Re: Good approach to disable WiFi?

Postby Adriano » Mon Jan 09, 2023 4:19 pm

I don't know if the WiFi is enabled...
When I get a new ESP32, the WiFi could be enabled.

I want to disable it, if enabled. Or at least be sure it is disabled.

ESP_Sprite
Posts: 9577
Joined: Thu Nov 26, 2015 4:08 am

Re: Good approach to disable WiFi?

Postby ESP_Sprite » Tue Jan 10, 2023 12:53 am

Adriano wrote:
Mon Jan 09, 2023 4:19 pm
When I get a new ESP32, the WiFi could be enabled.
It can't be if you don't manually enable it.

Who is online

Users browsing this forum: No registered users and 147 guests