mirror of
				https://github.com/espressif/esp-idf.git
				synced 2025-10-31 13:09:38 +00:00 
			
		
		
		
	wifi_prov_mgr: Add Kconfig option to restart provisioning
This commit is contained in:
		| @@ -20,6 +20,24 @@ menu "Example Configuration" | ||||
|         default 1 if EXAMPLE_PROV_TRANSPORT_BLE | ||||
|         default 2 if EXAMPLE_PROV_TRANSPORT_SOFTAP | ||||
|  | ||||
|     config EXAMPLE_RESET_PROV_MGR_ON_FAILURE | ||||
|         bool | ||||
|         default y | ||||
|         prompt "Reset provisioned credentials and state machine after session failure" | ||||
|         help | ||||
|             Enable reseting provisioned credentials and state machine after session failure. | ||||
|             This will restart the provisioning service after retries are exhausted. | ||||
|  | ||||
|     config EXAMPLE_PROV_MGR_MAX_RETRY_CNT | ||||
|         int | ||||
|         default 5 | ||||
|         prompt "Max retries before reseting provisioning state machine" | ||||
|         depends on EXAMPLE_RESET_PROV_MGR_ON_FAILURE | ||||
|         help | ||||
|             Set the Maximum retry to avoid reconnecting to an inexistent AP or if credentials | ||||
|             are misconfigured. Provisioned credentials are erased and internal state machine | ||||
|             is reset after this threshold is reached. | ||||
|  | ||||
|     config EXAMPLE_PROV_SHOW_QR | ||||
|         bool "Show provisioning QR code" | ||||
|         default y | ||||
|   | ||||
| @@ -45,6 +45,9 @@ static EventGroupHandle_t wifi_event_group; | ||||
| static void event_handler(void* arg, esp_event_base_t event_base, | ||||
|                           int32_t event_id, void* event_data) | ||||
| { | ||||
| #ifdef CONFIG_EXAMPLE_RESET_PROV_MGR_ON_FAILURE | ||||
|     static int retries; | ||||
| #endif | ||||
|     if (event_base == WIFI_PROV_EVENT) { | ||||
|         switch (event_id) { | ||||
|             case WIFI_PROV_START: | ||||
| @@ -64,10 +67,21 @@ static void event_handler(void* arg, esp_event_base_t event_base, | ||||
|                          "\n\tPlease reset to factory and retry provisioning", | ||||
|                          (*reason == WIFI_PROV_STA_AUTH_ERROR) ? | ||||
|                          "Wi-Fi station authentication failed" : "Wi-Fi access-point not found"); | ||||
| #ifdef CONFIG_EXAMPLE_RESET_PROV_MGR_ON_FAILURE | ||||
|                 retries++; | ||||
|                 if (retries >= CONFIG_EXAMPLE_PROV_MGR_MAX_RETRY_CNT) { | ||||
|                     ESP_LOGI(TAG, "Failed to connect with provisioned AP, reseting provisioned credentials"); | ||||
|                     wifi_prov_mgr_reset_sm_state_on_failure(); | ||||
|                     retries = 0; | ||||
|                 } | ||||
| #endif | ||||
|                 break; | ||||
|             } | ||||
|             case WIFI_PROV_CRED_SUCCESS: | ||||
|                 ESP_LOGI(TAG, "Provisioning successful"); | ||||
| #ifdef CONFIG_EXAMPLE_RESET_PROV_MGR_ON_FAILURE | ||||
|                 retries = 0; | ||||
| #endif | ||||
|                 break; | ||||
|             case WIFI_PROV_END: | ||||
|                 /* De-initialize manager once provisioning is finished */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Shubham Kulkarni
					Shubham Kulkarni