This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

GATT service bt_gatt_notify argument const structbt_gatt_attr*attr

Hello,


I'm making an own service with a notify.

When I look at the bas service there is the following line to trigger the notifty:

rc = bt_gatt_notify(NULL, &bas.attrs[1], &level, sizeof(level));

Because I have serveral characteristics and the notify is not on the top.

The index of [1] should not be okay.

How can I determine the attribute index of my service?

Is there a easier way to join this, because when I add some attributes the index could change.


Greetings,

Peter

Parents
  • Additional.

    I looked it up by comparing with the address of the variable mentioned in the characteristic

    Something like this.

    for( int i = 0; i < My_service.attr_count; i++)
    {
    	if( My_service.attrs[i].user_data == &my_notify_variable )
    	{
    		attr_index_notify= i;
    	}
    }
    
    ...
    
    bt_gatt_notify(NULL, &My_service.attrs[attr_index_notify], &my_notify_variable, sizeof(my_notify_variable));

    Is this method okay to use it like this?

Reply
  • Additional.

    I looked it up by comparing with the address of the variable mentioned in the characteristic

    Something like this.

    for( int i = 0; i < My_service.attr_count; i++)
    {
    	if( My_service.attrs[i].user_data == &my_notify_variable )
    	{
    		attr_index_notify= i;
    	}
    }
    
    ...
    
    bt_gatt_notify(NULL, &My_service.attrs[attr_index_notify], &my_notify_variable, sizeof(my_notify_variable));

    Is this method okay to use it like this?

Children
No Data
Related