This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to know when a GATT client characteristic is updated

Hi,

I use the Current Time Service to get back the time from a smartphone to have a real time clock with a timer. On the current time service example, the value is read when we press the button.

On my application, I want to be notified when the smartphone updated the time characteristic.

I'm not accustomed with GATT client. I have read message sequence chart in the documentation but I don't understand what is the BLE Event that tell me that the GATT server updated the value in the time characteristic.

Thank you for your help

Parents
  • If you want to notify a peer of changes to the value of a characteristic then you make the characteristic notifyable or indicatable. The peer then subscribes to the characteristic and you send out notifications or indications each time you make a change.

    If you look at the description of the current time service you'll see the Current Time characteristic is notifyable (and it's mandatory to be).

    As far as I can see, the Current Time Service client code (ble_cts_c) doesn't have any code to support subscribing to the characteristic, so you'll have to write your own/add your own. If you look at the code for the ble_hrs_c service however, that does show how to subscribe to notifications, you have to write to the 'cccd' characteristic to enable and disable them, then handle the resultant messages.

    So you need to integrate that subscription and handling code into the Current Time Service code.

Reply
  • If you want to notify a peer of changes to the value of a characteristic then you make the characteristic notifyable or indicatable. The peer then subscribes to the characteristic and you send out notifications or indications each time you make a change.

    If you look at the description of the current time service you'll see the Current Time characteristic is notifyable (and it's mandatory to be).

    As far as I can see, the Current Time Service client code (ble_cts_c) doesn't have any code to support subscribing to the characteristic, so you'll have to write your own/add your own. If you look at the code for the ble_hrs_c service however, that does show how to subscribe to notifications, you have to write to the 'cccd' characteristic to enable and disable them, then handle the resultant messages.

    So you need to integrate that subscription and handling code into the Current Time Service code.

Children
  • Hi RK, thanks for your answer.

    I don't understand very well the service initialization on the Current Time Service client code. It seems that everything is managed in the db_discover_evt_handler(ble_db_discovery_evt_t * p_evt) and that I can get back cccd handle here :

    if (p_evt->params.discovered_db.charateristics[i].characteristic.uuid.uuid ==
                BLE_UUID_CURRENT_TIME_CHAR)
            {
                // Found Current Time characteristic. Store CCCD and value handle and break.
                mp_ble_cts->cts_cccd_handle =
                    p_evt->params.discovered_db.charateristics[i].cccd_handle;
                mp_ble_cts->current_time_handle =
                    p_evt->params.discovered_db.charateristics[i].characteristic.handle_value;
                break;
    

    Do I have to add a BLE CTS event type when I get back notification information from the DB?

Related