Skip to content

Commit ccbb885

Browse files
committed
fix(wifi_prov_mgr): Fixed wifi_prov_mgr_deinit api return type
1. Updated the return type for wifi_prov_mgr_deinit api from void to esp_err_t. 2. Due to void type unable to trace the api failure.
1 parent 78faa25 commit ccbb885

File tree

10 files changed

+53
-16
lines changed

10 files changed

+53
-16
lines changed

components/wifi_provisioning/include/wifi_provisioning/manager.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -280,8 +280,13 @@ esp_err_t wifi_prov_mgr_init(wifi_prov_mgr_config_t config);
280280
* If provisioning service is still active when this API is called,
281281
* it first stops the service, hence emitting WIFI_PROV_END, and
282282
* then performs the de-initialization
283+
*
284+
* @return
285+
* - ESP_OK : Success
286+
* - ESP_FAIL : Failed to post event WIFI_PROV_DEINIT or WIFI_PROV_END
287+
* - ESP_ERR_NO_MEM : Out of memory (as may be returned by esp_event_post)
283288
*/
284-
void wifi_prov_mgr_deinit(void);
289+
esp_err_t wifi_prov_mgr_deinit(void);
285290

286291
/**
287292
* @brief Checks if device is provisioned

components/wifi_provisioning/src/manager.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,11 +1474,13 @@ void wifi_prov_mgr_wait(void)
14741474
RELEASE_LOCK(prov_ctx_lock);
14751475
}
14761476

1477-
void wifi_prov_mgr_deinit(void)
1477+
esp_err_t wifi_prov_mgr_deinit(void)
14781478
{
1479+
esp_err_t ret = ESP_FAIL;
1480+
14791481
if (!prov_ctx_lock) {
1480-
ESP_LOGE(TAG, "Provisioning manager not initialized");
1481-
return;
1482+
ESP_LOGW(TAG, "Provisioning manager not initialized");
1483+
return ESP_OK;
14821484
}
14831485

14841486
ACQUIRE_LOCK(prov_ctx_lock);
@@ -1498,7 +1500,7 @@ void wifi_prov_mgr_deinit(void)
14981500
RELEASE_LOCK(prov_ctx_lock);
14991501
vSemaphoreDelete(prov_ctx_lock);
15001502
prov_ctx_lock = NULL;
1501-
return;
1503+
return ESP_OK;
15021504
}
15031505

15041506
if (prov_ctx->app_info_json) {
@@ -1531,8 +1533,10 @@ void wifi_prov_mgr_deinit(void)
15311533
if (app_cb) {
15321534
app_cb(app_data, WIFI_PROV_END, NULL);
15331535
}
1534-
if (esp_event_post(WIFI_PROV_EVENT, WIFI_PROV_END, NULL, 0, portMAX_DELAY) != ESP_OK) {
1536+
ret = esp_event_post(WIFI_PROV_EVENT, WIFI_PROV_END, NULL, 0, portMAX_DELAY);
1537+
if (ret != ESP_OK) {
15351538
ESP_LOGE(TAG, "Failed to post event WIFI_PROV_END");
1539+
return ret;
15361540
}
15371541
}
15381542

@@ -1545,12 +1549,15 @@ void wifi_prov_mgr_deinit(void)
15451549
if (app_cb) {
15461550
app_cb(app_data, WIFI_PROV_DEINIT, NULL);
15471551
}
1548-
if (esp_event_post(WIFI_PROV_EVENT, WIFI_PROV_DEINIT, NULL, 0, portMAX_DELAY) != ESP_OK) {
1552+
ret = esp_event_post(WIFI_PROV_EVENT, WIFI_PROV_DEINIT, NULL, 0, portMAX_DELAY);
1553+
if (ret != ESP_OK) {
15491554
ESP_LOGE(TAG, "Failed to post event WIFI_PROV_DEINIT");
1555+
return ret;
15501556
}
15511557

15521558
vSemaphoreDelete(prov_ctx_lock);
15531559
prov_ctx_lock = NULL;
1560+
return ESP_OK;
15541561
}
15551562

15561563
esp_err_t wifi_prov_mgr_start_provisioning(wifi_prov_security_t security, const void *wifi_prov_sec_params,

docs/en/api-reference/provisioning/wifi_provisioning.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ The configuration structure :cpp:type:`wifi_prov_mgr_config_t` has a few fields
7676
case WIFI_PROV_CRED_SUCCESS:
7777
ESP_LOGI(TAG, "Provisioning successful");
7878
break;
79-
case WIFI_PROV_END:
79+
case WIFI_PROV_END: {
8080
/* De-initialize manager once provisioning is finished */
81-
wifi_prov_mgr_deinit();
81+
esp_err_t err = wifi_prov_mgr_deinit();
82+
if (err != ESP_OK) {
83+
ESP_LOGE(TAG, "Failed to de-initialize provisioning manager: %s", esp_err_to_name(err));
84+
}
8285
break;
86+
}
8387
default:
8488
break;
8589
}

