Page 1 of 1
changing wifi password
Posted: Thu Feb 29, 2024 3:00 pm
by Jimis1
Hi,
I have set up the https_ota_example. The password is set up through menuconfig but is there a way to change the password from inside the code calling a function or something. I couldn't find anything on the documentation
Re: changing wifi password
Posted: Thu Feb 29, 2024 3:47 pm
by MicroController
Re: changing wifi password
Posted: Fri Mar 01, 2024 7:16 am
by Jimis1
Like I said I didn't find how to change the password in the documentation. I don't see the library providing a function for that. Changing the library is not very wise since other updates might change it back
Re: changing wifi password
Posted: Fri Mar 01, 2024 6:27 pm
by ves011
You don't need to change anything. @MicroController pointed you to the right places.
Here is a small example
Code: Select all
bool wifi_join(const char *ssid, const char *pass, int timeout_ms)
{
int bits = 0;
if(isConnected())
wifi_disconnect(1, NULL);
wifi_config_t wifi_config = { 0 };
strlcpy((char *) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
if (pass)
strlcpy((char *) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
esp_wifi_connect();
bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
pdFALSE, pdTRUE, timeout_ms / portTICK_PERIOD_MS);
return (bits & CONNECTED_BIT) != 0;
}
Re: changing wifi password
Posted: Sat Mar 02, 2024 6:50 am
by Jimis1
Thanks a lot ! That's what I was looking for!
I searched for that function and found it here :
esp-idf\examples\system\console\advanced\components\cmd_wifi\cmd_wifi.c
I will test it