<?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>Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/42180/scan-beacons-loss-too-many-packets</link><description>Hi all, I&amp;#39;m testing ble adv packets loss rate. I am using a simple scanner example in nRF52832 (Softdevice v2.0.0 &amp;amp; SDK v11), the scanner works in passive scanning, no whitelist, scan interval and scan window are both 60ms, scan timeout is 0x0000, disable</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 09 Jan 2019 01:02:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/42180/scan-beacons-loss-too-many-packets" /><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164597?ContentTypeID=1</link><pubDate>Wed, 09 Jan 2019 01:02:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:495af905-b0a3-48e3-b759-bb62eed3cf65</guid><dc:creator>ReedLi</dc:creator><description>&lt;p&gt;Thanks for your time and patience.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164574?ContentTypeID=1</link><pubDate>Tue, 08 Jan 2019 17:27:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:433242e7-225b-4ab3-9f48-7995e0becf63</guid><dc:creator>natersoz</dc:creator><description>&lt;p&gt;I will try to replicate your results this weekend (I have to do other work during the week). I&amp;#39;ll let you know what I find. I think I understand how you are counting packets and loss now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164433?ContentTypeID=1</link><pubDate>Tue, 08 Jan 2019 08:08:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1da9c82-7897-4ec9-9418-d5fc0297d3f9</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;An advertisement packet is up to 47bytes including everything, this equal 376us. If we presume you have 100 beacons advertise every 500ms, and that you in a perfect world is able to align 99 of the beacons ideally after each other they will take approx 37ms. The risk of a beacon to collide with the 99 others then are 37/500ms = 7.4%. However since you are not in an ideal world it is likely all 100 will collide with each other, so I don&amp;#39;t think 17% packet loss is unexpected here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164403?ContentTypeID=1</link><pubDate>Tue, 08 Jan 2019 03:18:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b50e203e-4d0c-4b22-af0d-0667b9e096b4</guid><dc:creator>ReedLi</dc:creator><description>&lt;p&gt;Hi, when receiving&amp;nbsp;&lt;span&gt;BLE_GAP_EVT_ADV_REPORT&amp;nbsp;event,&amp;nbsp;advertising packet number add 1 and i would get peer addr/rssi/dlen/data of the struct&amp;nbsp;ble_gap_evt_adv_report_t.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;About channel hopping, beacons would advertise on both 3 channels(37,38,39), and scanner would also scan on both 3 channels.So it wouldn&amp;#39;t be 33%.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164398?ContentTypeID=1</link><pubDate>Tue, 08 Jan 2019 02:10:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92df0bba-f610-4a92-93dc-4608f1d31e62</guid><dc:creator>ReedLi</dc:creator><description>&lt;p&gt;Hi, some collisions and channel switching may cause packet loss, i just don&amp;#39;t know if 17% packet loss rate is reasonable and how to improve it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164318?ContentTypeID=1</link><pubDate>Mon, 07 Jan 2019 14:54:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ffbb994-1960-483a-ad8d-445e7b3b1b7e</guid><dc:creator>natersoz</dc:creator><description>&lt;p&gt;Digging deeper&amp;nbsp; :)&lt;/p&gt;
&lt;p&gt;What part of the struct ble_gap_evt_adv_report_t are you using for your &amp;#39;advertising packet number&amp;#39;?&lt;/p&gt;
&lt;p&gt;I would expect that with channel hopping enabled, a scanner would only see 1/3 (33%) of the advertised packets. So I am surprised that you are not seeing a much larger packet loss number.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164278?ContentTypeID=1</link><pubDate>Mon, 07 Jan 2019 13:33:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bfbeaafb-3473-4ce4-a38f-e854dc957cd9</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I assume there may be some packet loss when switching scan channel, this will occur every scan interval. If you have 100 devices, then it is likely that there will be some collisions, where two advertisers advertise at the same time, this may prevent either or both packets to be received at some intervals.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164163?ContentTypeID=1</link><pubDate>Mon, 07 Jan 2019 08:47:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1bde8bc2-ad17-47ee-9836-9d754e5dabaa</guid><dc:creator>ReedLi</dc:creator><description>&lt;p&gt;Thanks for your thoughts.Here are replies to thoughts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Advertisement and scan in 3 channels&lt;/li&gt;
&lt;li&gt;There is no printf(), i turn off&amp;nbsp;it&lt;span&gt;.&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;I can only get adv packets when receive&amp;nbsp;BLE_GAP_EVT_ADV_REPORT Event&amp;nbsp; in ble_evt_dispatch. And after receiving adv packets i only count the number, &amp;nbsp;no flash and printf() operations.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164137?ContentTypeID=1</link><pubDate>Mon, 07 Jan 2019 05:29:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a7cde68-8b79-4bed-86da-1ce5528ad2f8</guid><dc:creator>natersoz</dc:creator><description>&lt;p&gt;Update: I realized that the method I am counting packets and you are counting packets are different.&lt;/p&gt;
&lt;p&gt;I changed the python program to match what I think you are doing to count packets received and lost and updated the python code. It is checked in here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/natersoz/nrf/blob/master/scripts/packet_loss.py"&gt;https://github.com/natersoz/nrf/blob/master/scripts/packet_loss.py&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It is checked in with 1.5 msec of software latency, which is still very high. &lt;strong&gt;17% packet loss.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164134?ContentTypeID=1</link><pubDate>Mon, 07 Jan 2019 05:07:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:487d8f74-ebc3-437c-b29e-78ae767e17a8</guid><dc:creator>natersoz</dc:creator><description>&lt;p&gt;Sorry - more questions:&lt;/p&gt;
&lt;p&gt;Are you limiting your advertising and scanning to only one frequency?&lt;/p&gt;
&lt;p&gt;Let me assume that you are.&lt;/p&gt;
&lt;p&gt;At 31 bytes of advertising data, this is a fully loaded advertising packet.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not an expert on the PHY/Link layer aspects of BLE, but that should be 376 usec of duration. Citing Robin Hayden, Bluetooth LE: The Developer&amp;#39;s Handbook, 3.1.1 Physical Layer.&lt;/p&gt;
&lt;p&gt;This seems right: For a full Link Layer packet there are 37 bytes, 376 bits. At a 1 Mbps symbol rate, 1 bit / symbol that is a Link Layer duration of 376 usec.&lt;/p&gt;
&lt;p&gt;Here is how I would model this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Assuming you&amp;#39;re on a single PHY layer frequency (otherwise, I don&amp;#39;t know how this could be lossless. I would expect a hopping scanner and a single hopping beacon to experience a 2/3 transmission loss (67%)).&lt;/li&gt;
&lt;li&gt;There is an expected arrival time of the advertising interval / the beacon count.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I &lt;strong&gt;think&lt;/strong&gt; this can be modeled as a Poisson distribution:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Poisson_distribution#Probability_of_events_for_a_Poisson_distribution"&gt;https://en.wikipedia.org/wiki/Poisson_distribution#Probability_of_events_for_a_Poisson_distribution&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The interval is 367 usec + software latency (let&amp;#39;s assume ero for now).&lt;/p&gt;
&lt;p&gt;Poisson&amp;#39;s lambda &amp;lambda; = 367 usec / 5 msec = 0.0734&lt;/p&gt;
&lt;p&gt;For zero time of software latency, I get an expected packet loss of 7%:&lt;/p&gt;
&lt;p&gt;Beacon Count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 100&lt;br /&gt;Advertising Interval&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 500 msec&lt;br /&gt;Link Layer Packet Length = 47 bytes, 376 bits&lt;br /&gt;Link Layer Packet Period = 376 usec&lt;br /&gt;P(&amp;nbsp; 0, 0.075) = 9.276e-01&lt;br /&gt;P(&amp;nbsp; 1, 0.075) = 6.975e-02&lt;br /&gt;P(&amp;nbsp; 2, 0.075) = 2.623e-03&lt;br /&gt;P(&amp;nbsp; 3, 0.075) = 6.574e-05&lt;br /&gt;P(&amp;nbsp; 4, 0.075) = 1.236e-06&lt;br /&gt;P(&amp;nbsp; 5, 0.075) = 1.859e-08&lt;br /&gt;P(&amp;nbsp; 6, 0.075) = 2.330e-10&lt;br /&gt;P(&amp;nbsp; 7, 0.075) = 2.503e-12&lt;br /&gt;P(&amp;nbsp; 8, 0.075) = 2.353e-14&lt;br /&gt;P(&amp;nbsp; 9, 0.075) = 1.966e-16&lt;br /&gt;&lt;br /&gt;P packet none = 9.2756e-01&lt;br /&gt;P packet none = 6.9752e-02&lt;br /&gt;P packet lost = 2.6897e-03&lt;/p&gt;
&lt;p&gt;Using this python 3.6 script:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;#39;&amp;#39;&amp;#39; Calculate advertising packet loss based on the Poission distribution &amp;#39;&amp;#39;&amp;#39;
import math

