Our goal is to turn on station wifi mode on and start connecting via MQTT after boot, but having it boot with it off first. We want to save on power consumption. We want to read off the I2C bus first, and use data from reads to determine whether we should turn on WiFi or not. We use mjs for prototyping, but did attempt to import create custom c function(s) to achieve.
We first tried changing the config, with no reboot, this did not enable wifi as we expected. We did not see the power consumption jump that would indicate the WiFi peripherals were enabled. We would need to reboot to have the config changes applied, but that would be inconvenient, but if we need to do so, that is the best option we have so far.
We next tried creating a custom function as mentioned above. The logic we attempted to achieve turning on the WiFi without a reboot is below, but this caused a brown out on the device, which we found interesting.
esp_netif_create_default_wifi_sta();
esp_wifi_set_mode(WIFI_MODE_STA);
esp32_wifi_ensure_init();
esp32_wifi_ensure_init();
esp32_wifi_ensure_start();
esp_wifi_connect();
Any thoughts on how turning on the WiFi and connecting via MQTT can be achieved after boot? Thank you very much.