add WiFi SSID/password and NVS erase options to menuconfig
This commit is contained in:
30
main/Kconfig
30
main/Kconfig
@@ -20,4 +20,34 @@ menu "espScope Configuration"
|
||||
a file called "./boards/<your board name>.h" and set this to "./boards/your board name.h"
|
||||
Default is boards/default.h which is empty.
|
||||
|
||||
config WIFI_ERASE_NVS
|
||||
bool "Erase NVS WiFi config on boot"
|
||||
default n
|
||||
help
|
||||
Enable to erase stored WiFi credentials from NVS at every boot.
|
||||
Useful when you want to always use the credentials set in
|
||||
menuconfig instead of previously saved ones.
|
||||
|
||||
config WIFI_CONFIGURE
|
||||
bool "Configure WiFi credentials"
|
||||
default n
|
||||
help
|
||||
Enable to set WiFi SSID and Password in menuconfig.
|
||||
If disabled (default), device boots in SoftAP mode
|
||||
for over-the-air provisioning.
|
||||
|
||||
config WIFI_SSID
|
||||
string "WiFi SSID"
|
||||
depends on WIFI_CONFIGURE
|
||||
default ""
|
||||
help
|
||||
WiFi SSID for Station mode.
|
||||
|
||||
config WIFI_PASSWORD
|
||||
string "WiFi Password"
|
||||
depends on WIFI_CONFIGURE
|
||||
default ""
|
||||
help
|
||||
WiFi password for the configured SSID.
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -322,7 +322,12 @@ bool wifi_manager_init_wifi(void) {
|
||||
esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, NULL);
|
||||
esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, NULL);
|
||||
|
||||
// 2. Check NVS
|
||||
// 2. Erase NVS on boot if configured
|
||||
#if CONFIG_WIFI_ERASE_NVS
|
||||
wifi_manager_erase_config();
|
||||
#endif
|
||||
|
||||
// 3. Check NVS
|
||||
nvs_handle_t nvs_handle;
|
||||
char pass[64] = {0};
|
||||
size_t ssid_len = sizeof(ssid);
|
||||
@@ -339,14 +344,19 @@ bool wifi_manager_init_wifi(void) {
|
||||
nvs_close(nvs_handle);
|
||||
}
|
||||
|
||||
// 3. Start Mode
|
||||
// 4. Start Mode
|
||||
if (has_creds && strlen(ssid) > 0) {
|
||||
wifi_init_station(ssid, pass);
|
||||
return false;
|
||||
} else {
|
||||
wifi_init_softap();
|
||||
return true;
|
||||
}
|
||||
#if CONFIG_WIFI_CONFIGURE
|
||||
ESP_LOGI(TAG, "Using Kconfig WiFi credentials for SSID=%s", CONFIG_WIFI_SSID);
|
||||
wifi_init_station(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD);
|
||||
return false;
|
||||
#else
|
||||
wifi_init_softap();
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void wifi_manager_erase_config(void) {
|
||||
|
||||
Reference in New Issue
Block a user