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?

Parents
  • yeah it's failing when processing the advertising packet, here's a code of the central looks at the manuf data and compares it:

    uint32_t              err_code;
    const ble_gap_evt_t * p_gap_evt = &p_ble_evt->evt.gap_evt;
    /* When the scanner recieves an advertisement packet, it will return it in a BLE_GAP_EVT_aDV_REPORT event to the application. */ 
    	uint8_t string = 120; 
    	uint8_t manuf_data_length; 
    	uint8_t * manuf_data = 0;
    	char * device_name; 
    	switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:
    			{
            const ble_gap_evt_adv_report_t * p_adv_report = &p_gap_evt->params.adv_report; /* Contains the adv report */ 
    				//	if (is_uuid_present(&m_pressure_uuid, p_adv_report))
    						if(is_device_name_present(DEVICE_NAME, 7, p_adv_report)) 
    						{
    							if(is_manuf_data_present(manuf_data, 8, p_adv_report))
    							{ 
                                              err_code = sd_ble_gap_connect(&p_adv_report->peer_addr,
                                              &m_scan_params,
                                              &m_connection_param);
    
                if (err_code == NRF_SUCCESS)
                {
                    // scan is automatically stopped by the connect
                    err_code = bsp_indication_set(BSP_INDICATE_IDLE);
                    APP_ERROR_CHECK(err_code);
                }
    							n_periph += 1;
            //}
    					//else{
    					// code here to specifically connect to devices based on their timestamp
    					}
    				}
           break;
        }
    

    this is the code of the is_manuf_data_present function:

         static bool is_manuf_data_present(uint8_t * manuf_data, uint8_t manuf_data_length, const ble_gap_evt_adv_report_t *p_adv_report)
      {
      uint32_t err_code;
      uint32_t index = 0;
      uint8_t *p_data = (uint8_t *)p_adv_report->data;
      uint8_t adv_data_length; 
     uint8_t * adv_data;
    
    while (index < p_adv_report->dlen)
    {
        uint8_t field_length = p_data[index];
        uint8_t field_type   = p_data[index+1];
    
    			if (field_type == BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA)
        {
            adv_data_length = field_length-1;
    					memcpy(&adv_data, &p_data[index+4], adv_data_length-2) ;
    					usb_printf("Manuf data:%08x length: %d\r\n", adv_data, adv_data_length);
    			//	LED2_ON(); 
    					if((adv_data_length == (manuf_data_length+2)) && (!memcmp(adv_data, manuf_data, manuf_data_length))){						            
    						return true;
    					}
        }
        index += field_length+1;
    }
    return false;
    

    }

Reply
  • yeah it's failing when processing the advertising packet, here's a code of the central looks at the manuf data and compares it:

    uint32_t              err_code;
    const ble_gap_evt_t * p_gap_evt = &p_ble_evt->evt.gap_evt;
    /* When the scanner recieves an advertisement packet, it will return it in a BLE_GAP_EVT_aDV_REPORT event to the application. */ 
    	uint8_t string = 120; 
    	uint8_t manuf_data_length; 
    	uint8_t * manuf_data = 0;
    	char * device_name; 
    	switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:
    			{
            const ble_gap_evt_adv_report_t * p_adv_report = &p_gap_evt->params.adv_report; /* Contains the adv report */ 
    				//	if (is_uuid_present(&m_pressure_uuid, p_adv_report))
    						if(is_device_name_present(DEVICE_NAME, 7, p_adv_report)) 
    						{
    							if(is_manuf_data_present(manuf_data, 8, p_adv_report))
    							{ 
                                              err_code = sd_ble_gap_connect(&p_adv_report->peer_addr,
                                              &m_scan_params,
                                              &m_connection_param);
    
                if (err_code == NRF_SUCCESS)
                {
                    // scan is automatically stopped by the connect
                    err_code = bsp_indication_set(BSP_INDICATE_IDLE);
                    APP_ERROR_CHECK(err_code);
                }
    							n_periph += 1;
            //}
    					//else{
    					// code here to specifically connect to devices based on their timestamp
    					}
    				}
           break;
        }
    

    this is the code of the is_manuf_data_present function:

         static bool is_manuf_data_present(uint8_t * manuf_data, uint8_t manuf_data_length, const ble_gap_evt_adv_report_t *p_adv_report)
      {
      uint32_t err_code;
      uint32_t index = 0;
      uint8_t *p_data = (uint8_t *)p_adv_report->data;
      uint8_t adv_data_length; 
     uint8_t * adv_data;
    
    while (index < p_adv_report->dlen)
    {
        uint8_t field_length = p_data[index];
        uint8_t field_type   = p_data[index+1];
    
    			if (field_type == BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA)
        {
            adv_data_length = field_length-1;
    					memcpy(&adv_data, &p_data[index+4], adv_data_length-2) ;
    					usb_printf("Manuf data:%08x length: %d\r\n", adv_data, adv_data_length);
    			//	LED2_ON(); 
    					if((adv_data_length == (manuf_data_length+2)) && (!memcmp(adv_data, manuf_data, manuf_data_length))){						            
    						return true;
    					}
        }
        index += field_length+1;
    }
    return false;
    

    }

Children
No Data
Related