Hello everyone,
I am working on an application where I am using the BLE Nordic UART service (NUS) with a changed service UUID. I need to be able to uninitialize the service after a while so it should only be available after startup for a certain time.
My thought was to enable CONFIG_BT_GATT_DYNAMIC_DB so the bt_gatt_service_register/unregister functions can be used.
Therefore a service object with type struct bt_gatt_service is needed (instead of struct bt_gatt_service_static), so I replaced this service declaration:
/* UART Service Declaration */ BT_GATT_SERVICE_DEFINE(nus_svc, BT_GATT_PRIMARY_SERVICE(BT_UUID_NUS_SERVICE), BT_GATT_CHARACTERISTIC(BT_UUID_NUS_TX, BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ, NULL, NULL, NULL), BT_GATT_CCC(nus_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), BT_GATT_CHARACTERISTIC(BT_UUID_NUS_RX, BT_GATT_CHRC_WRITE | BT_GATT_CHRC_WRITE_WITHOUT_RESP, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, NULL, on_receive, NULL), );
with this code:
#define BT_NUS_SERVICE_DEFINITION { \ BT_GATT_PRIMARY_SERVICE(BT_UUID_NUS_SERVICE), \ BT_GATT_CHARACTERISTIC(BT_UUID_NUS_TX, \ BT_GATT_CHRC_NOTIFY, \ BT_GATT_PERM_READ, \ NULL, NULL, NULL), \ BT_GATT_CCC(nus_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), \ BT_GATT_CHARACTERISTIC(BT_UUID_NUS_RX, \ BT_GATT_CHRC_WRITE | \ BT_GATT_CHRC_WRITE_WITHOUT_RESP, \ BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, \ NULL, on_receive, NULL), \ } static struct bt_gatt_attr attr_nus_svc[] = BT_NUS_SERVICE_DEFINITION; static struct bt_gatt_service nus_svc = { .attrs = attr_nus_svc, .attr_count = ARRAY_SIZE(attr_nus_svc), };
Is this the right way to this, or am I missing something?
Thanks in advance!