how to read and enable notifications for custom UUIDs

Hi there,

I am developing a central in nrf52840 dk using SDK v2.0.0 in VS code. 

The peripheral uses 128 bit custom UUIDs. The peripheral is working fine with nrf connect. With my central dk,

it is possible me to connect with  peripheral and reading services ,characteristics etc. 

 I need to enable notifications for some of the characteristics.  1. How can I enable notifications for custom 128 bit UUID services?

Referring on google, I found that the CCCD has a 128 bit UUID 00002902-0000-1000-8000-00805f9b34fb. Does it is enough to enable notifications?

It is possible me to use BAS and battery percentage is available in central side.

I am adding a small portion code where I use CCDS...

 else if (!bt_uuid_cmp(discover_params.uuid,&tx_chrc_uuid)) {
		//memcpy(&uuid, &ccc128_uuid, sizeof(uuid));
		memcpy(&uuid3, BT_UUID_GATT_CCC, sizeof(uuid3));
		discover_params.uuid = &uuid3.uuid;
		discover_params.start_handle = attr->handle + 2;
		discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR;
		subscribe_params.value_handle = bt_gatt_attr_value_handle(attr);
		err = bt_gatt_discover(conn, &discover_params);
		if (err) {
			printk("Discover failed (err %d)\n", err);
		}
	}	
		
	else {
		subscribe_params.notify = notify_func;
		subscribe_params.value = BT_GATT_CCC_NOTIFY;
		subscribe_params.ccc_handle = attr->handle;

		err = bt_gatt_subscribe(conn, &subscribe_params);
		if (err && err != -EALREADY) {
			printk("Subscribe failed (err %d)\n", err);
		} else {
			printk("[SUBSCRIBED]\n");
		}

		return BT_GATT_ITER_STOP;
	 }

NB:code snippet from callback discover function

Currently, using this code I don't get any notifications . I think it is not entering the call back notify function.

What should be the reason for this?

2. How can I write values to the peripheral? (write without response)

   What should I do for writing it more than once(like in mobile app:nRF connect)

Thanks in Advance...

Parents
  • Hi,

    1. How can I enable notifications for custom 128 bit UUID services?

    Are you able to enable notification when using your phone, so you know that you have added this correctly on the peripheral?

    You can look at how this is done in the Central UART sample and with the Nordic UART Service (NUS), which is a custom service. The function bt_nus_subscribe_receive(), which is called here in central uart, is used to enable notifications of the TX characteristic.

    2. How can I write values to the peripheral? (write without response)

    You can also look at central UART and NUS for this one. The example waits for UART data which it is to send, and then writes to the characteristic with a bt_nus_client_send() call to here. The implementation of the function can be found here: bt_nus_client_send().

    Best regards,

    Marte

Reply
  • Hi,

    1. How can I enable notifications for custom 128 bit UUID services?

    Are you able to enable notification when using your phone, so you know that you have added this correctly on the peripheral?

    You can look at how this is done in the Central UART sample and with the Nordic UART Service (NUS), which is a custom service. The function bt_nus_subscribe_receive(), which is called here in central uart, is used to enable notifications of the TX characteristic.

    2. How can I write values to the peripheral? (write without response)

    You can also look at central UART and NUS for this one. The example waits for UART data which it is to send, and then writes to the characteristic with a bt_nus_client_send() call to here. The implementation of the function can be found here: bt_nus_client_send().

    Best regards,

    Marte

Children
Related