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.

  • 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. But, I need to get notifications at the central code, whenever a characteristic gets written by any of the peripherals that are already in connected mode with the central.

  • Ok. What is the problem? Have you enabled notifications in all peripherals by writing to their CCCD?

  • Hi Petter, Thanks for the reply. Yes, I am enabling the read and write permissions to the peripherals for all the characteristics. I use the following for adding all characteristics at the peripheral side:

    static uint32_t rx_char_add_information(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init)
    {
        /**@snippet [Adding proprietary characteristic to S110 SoftDevice] */
        ble_gatts_char_md_t char_md;
        ble_gatts_attr_md_t cccd_md;
        ble_gatts_attr_t    attr_char_value;
        ble_uuid_t          ble_uuid;
        ble_gatts_attr_md_t attr_md;
    
        memset(&cccd_md, 0, sizeof(cccd_md));
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
    
        cccd_md.vloc = BLE_GATTS_VLOC_STACK;
    
        memset(&char_md, 0, sizeof(char_md));
    
        char_md.char_props.notify = 1;
        char_md.p_char_user_desc  = NULL;
        char_md.p_char_pf         = NULL;
        char_md.p_user_desc_md    = NULL;
        char_md.p_cccd_md         = &cccd_md;
        char_md.p_sccd_md         = NULL;
    
        ble_uuid.type = p_nus->uuid_type;
        ble_uuid.uuid = BLE_UUID_NUS_RX_INFORMATION_CHARACTERISTIC;
    
        memset(&attr_md, 0, sizeof(attr_md));
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    
        attr_md.vloc    = BLE_GATTS_VLOC_STACK;
        attr_md.rd_auth = 0;
        attr_md.wr_auth = 0;
        attr_md.vlen    = 1;
    
        memset(&attr_char_value, 0, sizeof(attr_char_value));
    
        attr_char_value.p_uuid    = &ble_uuid;
        attr_char_value.p_attr_md = &attr_md;
        attr_char_value.init_len  = sizeof(uint8_t);
        attr_char_value.init_offs = 0;
        attr_char_value.max_len   = BLE_NUS_MAX_RX_CHAR_LEN;
    
        return sd_ble_gatts_characteristic_add(p_nus->service_handle,
                                               &char_md,
                                               &attr_char_value,
                                               &p_nus->rx_handles_information);
        /**@snippet [Adding proprietary characteristic to S110 SoftDevice] */
    }
    

    But, at the central side, I get notified when a peripheral has written to one particular characteristic(which is the same characteristic used in ble_nus_c_rx_notif_enable). In other words, I dont get notified at the central end when the peripheral writes to the any characteristic that is not used in ble_nus_c_rx_notif_enable.

  • I am not talking about enabling read and write permissions, I'm talking about the client (central) enabling notifications by writing 0x0001 to the CCCD of the characteristics you want to notify.

    Have you done this on all characteristics you want to be able to notify? Or only one?

Related