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

Reinitializing advertising packet stops scanner?

I am working on a project using the nRFDK51 as BLE scanner with s130 and BLE peripheral an nrf51822 custom PCB design. The BLE peripheral is the device we are developing for sensor measurement project.

We are assigning id's to the devices during the connection. The way the id assignment works for each device is:

  1. The peripheral advertisement packet contains:
  • full name
  • manufacturer's data with Nordic company identifier(0x0059) and 8 bytes set to zero.

2)Scanner connects on name and zero manufacturer's data.

3)During connection scanner sends timestamp to peripheral

4)Peripheral acknowledges the timestamp by sending back to scanner a specific message

  1. When scanner receives this message it disconnects.

  2. Peripheral uses this timestamp as id and reinitialises the advertisement packet with 8 bytes of manufacturer's data set to timestamp and starts advertising.

This is where we encounter the problem The scanner shuts off when we reinitialize the advertisement. Instead of continuing to scan. It is definitely disconnected from the peripheral during re initialization and should be no longer able to connect to it after manuf data is changed since empty manuf data is still a criteria for connection. Why are we encountering a problem with scanner when peripheral is the device changing its packet during disconnection? Also, the peripheral continues advertising with new manuf data with no problem.

To debug, I reinitialize it to zero again, it causes no problem since it same as original. Thus, the problem causing the scanner shut off is not reinitializing function but with changing the manuf data from what it originally was. I also tried a scan_start() to restarting scanning, but it didn’t work.

It looks like scanner saves address of periph and its advertsing packet, and when that changes it causes a SystemReset or NVICSystemReset().

Any suggestions on what problem might be? Do you know if scanner remembers peer's advertising parameters and uses them for future connections and how a scan “refresh” or restart can be made?

  • Are you checking all error codes from softdevice calls? Have you tried debugging your application to see where your application is crashing?

  • The error code of softdevice calls on peripheral are NRF_SUCCESS and on the scanner, the softdevice call is diconnect returns an NRF_SUCCESS, after disconnection it does a scan strat again anf the error_code for that iis also an NRF_SUCCESS.

    I tired debugging my application using LED's to see where it fails. The application fails ehen examining the manuf data of peripheral. So it sees the adv packet and extracts its content then fails.

  • Can you post the code of what you are doing in the code when it fails?

  • sorry for the late reply, here's a screenshot of my code on the peripheral side in main while loop:

    while(true){
    	if(disconnected){
    		err_code = sd_ble_gap_adv_stop(); //SD_BLE_GAP_ADV_STOP
    		APP_ERROR_CHECK(err_code);
    		reintialise_ble_adv_packet();
    		err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    		APP_ERROR_CHECK(err_code);
    		disconnected = false;
    	}
    

    } and here's where I disconnect in response to the message 150 in the scanner:

        case BLE_PRESSURE_C_EVT_RX_EVT:  
    					//usb_printf("Received over BLE: %f\r\n", *((float*)(p_ble_pressure_evt->p_data))); 
    				//usb_printf("Received over BLE with reference %d", p_ble_pressure_evt->p_data[0]);
    				if(p_ble_pressure_evt->p_data[0] == 100){
    					usb_send_message(p_ble_pressure_evt->p_data[0], &p_ble_pressure_evt->p_data[1], p_ble_pressure_evt->data_len - 1); }
    					else if( p_ble_pressure_evt->p_data[0] == 150) {
    						//usb_printf("Periph received TimeStamp\r\n");
    						err_code = sd_ble_gap_disconnect(m_ble_pressure_c.conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
    						
    						APP_ERROR_CHECK(err_code);
    						usb_printf("Periph received TimeStamp,disconnect err_code: %d\r\n", err_code);
    						connected = false; 
    					}
    					else{ // for other types of messages 
    					//stream_all_64_values(p_ble_pressure_evt);
    					//stream_2_values(p_ble_pressure_evt);
    					stream_Cext_C2_C15_C30_temp_values(p_ble_pressure_evt);
    				}
    				break;
    

    The err code from discconnect is an NRF_SUCCESS, when the scanner detects a disconnect event on the ble event handler it does a scan_start as shown below:

    	case	BLE_GAP_EVT_DISCONNECTED:
    		p_ble_pressure_c->conn_handle = BLE_CONN_HANDLE_INVALID; 
    		printf("Disconnected"); 
    		scan_start(); 
    		break;
    
  • None of this code shows where your application is failing. It sounds like your central is failing when it process the received advertising packet. Could you post code of how you are looking at the manufacturer data of the advertising packet? The central should not "remember" anything about the peripheral, unless you have performed bonding, and nothing related to advertising whatsoever.

Related