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

Detecting a BLE connection using 'm_conn_handle' issue

Hi again, Hope everyone had a great Christmas.. I did, but Santa also gave me a litte issue with my nRF52-DK..

I using a modified UART example, I have a 5min repeating timer that set's a flag to call a '5minAction' sub from the main loop (works as expected) In the '5minAction' sub I start advertising, I then want to wait until a connection is established before transferring some data

err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
				APP_ERROR_CHECK(err_code);
		while(m_conn_handle == BLE_CONN_HANDLE_INVALID && connect_timout_secs < 40)
		{
			nrf_delay_ms(1000);
			connect_timout_secs++;
		}
	

However once I enter the loop testing for the connection it never exits the loop until the count down completes (I can see that normally I have a connection within a second (I can see my mobile says connected and a UART msg I send as a test from the ble_evt_handler - BLE_GAP_EVT_CONNECTED handler).

If I add a delay "nrf_delay_ms(20000) ;" between starting advertising and entering the loop, it see's it's connected on the first loop and exits as I would expect.

It seems that 'm_conn_handle' is not being updated whilst in this loop, I don't understand why, can anyone help?

Parents
  • Jesus Christ stop using bloody blocking calls like nrf_delay(xxx)!!! All FWs which uses BLE stack should be strictly asynchronous, no while or other waiting loops. Simply do what you need before entering main loop in the main() where you should only execute wait for event/interrupt and all the rest is handled as callback to your handler function supplied to Soft Device during initialization. Literally every BLE example in the SDK is written like that and it's not coincidence. So the best would probably be rewriting your application to fit this concept.

  • I only have that sort of loop in the one place(it was intended as a quick test), the rest uses interrupts, what was confusing me was that I could see other stuff happening outside the loop... i.e. serial transmission etc.

Reply Children
No Data
Related