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

bond_event_handler

I'm currently trying to learn the functions of the softdevice by using the HTS example. I've managed to make an additional temparature service (named custom), which almost mimics the temperature service.

Apparently, the bond event handler sends out a new temperature measurement in order to refresh the client state after a connection loss (and upon a re-bond). I get a BUSY error if I try to send out a custom measurement as well, and it doesn't matter which one I send first. If I exclude either of them it works fine. So my question is wether this pattern is wrong, or I need to use the Scheduler or similar.

/**@brief Function for handling the Bond Manager events.
 *
 * @param[in]   p_evt   Data associated to the bond manager event.
 */
static void bond_evt_handler(ble_bondmngr_evt_t * p_evt)
{
    uint32_t err_code;
    bool     is_indication_enabled;
    
    switch (p_evt->evt_type)
    {
        case BLE_BONDMNGR_EVT_ENCRYPTED:
            // Send a single temperature measurement if indication is enabled.
            // NOTE: For this to work, make sure ble_hts_on_ble_evt() is called before
            //       ble_bondmngr_on_ble_evt() in ble_evt_dispatch().
						err_code = ble_custom_is_indication_enabled(&m_custom, &is_indication_enabled);
            APP_ERROR_CHECK(err_code);
            if (is_indication_enabled)
            {
                custom_measurement_send();
            }

            err_code = ble_hts_is_indication_enabled(&m_hts, &is_indication_enabled);
            APP_ERROR_CHECK(err_code);
            if (is_indication_enabled)
            {
                temperature_measurement_send();
            }

						break;
            
        default:
            break;
    }
}
  • By Bluetooth spec you are allowed to have only one Indication pending confirmation at any time, and hence you get the BUSY error on the second call to send an Indication.

    There isn't any workaround to magically fix this, except to retry when you know that a confirmation has been received. When an indication is confirmed by the application on the peer device, you will receive a BLE_GATTS_EVT_HVC event, so when you get this, you can retry sending the indication.

Related