# Link Layer packet lengths.
PREAMBLE_LENGTH         =  1
ACCESS_ADDRESS_LENGTH   =  4
HEADER_LENGTH           =  1
LENGTH_LENGTH           =  1
PAYLOAD_LENGTH          = 37    # 6 + Advertising data bytes
CRC_LENGTH              =  3

# Link Layer
LINK_LAYER_PACKET_LENGTH = (PREAMBLE_LENGTH +
                            ACCESS_ADDRESS_LENGTH +
                            HEADER_LENGTH +
                            LENGTH_LENGTH +
                            PAYLOAD_LENGTH +
                            CRC_LENGTH)

# For a 1 Mbps data rate the symbol period:
BLE_SYMBOL_PERIOD = 1.0E-6

# The Data Packet duration, this is the period of one symbol multiplied
# by the number of bits (bytes * 8) in a packet.
LINK_LAYER_PACKET_PERIOD = BLE_SYMBOL_PERIOD * LINK_LAYER_PACKET_LENGTH * 8

BEACON_COUNT                = 100
BEACON_ADVERTISING_INTERVAL = 500E-3
SOFTWARE_LATENCY            = 0.0  #3.0E-3

def poisson(k, lamb):
    return math.exp(-lamb) * math.pow(lamb, k) / math.factorial(k)

