make bootstraping code from demo part of component

This commit is contained in:
Morgan Allen 2019-02-22 15:27:02 -08:00
parent f1ff7079fa
commit de55a62409
3 changed files with 26 additions and 10 deletions

View file

@ -19,4 +19,6 @@ uint8_t wifi_manager_add_ap(char *essid, char *password);
void wifi_manager_connect();
EventGroupHandle_t wifi_manager_start();
int wifi_manager_bootstrap_config();
#endif

View file

@ -268,3 +268,26 @@ EventGroupHandle_t wifi_manager_start() {
return wm_event_group;
};
int wifi_manager_bootstrap_config() {
int count = 0;
ESP_LOGI(TAG, "Bootstrapping config from IDF config");
if(strlen(CONFIG_WIFI_MANAGER_TEST_AP) > 0) {
wifi_manager_add_ap(CONFIG_WIFI_MANAGER_TEST_AP, CONFIG_WIFI_MANAGER_TEST_PWD);
count++;
}
if(strlen(CONFIG_WIFI_MANAGER_TEST_AP1) > 0) {
wifi_manager_add_ap(CONFIG_WIFI_MANAGER_TEST_AP1, CONFIG_WIFI_MANAGER_TEST_PWD1);
count++;
}
if(strlen(CONFIG_WIFI_MANAGER_TEST_AP2) > 0) {
wifi_manager_add_ap(CONFIG_WIFI_MANAGER_TEST_AP2, CONFIG_WIFI_MANAGER_TEST_PWD2);
count++;
}
return count;
}

View file

@ -126,16 +126,7 @@ void app_main() {
wifi_manager_reset_store();
if(wifi_manager_ap_count() == 0) {
ESP_LOGI(TAG, "Adding new AP");
if(strlen(CONFIG_WIFI_MANAGER_TEST_AP) > 0)
wifi_manager_add_ap(CONFIG_WIFI_MANAGER_TEST_AP, CONFIG_WIFI_MANAGER_TEST_PWD);
if(strlen(CONFIG_WIFI_MANAGER_TEST_AP1) > 0)
wifi_manager_add_ap(CONFIG_WIFI_MANAGER_TEST_AP1, CONFIG_WIFI_MANAGER_TEST_PWD1);
if(strlen(CONFIG_WIFI_MANAGER_TEST_AP2) > 0)
wifi_manager_add_ap(CONFIG_WIFI_MANAGER_TEST_AP2, CONFIG_WIFI_MANAGER_TEST_PWD2);
wifi_manager_bootstrap_config();
} else {
ESP_LOGI(TAG, "Got AP from store, waiting for connection");
}