Reconfiguring WiFi without a reboot

  1. My goal is: To reconfigure WiFi credentials without having to reboot. The use case here is that the WiFi credentials were initially misconfigured (wrong password, for example), and I would like the end user to be able to correct the password without rebooting the device. The configuration is done through Bluetooth, so I don’t want the bonding between device and user to be broken.
  2. My actions are: I’ve tried two methods. Each begins with setting the new credentials with mgos_sys_config_set_wifi_sta_ssid() and mgos_sys_config_set_wifi_sta_pass(). I’ve tried (1) calling mgos_wifi_disconnect() and then mgos_wifi_connect(), and (2) trying to reset the WiFi sta like so:
struct mgos_config_wifi_sta sta_config = {
        .enable = true,
        .ssid = ssid,
        .pass = pass,


if (mgos_wifi_setup_sta(&sta_config)) {
        mg_rpc_send_responsef(ri, "ok");
} else {
        mg_rpc_send_responsef(ri, "couldn't set up sta");

where ssid and pass are the new SSID and password, respectively.
3. The result I see is: I’m still connecting to the same network. Trying to set an incorrect password, for example, will not disconnect me from the AP.
4. My expectation & question is: I expect to be able to smoothly change WiFi creds while the device is running without any restarts. Is this possible?



Seems like swapping out my call to mgos_wifi_setup_sta() with mgos_wifi_setup((struct mgos_config_wifi *)mgos_sys_config_get_wifi()) in option 2 does the trick. I guess I was missing something important in my mgos_config_wifi_sta struct?