<?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>Sending scanning data via UART</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/49225/sending-scanning-data-via-uart</link><description>Hey guys. I am making a firmware using nrf52840 dongle which scans nearby bluetooth devices. I do not want to connect to any device, just send scanning data to another device via UART. 
 Below is the code where I am getting scanning data on console 
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 05 Jul 2019 06:52:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/49225/sending-scanning-data-via-uart" /><item><title>RE: Sending scanning data via UART</title><link>https://devzone.nordicsemi.com/thread/196712?ContentTypeID=1</link><pubDate>Fri, 05 Jul 2019 06:52:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0e72968-1397-42f4-9960-ad20b2e885ac</guid><dc:creator>PKSHER</dc:creator><description>&lt;p&gt;Ok i will look at it and get back to you. Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending scanning data via UART</title><link>https://devzone.nordicsemi.com/thread/196218?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2019 09:44:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:501e8386-e57f-469a-a9b1-560891295ad1</guid><dc:creator>awneil</dc:creator><description>[quote userid="80472" url="~/f/nordic-q-a/49225/sending-scanning-data-via-uart/196165"]I want to send advertisement data of beacons i.e. 31 bytes to be sent to uart [/quote]
&lt;p&gt;Identical question answered here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/49289/reading-raw-adv-packet"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/49289/reading-raw-adv-packet&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending scanning data via UART</title><link>https://devzone.nordicsemi.com/thread/196216?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2019 09:43:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b92ffa00-9047-4fb3-adc9-7e535050eb7c</guid><dc:creator>awneil</dc:creator><description>[quote userid="72220" url="~/f/nordic-q-a/49225/sending-scanning-data-via-uart/195858"] NULL terminator to inform the receiver that the end of the string has been reached.[/quote]
&lt;p&gt;No, that&amp;#39;s not (quite) true.&lt;/p&gt;
&lt;p&gt;The NUL terminator tells the &amp;#39;C&amp;#39; library functions that they have reached the end of the string.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The NUL terminator is &lt;em&gt;&lt;strong&gt;not&lt;/strong&gt; &lt;/em&gt;sent to the receiver!&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending scanning data via UART</title><link>https://devzone.nordicsemi.com/thread/196210?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2019 09:34:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0988b3c2-045f-4a7e-aa9c-133c8fbe601b</guid><dc:creator>cbd</dc:creator><description>&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;Hi PKSHER,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;I know what you&amp;#39;re after, but I&amp;#39;m not going to write your code for you.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;I explained why, in your first code snippet, you were seeing a hexadecimal formatted ASCII representation of your binary data.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;Your first code snippet implied that you knew how to access the advertising data, in any case y&lt;span style="background-color:#ffffff;"&gt;ou&amp;#39;ll find your it located at &lt;strong&gt;p_gap_evt-&amp;gt;params.adv_report.data.p_data&lt;/strong&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;and of length &lt;strong&gt;p_gap_evt-&amp;gt;params.adv_report.data.len&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;strong&gt;Note: &lt;/strong&gt;not all devices will advertise the same amount of data.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;In sending data over the UART you&amp;#39;ll need to allow for the fact that the BLE advertising events (with data) and the UART transmission are not synchronous, hence my mention of a temporary buffer into which you&amp;#39;ll need to copy your data and the UART code can draw your data from.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;br /&gt;I guess from your mention of &lt;strong&gt;app_uart_put&lt;/strong&gt; that your using one of the NRF libraries, which is all well and good, but let me ask you these two questions too think over (I don&amp;#39;t want a reply to them).&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style="background-color:#ffffff;"&gt;If at the receiving end of your UART line you receive a block of data, say 78 bytes, how do you know where an advertising record begins and ends, or indeed if it contains any part records?&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="background-color:#ffffff;"&gt;If you decide to send RSSI data and advertising data over the UART, how does your receiving device determine which byte of data relates to the RSSI value?&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;This is why I was guiding you towards some form of messaging structure, maybe with start and end termination sequences and data length indicators.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;Your first code snippet seemed to imply that you know of the need of a temporary buffer by using &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;strong&gt;m_scan.scan_buffer.p_data&lt;/strong&gt; and &lt;strong&gt;m_scan.scan_buffer.len&lt;/strong&gt; .&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;br /&gt;Your second code snippet with its &lt;strong&gt;for loop&lt;/strong&gt; seems to imply that you know how to write a block of data to the UART a byte at a time (although it should be limited to the length of the data in your buffer as it may be more than or less than 100 bytes) e.g.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;for( int i=0; i&amp;lt; m_scan.scan_buffer.len; i++)
{
    app_uart_put(m_scan.scan_buffer.p_data++);
}&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;The NRF UART library will indeed temporarily buffer data for you, but you&amp;#39;ll still need to package it so that you can understand how to handle it at the other end.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending scanning data via UART</title><link>https://devzone.nordicsemi.com/thread/196165?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2019 08:20:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d3078de-bc4e-455a-8f50-fbb8a25febd9</guid><dc:creator>PKSHER</dc:creator><description>&lt;p&gt;But my point is how to get the data. For example the below code&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;switch (p_ble_evt-&amp;gt;header.evt_id)
{
  case BLE_GAP_EVT_ADV_REPORT:
  {
    app_uart_put(p_gap_evt-&amp;gt;params.adv_report.rssi);
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It sends RSSI values of nearby devices to uart, I want to send advertisement data of beacons i.e. 31 bytes to be sent to uart just like these RSSi values.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending scanning data via UART</title><link>https://devzone.nordicsemi.com/thread/195858?ContentTypeID=1</link><pubDate>Tue, 02 Jul 2019 08:24:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93b0e471-345c-4880-89ab-5b97d59ba1b4</guid><dc:creator>cbd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You&amp;#39;re getting ASCII values back as that is what you&amp;#39;re converting the binary data to.&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:#ffffff;"&gt;All of the NRF_LOG functions convert the binary data to ASCII, NRF_LOG_RAW_HEXDUMP_INFO converts the binary data to an ASCII representation of the binary data.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:#ffffff;"&gt;If you want to send binary data then you can do so, but you&amp;#39;ll need to put your own protocol in place as most UART examples send only ASCII data as it&amp;#39;s easier - by&lt;/span&gt;&lt;span style="background-color:#ffffff;"&gt; sending ASCII strings you&amp;#39;re using the NULL terminator to inform the receiver that the end of the string has been reached.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;For your purposes sending data in the following format would be a start:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;data length (number of bytes)&lt;/li&gt;
&lt;li&gt;data (all bytes from data array)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Using this all data would need to be treated as binary, unless you add another field to indicate whether the data is binary or ASCII. You may wish to add a short sequence of known bytes to indicate the start of a message e.g. 0xA5A5, you may also place something similar at the end of every message e.g. 5A5A. At the receiving end you would read those fields back and handle them accordingly e.g. is this the start of a message; does the data length match the length stated in the length field etc.&lt;/p&gt;
&lt;p&gt;In this case you&amp;#39;d build up your data string in a buffer array and send that.&lt;/p&gt;
&lt;p&gt;For example the data copied into the array would be in the order:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;data length (copy of m_scan.scan_buffer.len value)&lt;/li&gt;
&lt;li&gt;data (copy of all bytes in buffer pointed to by m_scan.scan_buffer.p_data)&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>