Problem with BLE scanning - event 0x1D overflow

Hi, I'm a having a serious issue with the workings of my device. The device normally scans for external ble devices to connect to. It uses BLE (anf ANT+ but not simultanously) to do that. It goes through a list of devices and tries to connect to each one, one after another. I don't use bonding and there are actually two types of BLE devices my device wants to find - BLE HRM (it uses the type 180D + name filter) and a LED driver (also know type + name filter).

It works normally when the devices are found within maybe couple of hours. If the use leaves my device ON and there are no devices to connect to, my device will try in a loop but after some longer type, couple of hours, sometime like 10 hours, my device is overflooded with "00> <debug> nrf_sdh_ble: BLE event: 0x1D." and it becomes unresponsive.

I don't know what is the reason. It seems that maybe the number of BLE devices in vicinity causes the problem to arise sooner. 

I tried mnipulaling the BLE parameters in sdk_config. I can get longer runs but then the device takes too long to find and connect to my devices. 

My guess is, there is some sort of memory leak in the softdevice. I can't think of anything else. Is this some sort of a known bug? Or am I crazy and do something wrong? Please advice. I need to be able to leave the device working all around the clock and not worry about it being stuck.

My sdk is 17.0.2, my softdevice is S340

My relevant sdl_config parameters:

#define NRF_BLE_SCAN_SCAN_DURATION 350 // 330 // 5s
#endif

// <o> NRF_BLE_SCAN_SCAN_WINDOW - Scanning window. Determines the scanning window in units of 0.625 millisecond.
#ifndef NRF_BLE_SCAN_SCAN_WINDOW
#define NRF_BLE_SCAN_SCAN_WINDOW 320 // 160 // = 100 ms
#endif

// <o> NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL - Determines minimum connection interval in milliseconds.
#ifndef NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL
#define NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL 7.5
#endif

// <o> NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL - Determines maximum connection interval in milliseconds.
#ifndef NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL
#define NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL 60//30
#endif

// <o> NRF_BLE_SCAN_SLAVE_LATENCY - Determines the slave latency in counts of connection events.
#ifndef NRF_BLE_SCAN_SLAVE_LATENCY
#define NRF_BLE_SCAN_SLAVE_LATENCY 0
#endif

