Reding GATT Characterictic value.

Hi All,

I am using the samples/bluetooth/central_hr and samples/bluetooth/peripheral_hr examples form the zephyr tree for evaluating the GATT characteristic value reading. I am getting output like:

 

initialized
Scanning successfully started
[DEVICE]: HeartRateSensor, AD evt type 1, AD data len 11, RSSI -70
[AD]: 1 data_len 11
[UNSUBSCRIBED]
[SUBSCRIBED]
Connected: HeartRateSensor
[ATTRIBUTE] handle 15
[ATTRIBUTE] handle 16
[ATTRIBUTE] handle 18
Discover complete
[NOTIFICATION] data 0x20007df length 2
[NOTIFICATION] data 0x20007df length 2

I know this is the dummy heart rate values from the peripheral_hr.

I want to know if the [NOTIFICATION] data 0x20007fd length 2 is GATT characteristic value or not.

If now how do I print the characteristic value?

Thanks,

Gotak

Parents
  • Hi,

    static uint8_t notify_func(struct bt_conn *conn,
    			   struct bt_gatt_subscribe_params *params,
    			   const void *data, uint16_t length)
    {
    	if (!data) {
    		printk("[UNSUBSCRIBED]\n");
    		params->value_handle = 0U;
    		return BT_GATT_ITER_STOP;
    	}
    
    	printk("[NOTIFICATION] data %p length %u\n", data, length);
    
    	return BT_GATT_ITER_CONTINUE;
    }
    

    The structure "struct bt_gatt_subscribe_params *params"

    from the above function contains the parameters:

    uint16_t value;
    does this store the GATT characteristic value?
  • Hi,

    I have tried the below logic for reading:

    static void read_cb(struct bt_conn *conn, uint8_t err,

                        struct bt_gatt_read_params *params,

                        const void *data, uint16_t length)

    {

     printk("\nread_cb");

        if (err)

        {

            printk("Read failed (err %u)\n", err);

            return;

        }

     else{

      printk("\nGATT_READ");

     }

        printk("Read successful. Value: ");

        for (int i = 0; i < length; i++)

        {

            printk("%02X ", ((uint8_t *)data)[i]);

        }

        printk("\n");

     //bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);

    }

    The output: Read successful. Value: 10 1B 00 37 2A

    37 2A --> are the characteristic UUID which I can recognise

    But what is 10 1B 00??

    Is it the characteristic value?

  • Gotak said:

    But what is 10 1B 00??

    Is it the characteristic value?

    Yes, it is.

  • But in the nRF mobile app if I see the characteristic value it is like 

    Value: (0x) 01

    Are they both considered same values?

  • Hi I actually use the central heart rate monitor example before posting this ticket,

    I am able to hear the GATT data from the peripheral hr example by giving the HRS UUID  to read the GATT characteristic value for the heart rate monitor.

    I wanted to use this example to read by customised gatt UUID characteristics, so I modified the GATT UUID as required and I am able to read some gatt value which is as told in the above reply

    3 bytes + Characteristic UUID

    And as you told they these prefixed 3 bytes are the characteristic value but when I verified it in the nRF mobile app the same characteristic value is like : (0x) 01 which is not equal to the 3 bytes I got in my nRF gatt reading code output...

  • I am not sure of all the code on the central (here) and peripheral (GATT server) so there may be something I am not aware of regardign what this data represetn, but in any case, the read callback holds the data. It might be easier to test with something like the NUS central and peripheral samples, where you clearly have just a data "channel".

Reply Children
No Data
Related