Define a service dynamically

Hi,

I am trying to define a service at runtime because we want that the Service UUID may be changed according to a configuration variable.

I have set CONFIG_BT_GATT_DYNAMIC_DB=y

And added the code:

static struct bt_uuid_128 uuid;
uuid = (struct bt_uuid_128)BT_UUID_INIT_128(0x53, 0xF5, 0x3C, 0x12, 0xF0, 0xD6, 0x25, 0xAD, 0xD6, 0x4E, 0xA6, 0x48, 0x01, 0x00, 0x54, 0xE7);
static struct bt_gatt_attr attr;
attr = (struct bt_gatt_attr)BT_GATT_PRIMARY_SERVICE(&uuid);
static struct bt_gatt_service service;
service = (struct bt_gatt_service) { .attrs = &attr, .attr_count = 1 };
int result = bt_gatt_service_register(&service);
printk("Bluetooth dynamic service registration (result %d)\n", result);

When I test the code printout is:

Bluetooth dynamic service registration (result 0)

But the service is not available, when I connect to my device with a smartphone using the nRF Connect APP.

Can anyone help me?

Br Mads

Parents
  • Hello Mads,

    Thank you for your patience with this.

    Bluetooth dynamic service registration (result 0)

    The result 0 indicates that the operation was a success, and so the new service is added to the ATT table.

    But the service is not available, when I connect to my device with a smartphone using the nRF Connect APP.

    Are you using bonding with your device? Could it be that your smartphone has cached the ATT table from the peripheral device previously, and that your peripheral does not use the 'Services Changed' service to prompt a new discovery from the central device?

    Best regards,
    Karl

Reply
  • Hello Mads,

    Thank you for your patience with this.

    Bluetooth dynamic service registration (result 0)

    The result 0 indicates that the operation was a success, and so the new service is added to the ATT table.

    But the service is not available, when I connect to my device with a smartphone using the nRF Connect APP.

    Are you using bonding with your device? Could it be that your smartphone has cached the ATT table from the peripheral device previously, and that your peripheral does not use the 'Services Changed' service to prompt a new discovery from the central device?

    Best regards,
    Karl

Children
Related