Skip to content

Commit 27a63c4

Browse files
committed
Examples: Demonstrate the usage of esp_err_to_name
1 parent f891eac commit 27a63c4

File tree

31 files changed

+156
-145
lines changed

31 files changed

+156
-145
lines changed

examples/bluetooth/a2dp_sink/main/main.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,25 @@ void app_main()
8585

8686
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_BLE));
8787

88+
esp_err_t err;
8889
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
89-
if (esp_bt_controller_init(&bt_cfg) != ESP_OK) {
90-
ESP_LOGE(BT_AV_TAG, "%s initialize controller failed\n", __func__);
90+
if ((err = esp_bt_controller_init(&bt_cfg)) != ESP_OK) {
91+
ESP_LOGE(BT_AV_TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(ret));
9192
return;
9293
}
9394

94-
if (esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT) != ESP_OK) {
95-
ESP_LOGE(BT_AV_TAG, "%s enable controller failed\n", __func__);
95+
if ((err = esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT)) != ESP_OK) {
96+
ESP_LOGE(BT_AV_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
9697
return;
9798
}
9899

99-
if (esp_bluedroid_init() != ESP_OK) {
100-
ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed\n", __func__);
100+
if ((err = esp_bluedroid_init()) != ESP_OK) {
101+
ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
101102
return;
102103
}
103104

104-
if (esp_bluedroid_enable() != ESP_OK) {
105-
ESP_LOGE(BT_AV_TAG, "%s enable bluedroid failed\n", __func__);
105+
if ((err = esp_bluedroid_enable()) != ESP_OK) {
106+
ESP_LOGE(BT_AV_TAG, "%s enable bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
106107
return;
107108
}
108109

examples/bluetooth/ble_adv/main/app_bt.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,17 @@ void app_main()
223223

224224
ret = esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
225225
if (ret) {
226-
ESP_LOGI(tag, "Bluetooth controller release classic bt memory failed");
226+
ESP_LOGI(tag, "Bluetooth controller release classic bt memory failed: %s", esp_err_to_name(ret));
227227
return;
228228
}
229229

230-
if (esp_bt_controller_init(&bt_cfg) != ESP_OK) {
231-
ESP_LOGI(tag, "Bluetooth controller initialize failed");
230+
if ((ret = esp_bt_controller_init(&bt_cfg)) != ESP_OK) {
231+
ESP_LOGI(tag, "Bluetooth controller initialize failed: %s", esp_err_to_name(ret));
232232
return;
233233
}
234234

235-
if (esp_bt_controller_enable(ESP_BT_MODE_BLE) != ESP_OK) {
236-
ESP_LOGI(tag, "Bluetooth controller enable failed");
235+
if ((ret = esp_bt_controller_enable(ESP_BT_MODE_BLE)) != ESP_OK) {
236+
ESP_LOGI(tag, "Bluetooth controller enable failed: %s", esp_err_to_name(ret));
237237
return;
238238
}
239239

examples/bluetooth/ble_eddystone/main/esp_eddystone_demo.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ static void esp_eddystone_show_inform(const esp_eddystone_result_t* res)
7979

8080
static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param)
8181
{
82+
esp_err_t err;
83+
8284
switch(event)
8385
{
8486
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
@@ -87,8 +89,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* par
8789
break;
8890
}
8991
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: {
90-
if(param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
91-
ESP_LOGE(DEMO_TAG,"Scan start failed");
92+
if((err = param->scan_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
93+
ESP_LOGE(DEMO_TAG,"Scan start failed: %s", esp_err_to_name(err));
9294
}
9395
else {
9496
ESP_LOGI(DEMO_TAG,"Start scanning...");
@@ -124,8 +126,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* par
124126
break;
125127
}
126128
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:{
127-
if(param->scan_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) {
128-
ESP_LOGE(DEMO_TAG,"Scan stop failed");
129+
if((err = param->scan_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
130+
ESP_LOGE(DEMO_TAG,"Scan stop failed: %s", esp_err_to_name(err));
129131
}
130132
else {
131133
ESP_LOGI(DEMO_TAG,"Stop scan successfully");
@@ -145,7 +147,7 @@ void esp_eddystone_appRegister(void)
145147

146148
/*<! register the scan callback function to the gap module */
147149
if((status = esp_ble_gap_register_callback(esp_gap_cb)) != ESP_OK) {
148-
ESP_LOGE(DEMO_TAG,"gap register error,error code = %x",status);
150+
ESP_LOGE(DEMO_TAG,"gap register error: %s", esp_err_to_name(status));
149151
return;
150152
}
151153
}

examples/bluetooth/ble_ibeacon/main/ibeacon_demo.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ static esp_ble_adv_params_t ble_adv_params = {
6262

6363
static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
6464
{
65+
esp_err_t err;
66+
6567
switch (event) {
6668
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:{
6769
#if (IBEACON_MODE == IBEACON_SENDER)
@@ -79,14 +81,14 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
7981
}
8082
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
8183
//scan start complete event to indicate scan start successfully or failed
82-
if (param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
83-
ESP_LOGE(DEMO_TAG, "Scan start failed");
84+
if ((err = param->scan_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
85+
ESP_LOGE(DEMO_TAG, "Scan start failed: %s", esp_err_to_name(err));
8486
}
8587
break;
8688
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
8789
//adv start complete event to indicate adv start successfully or failed
88-
if (param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
89-
ESP_LOGE(DEMO_TAG, "Adv start failed");
90+
if ((err = param->adv_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
91+
ESP_LOGE(DEMO_TAG, "Adv start failed: %s", esp_err_to_name(err));
9092
}
9193
break;
9294
case ESP_GAP_BLE_SCAN_RESULT_EVT: {
@@ -115,17 +117,17 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
115117
}
116118

117119
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
118-
if (param->scan_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
119-
ESP_LOGE(DEMO_TAG, "Scan stop failed");
120+
if ((err = param->scan_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS){
121+
ESP_LOGE(DEMO_TAG, "Scan stop failed: %s", esp_err_to_name(err));
120122
}
121123
else {
122124
ESP_LOGI(DEMO_TAG, "Stop scan successfully");
123125
}
124126
break;
125127

126128
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
127-
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
128-
ESP_LOGE(DEMO_TAG, "Adv stop failed");
129+
if ((err = param->adv_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS){
130+
ESP_LOGE(DEMO_TAG, "Adv stop failed: %s", esp_err_to_name(err));
129131
}
130132
else {
131133
ESP_LOGI(DEMO_TAG, "Stop adv successfully");
@@ -146,7 +148,7 @@ void ble_ibeacon_appRegister(void)
146148

147149
//register the scan callback function to the gap module
148150
if ((status = esp_ble_gap_register_callback(esp_gap_cb)) != ESP_OK) {
149-
ESP_LOGE(DEMO_TAG, "gap register error, error code = %x", status);
151+
ESP_LOGE(DEMO_TAG, "gap register error: %s", esp_err_to_name(status));
150152
return;
151153
}
152154

@@ -180,7 +182,7 @@ void app_main()
180182
esp_ble_gap_config_adv_data_raw((uint8_t*)&ibeacon_adv_data, sizeof(ibeacon_adv_data));
181183
}
182184
else {
183-
ESP_LOGE(DEMO_TAG, "Config iBeacon data failed, status =0x%x\n", status);
185+
ESP_LOGE(DEMO_TAG, "Config iBeacon data failed: %s\n", esp_err_to_name(status));
184186
}
185187
#endif
186188
}

examples/bluetooth/ble_spp_client/main/spp_client_demo.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
205205
{
206206
uint8_t *adv_name = NULL;
207207
uint8_t adv_name_len = 0;
208+
esp_err_t err;
208209

209210
switch(event){
210211
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
211-
if(param->scan_param_cmpl.status != ESP_BT_STATUS_SUCCESS){
212-
ESP_LOGE(GATTC_TAG, "Scan param set failed");
212+
if((err = param->scan_param_cmpl.status) != ESP_BT_STATUS_SUCCESS){
213+
ESP_LOGE(GATTC_TAG, "Scan param set failed: %s", esp_err_to_name(err));
213214
break;
214215
}
215216
//the unit of the duration is second
@@ -220,15 +221,15 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
220221
}
221222
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
222223
//scan start complete event to indicate scan start successfully or failed
223-
if (param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
224-
ESP_LOGE(GATTC_TAG, "Scan start failed");
224+
if ((err = param->scan_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
225+
ESP_LOGE(GATTC_TAG, "Scan start failed: %s", esp_err_to_name(err));
225226
break;
226227
}
227228
ESP_LOGI(GATTC_TAG, "Scan start successed");
228229
break;
229230
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
230-
if (param->scan_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) {
231-
ESP_LOGE(GATTC_TAG, "Scan stop failed");
231+
if ((err = param->scan_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
232+
ESP_LOGE(GATTC_TAG, "Scan stop failed: %s", esp_err_to_name(err));
232233
break;
233234
}
234235
ESP_LOGI(GATTC_TAG, "Scan stop successed");
@@ -262,8 +263,8 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
262263
break;
263264
}
264265
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
265-
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
266-
ESP_LOGE(GATTC_TAG, "Adv stop failed");
266+
if ((err = param->adv_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS){
267+
ESP_LOGE(GATTC_TAG, "Adv stop failed: %s", esp_err_to_name(err));
267268
}else {
268269
ESP_LOGI(GATTC_TAG, "Stop adv successfully");
269270
}
@@ -510,24 +511,25 @@ void spp_heart_beat_task(void * arg)
510511
void ble_client_appRegister(void)
511512
{
512513
esp_err_t status;
514+
char err_msg[20];
513515

514516
ESP_LOGI(GATTC_TAG, "register callback");
515517

516518
//register the scan callback function to the gap module
517519
if ((status = esp_ble_gap_register_callback(esp_gap_cb)) != ESP_OK) {
518-
ESP_LOGE(GATTC_TAG, "gap register error, error code = %x", status);
520+
ESP_LOGE(GATTC_TAG, "gap register error: %s", esp_err_to_name_r(status, err_msg, sizeof(err_msg)));
519521
return;
520522
}
521523
//register the callback function to the gattc module
522524
if ((status = esp_ble_gattc_register_callback(esp_gattc_cb)) != ESP_OK) {
523-
ESP_LOGE(GATTC_TAG, "gattc register error, error code = %x", status);
525+
ESP_LOGE(GATTC_TAG, "gattc register error: %s", esp_err_to_name_r(status, err_msg, sizeof(err_msg)));
524526
return;
525527
}
526528
esp_ble_gattc_app_register(PROFILE_APP_ID);
527529

528530
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(200);
529531
if (local_mtu_ret){
530-
ESP_LOGE(GATTC_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
532+
ESP_LOGE(GATTC_TAG, "set local MTU failed: %s", esp_err_to_name_r(local_mtu_ret, err_msg, sizeof(err_msg)));
531533
}
532534

533535
cmd_reg_queue = xQueueCreate(10, sizeof(uint32_t));
@@ -606,28 +608,28 @@ void app_main()
606608
nvs_flash_init();
607609
ret = esp_bt_controller_init(&bt_cfg);
608610
if (ret) {
609-
ESP_LOGE(GATTC_TAG, "%s enable controller failed\n", __func__);
611+
ESP_LOGE(GATTC_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
610612
return;
611613
}
612614

613615
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
614616
if (ret) {
615-
ESP_LOGE(GATTC_TAG, "%s enable controller failed\n", __func__);
617+
ESP_LOGE(GATTC_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
616618
return;
617619
}
618620

619621
ESP_LOGI(GATTC_TAG, "%s init bluetooth\n", __func__);
620622
ret = esp_bluedroid_init();
621623
if (ret) {
622-
ESP_LOGE(GATTC_TAG, "%s init bluetooth failed\n", __func__);
624+
ESP_LOGE(GATTC_TAG, "%s init bluetooth failed: %s\n", __func__, esp_err_to_name(ret));
623625
return;
624626
}
625627
ret = esp_bluedroid_enable();
626628
if (ret) {
627-
ESP_LOGE(GATTC_TAG, "%s enable bluetooth failed\n", __func__);
629+
ESP_LOGE(GATTC_TAG, "%s enable bluetooth failed: %s\n", __func__, esp_err_to_name(ret));
628630
return;
629631
}
630-
632+
631633
ble_client_appRegister();
632634
spp_uart_init();
633635
}

examples/bluetooth/ble_spp_server/main/ble_spp_server_demo.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,16 +461,17 @@ static void spp_task_init(void)
461461

462462
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
463463
{
464-
ESP_LOGI(GATTS_TABLE_TAG, "GAP_EVT, event %d\n", event);
464+
esp_err_t err;
465+
ESP_LOGE(GATTS_TABLE_TAG, "GAP_EVT, event %d\n", event);
465466

466467
switch (event) {
467468
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
468469
esp_ble_gap_start_advertising(&spp_adv_params);
469470
break;
470471
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
471472
//advertising start complete event to indicate advertising start successfully or failed
472-
if(param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
473-
ESP_LOGE(GATTS_TABLE_TAG, "Advertising start failed\n");
473+
if((err = param->adv_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
474+
ESP_LOGE(GATTS_TABLE_TAG, "Advertising start failed: %s\n", esp_err_to_name(err));
474475
}
475476
break;
476477
default:
@@ -664,25 +665,25 @@ void app_main()
664665

665666
ret = esp_bt_controller_init(&bt_cfg);
666667
if (ret) {
667-
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed\n", __func__);
668+
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
668669
return;
669670
}
670671

671672
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
672673
if (ret) {
673-
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed\n", __func__);
674+
ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
674675
return;
675676
}
676677

677678
ESP_LOGI(GATTS_TABLE_TAG, "%s init bluetooth\n", __func__);
678679
ret = esp_bluedroid_init();
679680
if (ret) {
680-
ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed\n", __func__);
681+
ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed: %s\n", __func__, esp_err_to_name(ret));
681682
return;
682683
}
683684
ret = esp_bluedroid_enable();
684685
if (ret) {
685-
ESP_LOGE(GATTS_TABLE_TAG, "%s enable bluetooth failed\n", __func__);
686+
ESP_LOGE(GATTS_TABLE_TAG, "%s enable bluetooth failed: %s\n", __func__, esp_err_to_name(ret));
686687
return;
687688
}
688689

examples/bluetooth/blufi/main/blufi_example_main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,24 +380,24 @@ void app_main()
380380
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
381381
ret = esp_bt_controller_init(&bt_cfg);
382382
if (ret) {
383-
BLUFI_ERROR("%s initialize bt controller failed\n", __func__);
383+
BLUFI_ERROR("%s initialize bt controller failed: %s\n", __func__, esp_err_to_name(ret));
384384
}
385385

386386
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
387387
if (ret) {
388-
BLUFI_ERROR("%s enable bt controller failed\n", __func__);
388+
BLUFI_ERROR("%s enable bt controller failed: %s\n", __func__, esp_err_to_name(ret));
389389
return;
390390
}
391391

392392
ret = esp_bluedroid_init();
393393
if (ret) {
394-
BLUFI_ERROR("%s init bluedroid failed\n", __func__);
394+
BLUFI_ERROR("%s init bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
395395
return;
396396
}
397397

398398
ret = esp_bluedroid_enable();
399399
if (ret) {
400-
BLUFI_ERROR("%s init bluedroid failed\n", __func__);
400+
BLUFI_ERROR("%s init bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
401401
return;
402402
}
403403

examples/bluetooth/bt_discovery/main/bt_discovery.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,23 +280,23 @@ void app_main()
280280
ESP_ERROR_CHECK( ret );
281281

282282
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
283-
if (esp_bt_controller_init(&bt_cfg) != ESP_OK) {
284-
ESP_LOGE(GAP_TAG, "%s initialize controller failed\n", __func__);
283+
if ((ret = esp_bt_controller_init(&bt_cfg)) != ESP_OK) {
284+
ESP_LOGE(GAP_TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(ret));
285285
return;
286286
}
287287

288-
if (esp_bt_controller_enable(ESP_BT_MODE_BTDM) != ESP_OK) {
289-
ESP_LOGE(GAP_TAG, "%s enable controller failed\n", __func__);
288+
if ((ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM)) != ESP_OK) {
289+
ESP_LOGE(GAP_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
290290
return;
291291
}
292292

293-
if (esp_bluedroid_init() != ESP_OK) {
294-
ESP_LOGE(GAP_TAG, "%s initialize bluedroid failed\n", __func__);
293+
if ((ret = esp_bluedroid_init()) != ESP_OK) {
294+
ESP_LOGE(GAP_TAG, "%s initialize bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
295295
return;
296296
}
297297

298-
if (esp_bluedroid_enable() != ESP_OK) {
299-
ESP_LOGE(GAP_TAG, "%s enable bluedroid failed\n", __func__);
298+
if ((ret = esp_bluedroid_enable()) != ESP_OK) {
299+
ESP_LOGE(GAP_TAG, "%s enable bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
300300
return;
301301
}
302302

0 commit comments

Comments
 (0)