<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Reinitializing advertising packet stops scanner?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/19903/reinitializing-advertising-packet-stops-scanner</link><description>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&amp;#39;s to the devices during the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 04 Mar 2017 19:25:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/19903/reinitializing-advertising-packet-stops-scanner" /><item><title>RE: Reinitializing advertising packet stops scanner?</title><link>https://devzone.nordicsemi.com/thread/77457?ContentTypeID=1</link><pubDate>Sat, 04 Mar 2017 19:25:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9011cd0-3051-4447-b7b8-320915e7bf37</guid><dc:creator>KasemC</dc:creator><description>&lt;p&gt;The line where the application was failing is in  is_manuf_data_present() function call here:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;memcmp(adv_data, manuf_data, manuf_data_length).
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem was that I didnt pass address in memcmp of the both adv_data and manuf_data values.&lt;/p&gt;
&lt;p&gt;Just for clarification the function is supposed to be written as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;memcmp(&amp;amp;adv_data, &amp;amp;manuf_data, manuf_data_length)
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reinitializing advertising packet stops scanner?</title><link>https://devzone.nordicsemi.com/thread/77454?ContentTypeID=1</link><pubDate>Fri, 03 Mar 2017 10:35:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4445e2d7-4d82-46be-91cb-723708d01dc9</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Could you debug your application, &lt;a href="https://devzone.nordicsemi.com/question/60125/my-device-is-freezing-and-restarting/"&gt;as described here&lt;/a&gt;, to see exactly on which line your application is failing? Have you checked the data in the advertising packet to see that you have the fields you expect? As there are not softdevice calls inside the &lt;code&gt;is_manuf_data_present()&lt;/code&gt; function, most likely your application is trying to access an index out of range in one the array or something similar.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reinitializing advertising packet stops scanner?</title><link>https://devzone.nordicsemi.com/thread/77453?ContentTypeID=1</link><pubDate>Thu, 02 Mar 2017 16:55:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:222fbca8-c8da-4ebe-b0d8-ad90c18b6f23</guid><dc:creator>KasemC</dc:creator><description>&lt;p&gt;yeah it&amp;#39;s failing when processing the advertising packet, here&amp;#39;s a code of the central looks at the manuf data and compares it:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t              err_code;
const ble_gap_evt_t * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;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-&amp;gt;header.evt_id)
{
    case BLE_GAP_EVT_ADV_REPORT:
			{
        const ble_gap_evt_adv_report_t * p_adv_report = &amp;amp;p_gap_evt-&amp;gt;params.adv_report; /* Contains the adv report */ 
				//	if (is_uuid_present(&amp;amp;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(&amp;amp;p_adv_report-&amp;gt;peer_addr,
                                          &amp;amp;m_scan_params,
                                          &amp;amp;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;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;this is the code of the is_manuf_data_present function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;     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-&amp;gt;data;
  uint8_t adv_data_length; 
 uint8_t * adv_data;

while (index &amp;lt; p_adv_report-&amp;gt;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(&amp;amp;adv_data, &amp;amp;p_data[index+4], adv_data_length-2) ;
					usb_printf(&amp;quot;Manuf data:%08x length: %d\r\n&amp;quot;, adv_data, adv_data_length);
			//	LED2_ON(); 
					if((adv_data_length == (manuf_data_length+2)) &amp;amp;&amp;amp; (!memcmp(adv_data, manuf_data, manuf_data_length))){						            
						return true;
					}
    }
    index += field_length+1;
}
return false;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reinitializing advertising packet stops scanner?</title><link>https://devzone.nordicsemi.com/thread/77456?ContentTypeID=1</link><pubDate>Thu, 02 Mar 2017 15:28:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b03dabc4-4abb-4b4f-b701-3d2b8a1b46a9</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;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 &amp;quot;remember&amp;quot; anything about the peripheral, unless you have performed bonding, and nothing related to advertising whatsoever.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reinitializing advertising packet stops scanner?</title><link>https://devzone.nordicsemi.com/thread/77455?ContentTypeID=1</link><pubDate>Wed, 01 Mar 2017 23:30:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2461676e-bea4-4b68-93fb-fc937279de45</guid><dc:creator>KasemC</dc:creator><description>&lt;p&gt;sorry for the late reply, here&amp;#39;s a screenshot of my code on the peripheral side in main while loop:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;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;
	}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}
and here&amp;#39;s where I disconnect in response to the message 150 in the scanner:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    case BLE_PRESSURE_C_EVT_RX_EVT:  
					//usb_printf(&amp;quot;Received over BLE: %f\r\n&amp;quot;, *((float*)(p_ble_pressure_evt-&amp;gt;p_data))); 
				//usb_printf(&amp;quot;Received over BLE with reference %d&amp;quot;, p_ble_pressure_evt-&amp;gt;p_data[0]);
				if(p_ble_pressure_evt-&amp;gt;p_data[0] == 100){
					usb_send_message(p_ble_pressure_evt-&amp;gt;p_data[0], &amp;amp;p_ble_pressure_evt-&amp;gt;p_data[1], p_ble_pressure_evt-&amp;gt;data_len - 1); }
					else if( p_ble_pressure_evt-&amp;gt;p_data[0] == 150) {
						//usb_printf(&amp;quot;Periph received TimeStamp\r\n&amp;quot;);
						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(&amp;quot;Periph received TimeStamp,disconnect err_code: %d\r\n&amp;quot;, 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;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;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:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;	case	BLE_GAP_EVT_DISCONNECTED:
		p_ble_pressure_c-&amp;gt;conn_handle = BLE_CONN_HANDLE_INVALID; 
		printf(&amp;quot;Disconnected&amp;quot;); 
		scan_start(); 
		break;
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reinitializing advertising packet stops scanner?</title><link>https://devzone.nordicsemi.com/thread/77451?ContentTypeID=1</link><pubDate>Thu, 23 Feb 2017 08:17:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:667c602d-e8a0-489e-af47-0101cfb365dc</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Can you post the code of what you are doing in the code when it fails?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reinitializing advertising packet stops scanner?</title><link>https://devzone.nordicsemi.com/thread/77452?ContentTypeID=1</link><pubDate>Wed, 22 Feb 2017 17:57:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:51b82fdf-a9a1-4927-887a-213c77295ab9</guid><dc:creator>KasemC</dc:creator><description>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;I tired debugging my application using LED&amp;#39;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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reinitializing advertising packet stops scanner?</title><link>https://devzone.nordicsemi.com/thread/77450?ContentTypeID=1</link><pubDate>Wed, 22 Feb 2017 15:06:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ada21c8f-b0ba-4cdf-90ca-e454bc64a5c7</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Are you checking all error codes from softdevice calls? Have you tried &lt;a href="https://devzone.nordicsemi.com/question/60125/my-device-is-freezing-and-restarting/"&gt;debugging your application&lt;/a&gt; to see where your application is crashing?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>