Cannot use NimBLE and WiFi provisioning together

brahmajit
Posts: 24
Joined: Wed Sep 08, 2021 10:31 am

Cannot use NimBLE and WiFi provisioning together

Postby brahmajit » Sat Mar 05, 2022 5:45 am

I'm trying to start wifi provisioning while using NimBLE SPP example. Basically if get a message like 'prov' I want to deinitialize the nimble and start provisioning. I'm able to do so, i.e. stop the NimBLE SPP example and start provisioning, but once the provisioning ends my device reboots is "Guru Meditation error". Unfortunately I'm not that experienced to understand what actually the error is, can anyone help?

Code:

spp example code:

Code: Select all

if (strcmp((const char *)msg, "prov") == 0) {
	esp_nimble_hci_and_controller_deinit();

	// calling this function is causing reboot.
	if (init_provision() == ESP_OK)
		ESP_LOGI("main", "Provisioning successful");

	nimble_port_freertos_deinit();
provisioning code:

Code: Select all

esp_err_t init_provision(void)
	/* Initialize NVS partition */
	esp_err_t ret = nvs_flash_init();
	if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
	    ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
		ESP_ERROR_CHECK(nvs_flash_erase());
		ESP_ERROR_CHECK(nvs_flash_init());
	}

	ESP_ERROR_CHECK(esp_netif_init());

	ESP_ERROR_CHECK(esp_event_loop_create_default());
	wifi_event_group = xEventGroupCreate();

	ESP_ERROR_CHECK(esp_event_handler_register(
		WIFI_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));

	esp_netif_create_default_wifi_sta();

	wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
	ESP_ERROR_CHECK(esp_wifi_init(&cfg));

	wifi_prov_mgr_config_t config = {
		.scheme = wifi_prov_scheme_ble,
		.scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE
	};

	ESP_ERROR_CHECK(wifi_prov_mgr_init(config));

	bool provisioned = false;
	wifi_prov_mgr_reset_provisioning();

	ESP_ERROR_CHECK(wifi_prov_mgr_is_provisioned(&provisioned));

	if (!provisioned) {
		ESP_LOGI(TAG, "Starting provisioning");

		char service_name[12];
		get_device_service_name(service_name, sizeof(service_name));
		wifi_prov_security_t security = WIFI_PROV_SECURITY_1;
		const char *pop = "abcd1234";
		const char *service_key = NULL;
		ESP_ERROR_CHECK(wifi_prov_mgr_start_provisioning(
			security, pop, service_name, service_key));
		wifi_prov_mgr_wait();
		wifi_prov_mgr_deinit();
	} else {
		ESP_LOGI(TAG, "Already provisioned, starting Wi-Fi STA");
	}

	/*
	 *[> Wait for Wi-Fi connection <]
	 *xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_EVENT, false,
	 *true, portMAX_DELAY);
	 */
	return ESP_OK;
}
Logs:

Code: Select all

Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x400945db  PS      : 0x00060233  A0      : 0x80093c19  A1      : 0x3ffd1e10
0x400945db: uxListRemove at /home/gogo/esp/esp-idf/components/freertos/FreeRTOS-Kernel/list.c:206

A2      : 0x3ffdcb88  A3      : 0x3ffc35c0  A4      : 0x3ffbf1b0  A5      : 0x00060223
A6      : 0x00000000  A7      : 0x00000001  A8      : 0x00000000  A9      : 0x3ffc3644
A10     : 0x3ffc3644  A11     : 0x00000000  A12     : 0x00000001  A13     : 0x00060223
A14     : 0x00000003  A15     : 0x00060023  SAR     : 0x00000004  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000004  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffa


Backtrace:0x400945d8:0x3ffd1e100x40093c16:0x3ffd1e30 0x400e592a:0x3ffd1e50 0x400d6fff:0x3ffd1e70 0x400e3245:0x3ffd1ea0 0x400e3286:0x3ffd1ed0 0x400e8fd2:0x3ffd1f10 0x400e9877:0x3ffd1f40 0x400ea129:0x3ffd1f60 0x400ddefd:0x3ffd1f90 0x400dddbe:0x3ffd1fc0 0x400dd4b5:0x3ffd1ff0 0x400dd4c7:0x3ffd2010 0x400e5ef2:0x3ffd2030 0x400d6f2f:0x3ffd2050 0x40094639:0x3ffd2070
0x400945d8: uxListRemove at /home/gogo/esp/esp-idf/components/freertos/FreeRTOS-Kernel/list.c:200

0x40093c16: vTaskDelete at /home/gogo/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:1349 (discriminator 4)

0x400e592a: nimble_port_freertos_deinit at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/src/nimble_port_freertos.c:57

0x400d6fff: ble_svc_gatt_handler at /home/gogo/Documents/work/idf_projects/walk/main/ble_spp_server.c:299

0x400e3245: ble_gatts_val_access at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_gatts.c:395

0x400e3286: ble_gatts_chr_val_access at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_gatts.c:421

0x400e8fd2: ble_att_svr_write at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_att_svr.c:524

0x400e9877: ble_att_svr_write_handle at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_att_svr.c:555

0x400ea129: ble_att_svr_rx_write at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_att_svr.c:2001

0x400ddefd: ble_att_rx at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_att.c:503

0x400dddbe: ble_hs_hci_evt_acl_process at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_hs_hci_evt.c:927

0x400dd4b5: ble_hs_process_rx_data_queue at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_hs.c:238

0x400dd4c7: ble_hs_event_rx_data at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_hs.c:532

0x400e5ef2: ble_npl_event_run at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h:125
 (inlined by) nimble_port_run at /home/gogo/esp/esp-idf/components/bt/host/nimble/nimble/porting/nimble/src/nimble_port.c:78

0x400d6f2f: ble_spp_server_host_task at /home/gogo/Documents/work/idf_projects/walk/main/ble_spp_server.c:236

0x40094639: vPortTaskWrapper at /home/gogo/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:141

Who is online

Users browsing this forum: Bing [Bot], Gaston1980, Majestic-12 [Bot] and 257 guests