<?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>Fitting data into advertisement packet nRF52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102709/fitting-data-into-advertisement-packet-nrf52840</link><description>Hi there, 
 I&amp;#39;m trying to advertise my changing sensor data over BLE, and according to my calculations it should fit without a scan response, but it isn&amp;#39;t fitting--what am I missing? Is there a way to get it to compress to send the data in one packet</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 11 Aug 2023 09:33:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102709/fitting-data-into-advertisement-packet-nrf52840" /><item><title>RE: Fitting data into advertisement packet nRF52840</title><link>https://devzone.nordicsemi.com/thread/440917?ContentTypeID=1</link><pubDate>Fri, 11 Aug 2023 09:33:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:667a05db-8a72-4fe4-a0c4-f462de90e77c</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Hello&lt;/p&gt;
[quote user=""]When I try to run the code, however, it gives me a packet &amp;quot;too big&amp;quot; error. Where&amp;#39;s the extra space coming from?[/quote]
&lt;p&gt;I believe you have 2 bytes Company ID, 1 byte for length, one byte for type, and then you have 27 bytes left. You should be able to see this structure pretty clearly in Wireshark. You can read about different advertising structures/options here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://novelbits.io/maximum-data-bluetooth-advertising-packet-ble/"&gt;https://novelbits.io/maximum-data-bluetooth-advertising-packet-ble/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So your options would be to either use extended advertising, or to represent your data using fewer bytes.&lt;/p&gt;
[quote user=""]Is there a 3-byte float? I don&amp;#39;t need 4 bytes of precision on 3 of the floats[/quote]
&lt;p&gt;You could represent a float with two ints, one &lt;code&gt;uint8_t&lt;/code&gt; and one &lt;code&gt;uint16_t&lt;/code&gt; for example.&lt;/p&gt;
&lt;p&gt;Is there really any good reason to send this data as floats anyway? How is the raw sensor data represented?&lt;/p&gt;
[quote user=""]1. I&amp;#39;m using a sniffer (with Wireshark) to look at packets, but I&amp;#39;m not sure how to decode my data back to the floats I started with--do you have advice on this?[/quote]
&lt;p&gt;You could put known data into your packet (eg [1.2, 3.4, 5.6, 7.8]), then it&amp;#39;d be easier to see what&amp;#39;s going on in your BLE data.&lt;/p&gt;
&lt;p&gt;Doesn&amp;#39;t Wireshark usually decode the data for you anyway?&lt;/p&gt;
[quote user=""]2. I need to configure a nRF52840 as a central device that retrieves the data from the adv packets of 20 of these BLE beacons, is there an example code using the nRF Connect SDK that I could start with? Or any advice you have?[/quote]
&lt;p&gt;There are BLE central role samples available yes:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/bl.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/bl.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/bluetooth/bluetooth.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/bluetooth/bluetooth.html&lt;/a&gt;&lt;/p&gt;
[quote user=""]&lt;p&gt;3. To identify each of the 20 devices to the central, is there room for a random static address (or would something else be easier?) so I can know which peripheral I&amp;#39;m receiving data from? Would this add to the advertising packet or just change it?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;The advertiser&amp;#39;s address is included in the advertisement payload before the advertisement data, you should be able to see this in Wireshark, so it should be possible to tell advertisements from different devices apart.&lt;/p&gt;
&lt;p&gt;You could add an identifier to your advertising data of course, but yes that would add to the advertising packet.&lt;/p&gt;
[quote user=""]4. The functions to start advertising and update advertising necessitate including a scan response--is there a way to remove the scanning feature?[/quote]
&lt;p&gt;Looks like Zephyr&amp;#39;s beacon sample uses&amp;nbsp;&lt;code&gt;BT_LE_ADV_NCONN_IDENTITY&lt;/code&gt; (though they are also defining a scan response):&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/bluetooth/beacon/src/main.c#L57"&gt;https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/bluetooth/beacon/src/main.c#L57&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>