BLE characteristic notification under NimBLE stack

azkarate
Posts: 7
Joined: Thu Jun 18, 2020 2:04 pm

BLE characteristic notification under NimBLE stack

Postby azkarate » Thu Jun 18, 2020 2:11 pm

Hello, I am trying to create a BLE peripheral on a ESP32-SOLO-1 using NimBLE Stack. I have successfully created characteristics and I am able to read and write on them, but I can't notify new values to the client.

I have configured the characteristic with read, write and notify flags (.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_NOTIFY) and I try to use ble_gatts_chr_updated(notifiedCharHandle) to notify the client, but the client does not receive the notification. I see that the function returns a 7 as an error identifier, but I can't find the meaning of it.

Thanks in advance,
Jon

azkarate
Posts: 7
Joined: Thu Jun 18, 2020 2:04 pm

Re: BLE characteristic notification under NimBLE stack

Postby azkarate » Mon Jun 22, 2020 2:38 pm

As an update, I am trying to know what do I need to do when a client registers for notification. At the moment I do nothing when I get the BLE_GAP_EVENT_SUBSCRIBE event. I should register the connection somewhere to know which connections are registered and which not, but I cant find how.

azkarate
Posts: 7
Joined: Thu Jun 18, 2020 2:04 pm

Re: BLE characteristic notification under NimBLE stack

Postby azkarate » Tue Aug 31, 2021 2:20 pm

As a follow up, I solved this issue adding a characteristic handle variable to the services' definition structure.

Code: Select all

static const struct ble_gatt_svc_def services[] = {
	.type = BLE_GATT_SVC_TYPE_PRIMARY,
	.uuid = &serviceUUID.u,
	.characteristics = (struct ble_gatt_chr_def[])
	{
		{
			.uuid = &characteristicUUID.u,
			.access_cb = ble_accessCallback,
			.val_handle = &charHandle,  /* I added this pointer to hold the characterisitc handle */
			.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC | BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC | BLE_GATT_CHR_F_NOTIFY,
		},
		{
			0,
		}
	},
	{
		0,
	}
}
Once the characteristic is registered, the variable charHandle holds the characteristic handle and this can be used to call ble_gatts_chr_updated(charHandle) to notify all connected device about value changes on the characteristic.

Who is online

Users browsing this forum: No registered users and 94 guests