NimBLE adding new characteristic to existing service in runtime

Ildar Belkin
Posts: 10
Joined: Mon Apr 24, 2023 3:16 pm

NimBLE adding new characteristic to existing service in runtime

Postby Ildar Belkin » Tue Feb 27, 2024 3:41 pm

Hello.
Im trying to use base example to using Nimble:

Code: Select all

...
static const struct ble_gatt_svc_def gatt_svcs[] = {
    {.type = BLE_GATT_SVC_TYPE_PRIMARY,
     .uuid = BLE_UUID16_DECLARE(0x180),                 // Define UUID for device type
     .characteristics = (struct ble_gatt_chr_def[]){
         {.uuid = BLE_UUID16_DECLARE(0xFEF4),           // Define UUID for reading
          .flags = BLE_GATT_CHR_F_READ,
          .access_cb = device_read},
         {.uuid = BLE_UUID16_DECLARE(0xDEAD),           // Define UUID for writing
          .flags = BLE_GATT_CHR_F_WRITE,
          .access_cb = device_write},
         {0}}},
    {0}
};
....

    nvs_flash_init();                          // 1 - Initialize NVS flash using
    esp_nimble_hci_init();      			   // 2 - Initialize ESP controller
    nimble_port_init();                        // 3 - Initialize the host stack
    ble_svc_gap_device_name_set("BLE-Server"); // 4 - Initialize NimBLE configuration - server name
    ble_svc_gap_init();                        // 4 - Initialize NimBLE configuration - gap service
    ble_svc_gatt_init();                       // 4 - Initialize NimBLE configuration - gatt service
    ble_gatts_count_cfg(gatt_svcs);            // 4 - Initialize NimBLE configuration - config gatt services
    ble_gatts_add_svcs(gatt_svcs);             // 4 - Initialize NimBLE configuration - queues gatt services.
    ble_hs_cfg.sync_cb = ble_app_on_sync;      // 5 - Initialize application
    nimble_port_freertos_init(host_task);      // 6 - Run the thread

Everything is working fine.
Please, explain me how to add another one characteristic to existing service when the ESP32 is already working.
I don't ask about 2 characteristic from start. I need to add new characteristic during runtime.

Who is online

Users browsing this forum: Baidu [Spider] and 334 guests