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

How to notify several characteristics in central

Hi, I am using ble_app_hrs_c as the base for central. I have included 5 characteristics in the peripheral and central side. How to make ble_nus_c_rx_notif_enable() to notify when any of the 5 characteristics is updated? At the moment, ble_nus_c_rx_notif_enable has only this: return cccd_configure(p_ble_nus_c->conn_handle,p_ble_nus_c->handles.nus_rx_cccd_handle, true);

How do I change it so that I get notification even when nus_rx_wheel_status_handle also receives a notification? My ble_nus_c_handles_t looks like this:

typedef struct {
    uint16_t                nus_rx_wheel_control_handle;      

    uint16_t                nus_rx_wheel_control_cccd_handle; /**< Handle of the CCCD of the NUS RX characteristic as provided by a discovery. */
    uint16_t                nus_rx_wheel_status_handle;	
    uint16_t                nus_rx_wheel_status_cccd_handle;	
    uint16_t                nus_rx_wheel_battery_handle;	
    uint16_t                nus_rx_wheel_battery_cccd_handle;		
    uint16_t                nus_rx_wheel_information_handle;	
    uint16_t                nus_rx_wheel_information_cccd_handle;		
    uint16_t                nus_rx_wheel_debug_handle;	
    uint16_t                nus_rx_wheel_debug_cccd_handle;		
    uint16_t                nus_tx_handle_wheel_control;      /**< Handle of the NUS TX characteristic as provided by a discovery. */
    uint16_t                nus_tx_handle_wheel_status;	
    uint16_t                nus_tx_handle_wheel_battery;	
    uint16_t                nus_tx_handle_wheel_information;		
    uint16_t                nus_tx_handle_wheel_debug;		
} ble_nus_c_handles_t;

The code works fine when I enable notification for one character at a time.

Parents
  • If you are using write request you have to enable one notification at the time, because you can only do one write request at the time, you have to wait for the response before you send a new one.

    And I think you must use write request to write to descriptors. You could of course try to use write command instead.

  • Hi Petter, thanks for the reply. Sorry about the indentation.

    1. By "You could of course try to use write command instead." do you mean write command without response? (reference: www.safaribooksonline.com/.../ch04.html).

    2. Could you please share a central and peripheral combo code that uses write command without response?

    3. If I use write command without response during declaration at periperals, will the central get an event when peripheral writes into that characteristics? Or, should the central do polling to find if a new data has been written to each characteristic (when peripheral uses write command without response during declaration)? If so, which register to poll at the central?

    4. If I wanted to use write with response, then, will the following logic work if I have 3 characteristics at the central and peripheral side?

    In the peripheral side, make sure that the 3 characteristics are defined with write and not write_wo_response:

    char_md.char_props.write         = 1;
    char_md.char_props.write_wo_resp = 0;
    

    The peripheral first writes to characteristic 1 and waits till BLE_GATTC_EVT_WRITE_RSP event has been got in the peripheral. The central first runs the routine: ble_nus_c_rx_notif_enable with cccd_configure with the handle of characteristic 1. This would mean that when peripheral writes data to characteristic1, the central would receive notification under : ble_nus_c_on_ble_evt routine with an event id : BLE_GATTC_EVT_HVX with p_ble_evt->evt.gattc_evt.params.hvx.handle == p_ble_nus_c->handles.characteristic1. So, now the central can go ahead and read the data recieved in BLE_NUS_C_EVT_NUS_RX_EVT (in the routine: ble_nus_c_evt_handler). Once the central reads out the data sent by the peripheral, the peripheral would receive a BLE_GATTC_EVT_WRITE_RSP event.

    Now, the peripheral would send data in characteristic 2 and wait for BLE_GATTC_EVT_WRITE_RSP to be received. In the central side, once the central receives data in characteristic 1, it would call the routine: ble_nus_c_rx_notif_enable with cccd_configure with the handle of characteristic 2.

    Once central receives data in characteristic 2, (the peripheral would receive BLE_GATTC_EVT_WRITE_RSP at the same time), the central would call would call the routine: ble_nus_c_rx_notif_enable with cccd_configure with the handle of characteristic 3 and peripheral would write data to characteristic 3 and wait for BLE_GATTC_EVT_WRITE_RSP to happen, etc. Whenever the peripheral wants to write data to any of the characteristics, the above procedure would be followed. Even if the peripheral wants to write to only 1 characteristic (for example characteristic 3), the peripheral still needs to write dummy data to characteristics 1 and 2 so that the central and peripheral are in sync about which characteristic to be written (by peripheral) and read (by the central).

    Is the above logic correct?

Reply
  • Hi Petter, thanks for the reply. Sorry about the indentation.

    1. By "You could of course try to use write command instead." do you mean write command without response? (reference: www.safaribooksonline.com/.../ch04.html).

    2. Could you please share a central and peripheral combo code that uses write command without response?

    3. If I use write command without response during declaration at periperals, will the central get an event when peripheral writes into that characteristics? Or, should the central do polling to find if a new data has been written to each characteristic (when peripheral uses write command without response during declaration)? If so, which register to poll at the central?

    4. If I wanted to use write with response, then, will the following logic work if I have 3 characteristics at the central and peripheral side?

    In the peripheral side, make sure that the 3 characteristics are defined with write and not write_wo_response:

    char_md.char_props.write         = 1;
    char_md.char_props.write_wo_resp = 0;
    

    The peripheral first writes to characteristic 1 and waits till BLE_GATTC_EVT_WRITE_RSP event has been got in the peripheral. The central first runs the routine: ble_nus_c_rx_notif_enable with cccd_configure with the handle of characteristic 1. This would mean that when peripheral writes data to characteristic1, the central would receive notification under : ble_nus_c_on_ble_evt routine with an event id : BLE_GATTC_EVT_HVX with p_ble_evt->evt.gattc_evt.params.hvx.handle == p_ble_nus_c->handles.characteristic1. So, now the central can go ahead and read the data recieved in BLE_NUS_C_EVT_NUS_RX_EVT (in the routine: ble_nus_c_evt_handler). Once the central reads out the data sent by the peripheral, the peripheral would receive a BLE_GATTC_EVT_WRITE_RSP event.

    Now, the peripheral would send data in characteristic 2 and wait for BLE_GATTC_EVT_WRITE_RSP to be received. In the central side, once the central receives data in characteristic 1, it would call the routine: ble_nus_c_rx_notif_enable with cccd_configure with the handle of characteristic 2.

    Once central receives data in characteristic 2, (the peripheral would receive BLE_GATTC_EVT_WRITE_RSP at the same time), the central would call would call the routine: ble_nus_c_rx_notif_enable with cccd_configure with the handle of characteristic 3 and peripheral would write data to characteristic 3 and wait for BLE_GATTC_EVT_WRITE_RSP to happen, etc. Whenever the peripheral wants to write data to any of the characteristics, the above procedure would be followed. Even if the peripheral wants to write to only 1 characteristic (for example characteristic 3), the peripheral still needs to write dummy data to characteristics 1 and 2 so that the central and peripheral are in sync about which characteristic to be written (by peripheral) and read (by the central).

    Is the above logic correct?

Children
No Data
Related