docs/en/migration-guides/release-6.x/6.0/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Migration from 5.5 to 6.0
88

99
build-system
1010
peripherals
11+
provisioning
1112
security
1213
tools
1314
system
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Provisioning
2+
==================
3+
4+
:link_to_translation:`zh_CN:[中文]`
5+
6+
Breaking Changes
7+
----------------
8+
9+
The return type of :cpp:func:`wifi_prov_mgr_deinit` has been changed from ``void`` to :cpp:type:`esp_err_t`. This change allows applications to properly handle potential failures during provisioning manager deinitialization.

docs/zh_CN/api-reference/provisioning/wifi_provisioning.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ Wi-Fi 配网
7878
break;
7979
case WIFI_PROV_END:
8080
/*配网完成后,反初始化管理器。*/
81-
wifi_prov_mgr_deinit();
81+
esp_err_t err = wifi_prov_mgr_deinit();
82+
if (err != ESP_OK) {
83+
ESP_LOGE(TAG, "Failed to de-initialize provisioning manager: %s", esp_err_to_name(err));
84+
}
8285
break;
8386
default:
8487
break;
@@ -172,7 +175,7 @@ Wi-Fi 配网
172175
{
173176
if (event_base == WIFI_PROV_EVENT && event_id == WIFI_PROV_END) {
174177
/* 配网完成后反初始化管理器 */
175-
wifi_prov_mgr_deinit();
178+
ESP_ERROR_CHECK( wifi_prov_mgr_deinit() );
176179
}
177180
}
178181

docs/zh_CN/migration-guides/release-6.x/6.0/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
build-system
1010
peripherals
11+
provisioning
1112
security
1213
tools
1314
system
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. include:: ../../../../en/migration-guides/release-6.x/6.0/provisioning.rst

examples/network/sta2eth/main/provisioning.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -120,7 +120,10 @@ static void event_handler(void *arg, esp_event_base_t event_base,
120120
break;
121121
case WIFI_PROV_END:
122122
/* De-initialize manager once provisioning is finished */
123-
wifi_prov_mgr_deinit();
123+
esp_err_t err = wifi_prov_mgr_deinit();
124+
if (err != ESP_OK) {
125+
ESP_LOGE(TAG, "Failed to de-initialize provisioning manager: %s", esp_err_to_name(err));
126+
}
124127
xEventGroupSetBits(*handler_args->flags, handler_args->success ? handler_args->success_bit : handler_args->fail_bit);
125128
free(handler_args);
126129
break;

examples/provisioning/wifi_prov_mgr/main/app_main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ static void event_handler(void* arg, esp_event_base_t event_base,
147147
break;
148148
case WIFI_PROV_END:
149149
/* De-initialize manager once provisioning is finished */
150-
wifi_prov_mgr_deinit();
150+
esp_err_t err = wifi_prov_mgr_deinit();
151+
if (err != ESP_OK) {
152+
ESP_LOGE(TAG, "Failed to de-initialize provisioning manager: %s", esp_err_to_name(err));
153+
}
151154
break;
152155
default:
153156
break;
@@ -520,7 +523,7 @@ void app_main(void)
520523

521524
/* We don't need the manager as device is already provisioned,
522525
* so let's release it's resources */
523-
wifi_prov_mgr_deinit();
526+
ESP_ERROR_CHECK(wifi_prov_mgr_deinit());
524527

525528
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
526529
/* Start Wi-Fi station */

0 commit comments

Comments
 (0)