// <o> NRF_BLE_SCAN_SUPERVISION_TIMEOUT - Determines the supervision time-out in units of 10 millisecond.
#ifndef NRF_BLE_SCAN_SUPERVISION_TIMEOUT
#define NRF_BLE_SCAN_SUPERVISION_TIMEOUT 800

  • Adding some key functions to show you how the scanning is initiated. I'm including only the BLE part - ant+ works fine.

    void ant_and_ble_scan_start(void)
    {
    		connect_to[LED] = false;
    		connect_to[BLE_HRM] = false;
    		connect_to[ANT_HRM] = false;
    		connect_to[ANT_BPWR] = false;
    		connect_to[ANT_BSC] = false;
    	
    		if (connect_to_leds) 
    		{
    				if (led_conn_handle == BLE_CONN_HANDLE_INVALID)
    				{
    						connect_to[LED] = true;					
    				}
    		}
    
    		if (connect_to_ble_hrm)
    		{
    				if (hrm_conn_handle == BLE_CONN_HANDLE_INVALID)
    				{
    						connect_to[BLE_HRM] = true;
    				}
    		}
    		else if (connect_to_ant_hrm)
    		{
    				if (!ant_hrm_connected) 
    				{
    						connect_to[ANT_HRM] = true;
    				}
    		}
    		
    		if (connect_to_bpwr) 
    		{
    				if(!ant_bpwr_connected) 
    				{
    						connect_to[ANT_BPWR] = true;
    				}
    		}
    		
    		if (connect_to_bsc) 
    		{
    				if(!ant_bsc_connected)
    				{
    						connect_to[ANT_BSC] = true;
    				}
    		}
    		scan_start();
    }
    
    void scan_start(void)
    {
    		if(scanning_in_progress) 
    		{
    				NRF_LOG_DEBUG("Scanning already IN PROGRESS");
    				return;
    		}
    		scanning_in_progress = true;
        	NRF_LOG_DEBUG("Starting scan...");
    
      		ret_code_t err_code;
    		connect_to_current = -1;
    	
    		// select to which device we should connect to - we should never do more than one to avoid overloading of the SD
    		// if more than 1 -> we need to alternate, to make sure we try all
    		// go CONNECT_TO_COUNT times to make sure we check all positions in the table
    		// start checking at connect_index
    		for(int i = 0; i < CONNECT_TO_COUNT; i++)
    		{
    				if(connect_to[connect_index]) 
    				{
    						connect_to_current = connect_index;
    						break;
    				}
    				connect_index = (connect_index + 1) % CONNECT_TO_COUNT;	
    		}
    		
    		if(connect_to_current == BLE_HRM) 
    		{
    				NRF_LOG_DEBUG("Starting scan for BLE HRM");
    				// reset those variables - if new config write comes, we will know the name changed since last connection initiation 
    				// and we can disconnect when the connection is established			
    				hrm_name_changed = false;
    			
    				scan_reinit_hrs();
    				err_code = nrf_ble_scan_start(&m_scan);
    				APP_ERROR_CHECK(err_code);
    		}
    		else if(connect_to_current == LED)
    		{
    				NRF_LOG_DEBUG("Starting scan for BLE LED");		
    			
    				scan_reinit_led();
    				err_code = nrf_ble_scan_start(&m_scan);
    				APP_ERROR_CHECK(err_code);
    		} 
    		else if((connect_to_current == ANT_HRM) && !ant_hrm_scan_waiting_for_chan_close)
    		{
    				NRF_LOG_DEBUG("Starting scan for ANT HRM");
    				app_timer_start(ant_scan_timer, APP_TIMER_TICKS(5000), NULL);
    				ant_hrm_rx_start();
    		}
    		else if((connect_to_current == ANT_BPWR) && !ant_bpwr_scan_waiting_for_chan_close)
    		{
    				NRF_LOG_DEBUG("Starting scan for ANT BPWR");
    				app_timer_start(ant_scan_timer, APP_TIMER_TICKS(5000), NULL);
    				ant_bpwr_rx_start();
    		}
    		else if((connect_to_current == ANT_BSC) && !ant_bsc_scan_waiting_for_chan_close) 
    		{
    				NRF_LOG_DEBUG("Starting scan for ANT BSC");
    				app_timer_start(ant_scan_timer, APP_TIMER_TICKS(5000), NULL);
    				ant_bsc_rx_start();
    		}
    		else
    		{
    				scanning_in_progress = false;
    				NRF_LOG_DEBUG("Nothing to scan for");
    		}
    		
    		// increase the index to try other device next time
    		connect_index = (connect_index + 1) % CONNECT_TO_COUNT;	
    }
    
    static void scan_reinit_led(void)
    {
    		ret_code_t err_code;
    		
    		ble_filter = NRF_BLE_SCAN_NAME_FILTER;
    		err_code = nrf_ble_scan_all_filter_remove(&m_scan);
        	APP_ERROR_CHECK(err_code);
    
    		err_code = nrf_ble_scan_name_filter_add(&m_scan, led_target_periph_name);
    		APP_ERROR_CHECK(err_code);
    
    		err_code = nrf_ble_scan_filters_enable(&m_scan, ble_filter, false);
    		APP_ERROR_CHECK(err_code);
    }

  • Hi,

    BLE event 0x1D is BLE_GAP_EVT_ADV_REPORT, so apparently you are receiving a lot of advertising reports (meaning receiving a lot of advertising packets). That itself is no error, but perhaps it means that you are scanning when you did not intend to, or are not filtering as you intended to? Also, if there are a lot of advertisers around and you print all incoming messages in the log, simply logging could cause problems (due to the amount of logging and time required to process the logs etc).

  • You might be right. It seems that decreasing the debug level solves it. I will keep this open for few more days just to make sure, but this seems like a probable cause. Thanks.

Related