From 1038d3f6deeb0c56486dd3ee7a40cbeb5f53e73c Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Mon, 5 Jan 2026 17:35:04 -0800 Subject: [PATCH] update: updated code to use network prov from wifi prov --- main/CMakeLists.txt | 3 ++- main/idf_component.yml | 1 + main/networking/wifi/app_wifi.c | 48 ++++++++++++++++----------------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 9887e89d..c855b3af 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -45,7 +45,6 @@ set(MAIN_INCLUDE_DIRS set(MAIN_REQUIRES qrcode - wifi_provisioning coreMQTT coreMQTT-Agent corePKCS11 @@ -58,6 +57,8 @@ set(MAIN_REQUIRES driver ) +set(EXCLUDE_COMPONENTS wifi_provisioning) + idf_component_register( SRCS ${MAIN_SRCS} diff --git a/main/idf_component.yml b/main/idf_component.yml index d09368b1..8c36ff43 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -6,3 +6,4 @@ dependencies: version: "^0.6.0" rules: - if: "idf_version >=5.0" + espressif/network_provisioning: "^1.2.0" diff --git a/main/networking/wifi/app_wifi.c b/main/networking/wifi/app_wifi.c index a7d77f72..6282b04c 100644 --- a/main/networking/wifi/app_wifi.c +++ b/main/networking/wifi/app_wifi.c @@ -24,11 +24,11 @@ #include #endif -#include +#include #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE - #include + #include #else /* CONFIG_APP_WIFI_PROV_TRANSPORT_SOFTAP */ - #include + #include #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ #include @@ -76,15 +76,15 @@ static void event_handler( void * arg, long int event_id, void * event_data ) { - if( event_base == WIFI_PROV_EVENT ) + if( event_base == NETWORK_PROV_EVENT ) { switch( event_id ) { - case WIFI_PROV_START: + case NETWORK_PROV_START: ESP_LOGI( TAG, "Provisioning started" ); break; - case WIFI_PROV_CRED_RECV: + case NETWORK_PROV_WIFI_CRED_RECV: { wifi_sta_config_t * wifi_sta_cfg = ( wifi_sta_config_t * ) event_data; ESP_LOGI( TAG, "Received Wi-Fi credentials" @@ -94,23 +94,23 @@ static void event_handler( void * arg, break; } - case WIFI_PROV_CRED_FAIL: + case NETWORK_PROV_WIFI_CRED_FAIL: { - wifi_prov_sta_fail_reason_t * reason = ( wifi_prov_sta_fail_reason_t * ) event_data; + network_prov_wifi_sta_fail_reason_t * reason = ( network_prov_wifi_sta_fail_reason_t * ) event_data; ESP_LOGE( TAG, "Provisioning failed!\n\tReason : %s" "\n\tPlease reset to factory and retry provisioning", - ( *reason == WIFI_PROV_STA_AUTH_ERROR ) ? + ( *reason == NETWORK_PROV_WIFI_STA_AUTH_ERROR ) ? "Wi-Fi station authentication failed" : "Wi-Fi access-point not found" ); break; } - case WIFI_PROV_CRED_SUCCESS: + case NETWORK_PROV_WIFI_CRED_SUCCESS: ESP_LOGI( TAG, "Provisioning successful" ); break; - case WIFI_PROV_END: + case NETWORK_PROV_END: /* De-initialize manager once provisioning is finished */ - wifi_prov_mgr_deinit(); + network_prov_mgr_deinit(); break; default: @@ -265,7 +265,7 @@ void app_wifi_init( void ) wifi_event_group = xEventGroupCreate(); /* Register our event handler for Wi-Fi, IP and Provisioning related events */ - ESP_ERROR_CHECK( esp_event_handler_register( WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL ) ); + ESP_ERROR_CHECK( esp_event_handler_register( NETWORK_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL ) ); ESP_ERROR_CHECK( esp_event_handler_register( WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL ) ); ESP_ERROR_CHECK( esp_event_handler_register( IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL ) ); @@ -280,14 +280,14 @@ void app_wifi_init( void ) esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) { /* Configuration for the provisioning manager */ - wifi_prov_mgr_config_t config = + network_prov_mgr_config_t config = { /* What is the Provisioning Scheme that we want ? * wifi_prov_scheme_softap or wifi_prov_scheme_ble */ #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE - .scheme = wifi_prov_scheme_ble, + .scheme = network_prov_scheme_ble, #else /* CONFIG_APP_WIFI_PROV_TRANSPORT_SOFTAP */ - .scheme = wifi_prov_scheme_softap, + .scheme = network_prov_scheme_softap, #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ /* Any default scheme specific event handler that you would @@ -299,7 +299,7 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) * to take care of this automatically. This can be set to * WIFI_PROV_EVENT_HANDLER_NONE when using wifi_prov_scheme_softap*/ #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE - .scheme_event_handler = WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM + .scheme_event_handler = NETWORK_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM #else /* CONFIG_APP_WIFI_PROV_TRANSPORT_SOFTAP */ .scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE, #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ @@ -307,11 +307,11 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) /* Initialize provisioning manager with the * configuration parameters set above */ - ESP_ERROR_CHECK( wifi_prov_mgr_init( config ) ); + ESP_ERROR_CHECK( network_prov_mgr_init( config ) ); bool provisioned = false; /* Let's find out if the device is provisioned */ - ESP_ERROR_CHECK( wifi_prov_mgr_is_provisioned( &provisioned ) ); + ESP_ERROR_CHECK( network_prov_mgr_is_wifi_provisioned( &provisioned ) ); /* If device is not yet provisioned start provisioning service */ if( !provisioned ) @@ -335,7 +335,7 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) * using X25519 key exchange and proof of possession (pop) and AES-CTR * for encryption/decryption of messages. */ - wifi_prov_security_t security = WIFI_PROV_SECURITY_1; + network_prov_security_t security = NETWORK_PROV_SECURITY_1; /* Do we want a proof-of-possession (ignored if Security 0 is selected): * - this should be a string with length > 0 @@ -374,7 +374,7 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) 0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02, }; - err = wifi_prov_scheme_ble_set_service_uuid( custom_service_uuid ); + err = network_prov_scheme_ble_set_service_uuid( custom_service_uuid ); if( err != ESP_OK ) { @@ -384,7 +384,7 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ /* Start provisioning service */ - ESP_ERROR_CHECK( wifi_prov_mgr_start_provisioning( security, pop, service_name, service_key ) ); + ESP_ERROR_CHECK( network_prov_mgr_start_provisioning( security, pop, service_name, service_key ) ); /* Print QR code for provisioning */ #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE app_wifi_print_qr( service_name, pop, PROV_TRANSPORT_BLE ); @@ -399,7 +399,7 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) /* We don't need the manager as device is already provisioned, * so let's release it's resources */ - wifi_prov_mgr_deinit(); + network_prov_mgr_deinit(); /* Start Wi-Fi station */ wifi_init_sta(); @@ -413,4 +413,4 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) void vWaitOnWifiConnected( void ) { xEventGroupWaitBits( wifi_event_group, WIFI_CONNECTED_EVENT, false, true, portMAX_DELAY ); -} +} \ No newline at end of file