Page 1 of 1

Good approach to disable WiFi?

Posted: Mon Dec 19, 2022 9:02 am
by Adriano
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

Re: Good approach to disable WiFi?

Posted: Mon Dec 19, 2022 10:16 am
by bidrohini
Here is a thread that may help: https://esp32.com/viewtopic.php?t=25515

Re: Good approach to disable WiFi?

Posted: Thu Dec 22, 2022 3:08 pm
by Adriano
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.

Re: Good approach to disable WiFi?

Posted: Fri Dec 23, 2022 7:48 pm
by bidrohini
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?

Re: Good approach to disable WiFi?

Posted: Mon Jan 09, 2023 8:21 am
by Adriano
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 :)

Re: Good approach to disable WiFi?

Posted: Mon Jan 09, 2023 11:39 am
by boarchuz
This is nuts. Don't initialise it. There's nothing to stop.

Re: Good approach to disable WiFi?

Posted: Mon Jan 09, 2023 4:06 pm
by Adriano
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?

Re: Good approach to disable WiFi?

Posted: Mon Jan 09, 2023 4:14 pm
by boarchuz
No, don't do anything:

Code: Select all

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

Re: Good approach to disable WiFi?

Posted: Mon Jan 09, 2023 4:19 pm
by Adriano
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.

Re: Good approach to disable WiFi?

Posted: Tue Jan 10, 2023 12:53 am
by ESP_Sprite
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.