Page 1 of 1

Changing AP SSID/Pass after start up

Posted: Fri Jul 13, 2018 3:21 pm
by FShiwani
Hey,

I have a bit of an issue. I'm basically trying to create a function that will accept a new SSID and Password and will automatically update the configuration. Initially, the device will use a default SSID/Pass and purpose of this function is to make it easy to change the SSID/Pass.

Setting the wifi_config_t is fine with you use a macro with the SSID/Pass defined but since I don't know what SSID/Pass the user will input, I'm using two function arguments - char* AP_SSID and char* AP_PASS. And that's the issue. Everytime I set the .ap -> .ssid to this char *, I get an error - "missing braces before initializer..").

Code: Select all

//-------------- Doesn't work -------------------------------------------------//
void wifi_configure_AP(char* AP_SSID, char* AP_PASS){
  wifi_config_t wifi_ap_config = {
    .ap = {
        .ssid = AP_SSID,
        .ssid_len = strlen(AP_SSID),
        .password = AP_PASS,
        .max_connection = DEFAULT_ESP_AP_MAX_STA_CONN,
        .authmode = WIFI_AUTH_WPA_WPA2_PSK
    },
  };
  ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_ap_config));
}
 
// In main
wifi_configure_AP("testSSID", "testPass");
 
//-------------- Works -------------------------------------------------//
#define AP_SSID                     "testSSID"
#define AP_PASS                     "testPass"
 
void wifi_configure_AP(){
  wifi_config_t wifi_ap_config = {
    .ap = {
        .ssid = AP_SSID,
        .ssid_len = strlen(AP_SSID),
        .password = AP_PASS,
        .max_connection = DEFAULT_ESP_AP_MAX_STA_CONN,
        .authmode = WIFI_AUTH_WPA_WPA2_PSK
    },
  };
  ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_ap_config));
}
 
// In main
wifi_configure_AP();

Also, one last thing. Is there "restart AP" function that I can use to update my AP to the new SSID/Pass. Or does it automatically realize that the config has changed and automatically updates it?