cancel
Showing results for 
Search instead for 
Did you mean: 

Updating values

jampino
Associate II
Posted on March 08, 2018 at 17:26

Hello all, 

I am having a problems to update some values on the master, I am using bluenrg-1 I have one device working as a master and other as a slave. The slave has a button, I have both connected and every time I press the button on the slave  the function aci_gatt_update_char_value() is called containing a value, I have on the slave that configuration:

aci_gatt_add_char( Service_Handle,

UUID_TYPE_128,

&char_uuid,

CHAR_VALUE_LENGTH,

CHAR_PROP_READ|CHAR_PROP_NOTIFY,

ATTR_PERMISSION_NONE,

GATT_DONT_NOTIFY_EVENTS,

ENCRYPTION_KEY_SIZE,

ATT_HAS_FIXED_LENGTH,

&CharHandle);

the master is discovering the service and characteristic from the slave. Do I need to do something more or in a different manner? Which event function will be call on the master?

I can read the values from the master  requesting the value every x time once both are connected but I would like to received the value on the master just the button is pressed. 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on March 09, 2018 at 16:34

You don't have to add characteristic 'A' to the master, as it is a characteristic of your slave. On the master, you just need to call the function aci_gatt_write_char_desc(). When calling it, please make sure to pass the handle of characteristic 'A' of the slave, just as you discovered it on the master, plus 2. So if the handle is h, please use (h+2) as an argument.

View solution in original post

16 REPLIES 16
Antonio Vilei
Senior III
Posted on March 09, 2018 at 12:02

Hi,

if I understood correctly your question, you want your GATT client o receive notifications from the GATT server each time its characteristic is updated, without having to read in it in polling mode. In order to make it work, you have to explicitly enable notifications on the GATT server, so that it can notify the GATT client about changes. To enable notifications, from the GATT client (the master in your case) you need to write the descriptor of the characteristic of the server that you are interested in, by calling the aci_gatt_write_char_desc() function. In this way, each time that the value of the characteristic of the server will change, the client will be notified.

For a working example, you can refer to the 'Project\BLE_Examples\BLE_Chat_Master_Slave' project.

Best regards,

Antonio

Posted on March 09, 2018 at 15:33

Hello Antonio,

Thank you for your answer, yes as you said every time I press the button, a different value will be sent from the slave to the master.

I have used aci_gatt_write_char_desc() just after adding the characteristic on the master but still not receiving anything on the master when I press the button on the slave.

On the slave the notify (

CHAR_PROP_NOTIFY)

is defined when adding the characteristic and the master will discover it when both are connected. I thought a function would be called on the master when the button is pressed on the slave so I can obtain the new value.

Any help with it?

Thank you

Posted on March 09, 2018 at 16:09

I'll try to summarize the steps you need to perform:

1. on the master, after you discover the characteristic of your slave, you must call the aci_gatt_write_char_desc() function on the attribute handle that corresponds to that characteristic (I emphasize here that we're talking about a characteristic of the slave, not of the master). Please notice that

you need to add 2 to the base handle

, as this will let you write the descriptor of your characteristic (handle + 1 is the value of the characteristic, while handle + 2 is the descriptor of the characteristic).

2. When a button is pressed on the slave, you call aci_gatt_update_char_value() on the characteristic you want to update.

3. Whenever the value of the characteristic will change on the slave, on the master you will see that the aci_gatt_notification_event() callback will be fired. Here you can add the code that you want to be executed when the button is pressed on the slave (e.g. read the value and blink an LED accordingly, etc.)

Posted on March 09, 2018 at 16:22

Thank you for your fast response Antonio,

Just a question in case I am doing something wrong.

Lets say I have Characteristic 'A' defined on the slave, the connection between Slave/Master is created and Master discover Characteristic 'A', then on the master should I call aci_gatt_add_char() to add characteristic 'A' or I should not added, just call the function  aci_gatt_write_char_desc().

Thank you

Antonio Vilei
Senior III
Posted on March 09, 2018 at 17:28

I'm glad it works now!

You can add this characteristic also on your master, but you'll have to synchronize the value manually.

Posted on March 09, 2018 at 16:34

You don't have to add characteristic 'A' to the master, as it is a characteristic of your slave. On the master, you just need to call the function aci_gatt_write_char_desc(). When calling it, please make sure to pass the handle of characteristic 'A' of the slave, just as you discovered it on the master, plus 2. So if the handle is h, please use (h+2) as an argument.

Posted on March 09, 2018 at 17:03

Thank you so much for your help, now is working.

I was just wondering if there is any problem on adding that characteristic 'A' on the master when it is discovered. As the master will be working as a master/slave ( slave(a) ==> master / slave(b) ==> master(c) ) so I was thinking about using the same characteristic to just populate the value from the slave(a) to the end master(c).

Thank you

Posted on March 10, 2018 at 17:33

Hi Antonio,

I am having a problem when adding more than one characteristic descriptor. The first one is added but the others are giving me an error (0x46 BLE_STATUS NOT_ALLOWED)

I am calling the function aci_gatt_write_char_desc() once the connection is stablished as I need the Connection Handle.

As you told me, I am passing the handle + 2.

I need to add 3 descriptors, what I am doing is:

aci_gatt_write_char_desc(Connectionhandle, handleA+2,lengthA,Value);

aci_gatt_write_char_desc(Connectionhandle, handleB+2,lengthB,Value);

aci_gatt_write_char_desc(Connectionhandle, handleC+2,lengthC,Value);

Where value is Value ={0x01,0x00}

Thank you

Posted on March 12, 2018 at 14:38

To add more information:

- first handle length is 1 byte.

- first handle length is 6 bytes.

- first handle length is 16 bytes.

Is there any problem about it?

Thank you