Skip to main content
jampino
Associate III
March 8, 2018
Solved

Updating values

  • March 8, 2018
  • 4 replies
  • 2278 views
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

    This topic has been closed for replies.
    Best answer by Antonio Vilei
    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.

    4 replies

    Antonio Vilei
    ST Employee
    March 9, 2018
    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

    jampino
    jampinoAuthor
    Associate III
    March 9, 2018
    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

    Antonio Vilei
    ST Employee
    March 9, 2018
    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.)

    Antonio Vilei
    ST Employee
    March 9, 2018
    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.

    jampino
    jampinoAuthor
    Associate III
    March 10, 2018
    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

    jampino
    jampinoAuthor
    Associate III
    March 12, 2018
    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

    jampino
    jampinoAuthor
    Associate III
    March 15, 2018
    Posted on March 15, 2018 at 16:52

    Hello,

    I have checked that when I am calling the function with:

    aci_gatt_write_char_desc(

    Connectionhandle, handle+2, length, Value) with length different to 1 I get the error 0x41(Failed) some idea why is that error.

    Thank you

    Andrea Palmieri
    ST Employee
    March 22, 2018
    Posted on March 22, 2018 at 15:36

    Hi Jamp,

    It is strange, because the length should be always 0x02. Is it happening for any char?

    Regards

    Andrea

    jampino
    jampinoAuthor
    Associate III
    March 26, 2018
    Posted on March 26, 2018 at 09:58

    Yes I have it working thanks, I added a waiting time between the calling functions