def main():
    print(&amp;quot;Beacon Count             = {}&amp;quot;.format(BEACON_COUNT))
    print(&amp;quot;Advertising Interval     = {:.0f} msec&amp;quot;.format(BEACON_ADVERTISING_INTERVAL * 1000))
    print(&amp;quot;Link Layer Packet Length = {} bytes, {} bits&amp;quot;.format(LINK_LAYER_PACKET_LENGTH, LINK_LAYER_PACKET_LENGTH*8))
    print(&amp;quot;Link Layer Packet Period = {:.0f} usec&amp;quot;.format(LINK_LAYER_PACKET_PERIOD * 1.0E6))

    p_packet_none = 0.0     # The probability that no packet is received or lost.
    p_packet_recv = 0.0     # The probability that a packet was received.
    p_packet_loss = 0.0     # The probability that a packet was lost

    lamb = (LINK_LAYER_PACKET_PERIOD + SOFTWARE_LATENCY) / (BEACON_ADVERTISING_INTERVAL / BEACON_COUNT)
    for k in range(0, 10):
        p = poisson(k, lamb)
        if k == 0:
            p_packet_none = p
        elif k == 1:
            p_packet_recv = p
        elif k &amp;gt; 1:
            p_packet_loss += p
        print(&amp;quot;P({:3d}, {:.3f}) = {:.3e}&amp;quot;.format(k, lamb, p))

    print(&amp;quot;&amp;quot;)
    print(&amp;quot;P packet none = {:.4e}&amp;quot;.format(p_packet_none))
    print(&amp;quot;P packet none = {:.4e}&amp;quot;.format(p_packet_recv))
    print(&amp;quot;P packet lost = {:.4e}&amp;quot;.format(p_packet_loss))

if __name__ == &amp;#39;__main__&amp;#39;:
    main()
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here are some thoughts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Are you using just 1 frequency for BLE advertisements? This is a fundamental assumption I have made and if it is incorrect then none of this makes any sense.&lt;/li&gt;
&lt;li&gt;If you are then the most likely point of loss is that the BLE central which is receiving the advertisements is blocking and getting in the way of reception? Increasing the SOFTWARE_LATENCY value to 3.0E-3 (a very large value) will get you in the ballpark. Is your accounting on the Central side using a blocking printf()?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is a very, very interesting setup that you have and I would like to know how your results turn out.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164126?ContentTypeID=1</link><pubDate>Mon, 07 Jan 2019 01:05:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c75a40e5-f93d-4783-93cd-f1f188f5ebf9</guid><dc:creator>ReedLi</dc:creator><description>&lt;p&gt;Hi, i test 1 advertiser just now, and i get nearly zero packet loss.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Scan Beacons loss too many packets</title><link>https://devzone.nordicsemi.com/thread/164120?ContentTypeID=1</link><pubDate>Sun, 06 Jan 2019 19:07:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ca2e685-3218-48df-9294-2b638c340d5f</guid><dc:creator>natersoz</dc:creator><description>&lt;p&gt;That sounds like a pretty cool setup!&lt;/p&gt;
&lt;p&gt;If you reduce your beacon count to just 1 advertiser then do you get nearly zero packet loss?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>