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

ble_advertising problem with broadcasting

There appears to be a conflict between ble_advertising and broadcasting while connected. If connected, the ble_advertising state machine still gets TIMEOUT messages from the broadcast and fails to ignore them and then advances the ble_advertising state machine into generating its own advertising packets while will cause false broadcasting. The ble_advertising state machine should ignore those TIMEOUT messages. I don't see a workaround other than compiling my own version of ble_advertising with a check to ignore timeouts if connected. Perhaps a better/proper fix for the Nordic SoftDevice would be to use a different timeout src: BLE_GAP_TIMEOUT_SRC_BROADCASTING for the evt.gap_evt.params.timeout.src field.

Parents Reply Children
  • I'm using the toolkit  nRF5_SDK_14.1.0_1dda907 s132 armgcc architectures. I copied the code into my own project and then modified it thusly:

    --- ble_advertising.c	2018-07-09 17:06:11.690065826 -0700
    +++ /home/scanner/ble_advertising.c	2018-08-03 16:13:07.912088784 -0700
    @@ -114,9 +114,9 @@
     
         p_advertising->whitelist_temporarily_disabled = false;
     
    -    if (p_ble_evt->evt.gap_evt.conn_handle == p_advertising->current_slave_link_conn_handle &&
    -        p_advertising->adv_modes_config.ble_adv_on_disconnect_disabled == false)
    -    {
    +    if (p_ble_evt->evt.gap_evt.conn_handle == p_advertising->current_slave_link_conn_handle) {
    +	p_advertising->current_slave_link_conn_handle = BLE_CONN_HANDLE_INVALID;
    +	if(p_advertising->adv_modes_config.ble_adv_on_disconnect_disabled == false) {
            ret = ble_advertising_start(p_advertising, BLE_ADV_MODE_DIRECTED);
            if ((ret != NRF_SUCCESS) && (p_advertising->error_handler != NULL))
            {
    @@ -124,6 +124,7 @@
            }
         }
     }
    +}
     
     
     /**@brief Function for handling the Timeout event.
    @@ -135,7 +136,8 @@
     {
         ret_code_t ret;
     
    -    if (p_ble_evt->evt.gap_evt.params.timeout.src != BLE_GAP_TIMEOUT_SRC_ADVERTISING)
    +    if (p_ble_evt->evt.gap_evt.params.timeout.src != BLE_GAP_TIMEOUT_SRC_ADVERTISING 
    +	|| p_advertising->current_slave_link_conn_handle != BLE_CONN_HANDLE_INVALID)
         {
             // Nothing to do.
             return;
    

     

  • Thanks for posting the changes you made, it's more clear now. I think this might be the best way to solve the problem for your use case. Another possible alternative could be to start brodcast advertising using the ble_advertising_start() with a mode that is followed by BLE_ADV_MODE_IDLE. 

Related