Hello -
I have been using the ESP32/NimBLE preview branch and have had good success getting our BLE central and peripheral apps running with the NimBLE APIs. Everything I've tried works as expected. It is also great that the stack requires less RAM compared to the Bluedroid implementation. In my testing we get back about 29 KB RAM.
One issue we have bumped into is not knowing how to cleanly shutdown the ESP32+NimBLE stack. All the example apps loop forever with no apparent cleanup. In our case, we need the ability to shutdown BLE while the app is running to conserve energy and RAM. Then on-demand we re-initialize BLE to perform certain functions.
The APIs to terminate the ESP32/Bluedroid stack are well documented and we use them. I didn't see anything similar for the ESP32/NimBLE stack. Could you please let us know the calls required to shutdown the ESP32/NimBLE stack, such that the stack can be restarted at some point later on-demand? For reference, here are the calls we currently use to initialize the NimBLE stack for a BLE server:
esp_nimble_hci_and_controller_init();
nimble_port_init();
ble_hs_cfg.reset_cb = nimble_on_reset;
ble_hs_cfg.sync_cb = nimble_on_sync;
ble_hs_cfg.gatts_register_cb = nimble_on_register;
ble_svc_gatt_init();
nimble_port_freertos_init(ble_host_task);
void nimble_host_task(void *param)
{
nimble_port_run();
}
void ble_host_task(void *param)
{
nimble_host_task(param);
}
Best regards,
Brian
@bfriedkin Thanks for the overall feedback.
I understand that disabling and then enabling Bluetooth is a valid use case. There is an API to stop the host ble_hs_shutdown() in the NimBLE code, but currently there seems to be no provision to stop and restart different ports (FreeRTOS, Linux etc.) it supports. We will soon be working on this.
@bfriedkin Please pull the latest feature/nimble-preview branch and update the NimBLE submodule too. We have added the support to cleanly close the NimBLE stack. Please refer the documentation here and try it out: https://github.com/espressif/esp-idf/blob/127caf3a04c603b8c289a67d36849c3ef9f269d7/components/nimble/esp-hci/include/esp_nimble_hci.h#L100
@dhrishi -
Thank you for the heads-up. I was able to confirm that the APIs work as expected.
In the esp_nimble_hci.h file, I think there's a typo here:
* ret = esp_nimble_hci_and_controller_deinit();
* if (ret != ESP_OK) {
ESP_LOGE(TAG, "esp_nimble_hci_and_controller_init() failed with error: %d", ret);
* }
Inside the ESP_LOGE, I believe the string should be esp_nimble_hci_and_controller_deinit().
Regards,
Brian
@bfriedkin Oops. I will fix it. Thanks!
Most helpful comment
@bfriedkin Thanks for the overall feedback.
I understand that disabling and then enabling Bluetooth is a valid use case. There is an API to stop the host
ble_hs_shutdown()in the NimBLE code, but currently there seems to be no provision to stop and restart different ports (FreeRTOS, Linux etc.) it supports. We will soon be working on this.