Nrf52 slow scanning

dhavaldalvadi gravatar image

asked 2018-01-09 12:33:30 +0100

updated 2018-01-09 12:33:58 +0100


I have made ble scanner using nrf52 and I have set uart baud rate 921600 and sending scanned beacon to other micro-controller for processing but It does not scanning all beacons.

I have around 100 beacons now and it takes around 10 seconds to scan all beacons(100) I have set beacon interval to 500ms.

Is nrf capable to scan all beacon that broadcasted?

I need to scan around 5000 beacons. is it possible to scan and send all beacons? if yes, then how much time it will take to scan and send 5000 beacons?

edit retag flag offensive close delete report spam

2 answers

Sort by » oldest newest most voted
ovrebekk gravatar image

answered 2018-01-12 16:34:38 +0100

updated 2018-01-12 16:35:44 +0100


Endnode has already covered the issues of having multiple advertisers in the same area, so I will focus only on your specific use case.

Sending a single advertise packet with 20 bytes of data takes about 350us.

If 5000 advertisers in perfect synchronization sent one packet after each other this would take 1.75 seconds in total.

In other words, if the advertising interval is lower than this then there is no way to fit all the advertise packets, there simply isn't enough time available. In practice the advertising interval would have to be significantly larger, to reduce the chance of packet collisions.

The chance of a collision between an advertiser and one particular other advertiser is approximately (2*L)/I, where L is the length of the packet and I is the interval of both advertisers.
The chance of colliding with one (or more) among a number of advertisers: PL = 1 - ((1 - (2*L)/I)^N)

With an interval of 1.75s this leads to a packet loss of 86% with 5000 nodes in the same area. Increase the interval to 10s, and packet loss drops to 30%, which might be acceptable.

Still, it is hard to predict how long it will take to read all the beacons. Scanning for 10 seconds should allow you to read 70% of the available beacons, following the same example. If you read for 10 seconds more you get 70% of the remaining 30%, and so on, but to be guaranteed that every single device is read you need to scan for a long time ;)

Best regards

edit flag offensive delete publish link more


If i will scan for 1 second and send it using spi what time it will take how can i calculate it? how much packet loss?

Dhaval Dalvadi ( 2018-01-13 13:22:50 +0100 )editconvert to answer


If you use my example above as a guide then you would receive 7% of the packets after 1 second, which means the packet loss is 93% ;)

If you are really serious about trying to scan 5000 beacons as quickly as possible you might want to consider using three different receivers in the scanning device. Then you can receive on all three advertising channels at the same time, allowing you to reduce the advertising interval (and the number of packet collisions) while maximizing the scanner throughput.

Best regards

Torbjørn Øvrebekk ( 2018-01-15 14:05:58 +0100 )editconvert to answer
endnode gravatar image

answered 2018-01-10 10:48:28 +0100

nRF5x chips are able to receive up to 2 ADV_xx packets per millisecond so scanning bandwidth is much higher then in your experiment (100 devices sending 2 packets per second make it 200 packets on given channel per 1000 millisecond = 0.2 packets per millisecond in average).

However you don't really say what scanning parameters you use (you need to set 100% duty cycle aka having the same scanning interval and window). Even with 100% duty cycle Nordic BLE stack (Soft Device) needs very small switching time when it closes one scanning window on one (of 3) advertising channels and moves to another. But that can be neglected if the scanning window is reasonably long.

Finally you need to understand that this is probabilistic game. First of all scanner (like nRF5x device) can listen only on one channel at the time so make sure that your advertisers advertise one packet on each channel each advertising interval. Secondly there is nothing like "thousands of beacons send packets and someone else will receive them". There indeed will be collisions - because advertisers are asynchronous - and these will be more likely if there will be more devices. Already with several hundreds of devices you will get some collisions and with thousands the probability will start to grow. If there are two packets colliding (even partially) then even if scanner listens the packet will be dropped because integrity checksum will be invalid. So what you should expect it: if you have 100 beacons in the room advertising with ~2Hz frequency on all 3 channels then any nRFx scanner should see all packets from all devices with >99% (or something like that). Once you grow number of advertisers to 500 the probability will lower by few percent and so on. I'm not having this model computed so the numbers are just based on my own experiment. But if you really care about this use case then you should easily make and compute correct statistical model in few hours or days (with proper books and all the knowledge of the mankind on the internet;)

edit flag offensive delete publish link more


How can i set 100% duty cycle? I have tested with same scanning interval and window but no difference.

Dhaval Dalvadi ( 2018-01-10 10:56:52 +0100 )editconvert to answer

Scanning interval must equal scanning window. I'm afraid you should blame your HCI/serialization set-up, If I collect advertising events on GAP Scanner running directly in nRF51 FW on top of S130 I have basically 100% packet capture if I have dozens of beacons with ~100ms interval. I never tried experimental collision rate for situation with 100/500/1000/5000 beacons advertising at 2Hz but if you have them then you should simply by professional BLE sniffer or radio analyzer and set the benchmark with these. Then you can say what is expected maximum percentage of detected packets and you should try to achieve the same with well written FW on nRF5x chip itself. Only then I would move to some relayed system over (stupid) UART.

endnode ( 2018-01-10 11:27:47 +0100 )editconvert to answer

To transfer data from nrf to other microcontroller I must require to use UART is there any other fast way?

Dhaval Dalvadi ( 2018-01-10 11:51:52 +0100 )editconvert to answer

Sure, SPI is typically faster (goes beyond 1Mbps).

endnode ( 2018-01-10 11:53:33 +0100 )editconvert to answer

But that shouldn't be your problem if your UART protocol is reasonable (which i probably isn't;)

endnode ( 2018-01-10 11:54:01 +0100 )editconvert to answer

you don't have given answer how to set 100% ?

Dhaval Dalvadi ( 2018-01-10 12:37:47 +0100 )editconvert to answer

I did, but if you need it 3rd time then here it is: "Set scanning interval equal to scanning window."

endnode ( 2018-01-10 12:39:13 +0100 )editconvert to answer

Oh sorry I think that "Setting scanning interval equal to scanning window" and duty cycle both are different

Dhaval Dalvadi ( 2018-01-10 12:41:44 +0100 )editconvert to answer

I want to say one thing that I am transferring only usable data using uart like mac address major minor etc that is of 21 character for one beacon. I have stopped scanning when transferring data using uart and start scanning after uart write

Dhaval Dalvadi ( 2018-01-10 12:43:52 +0100 )editconvert to answer

That's another example of stupid UART: if you stop scanning you indeed cannot achieve 100% duty cycle;))) Also nRF5x chips can do UART Tx any time without need to stop scanning so it's question why you do it. Another question is how you "command" the BLE stack. If you use UART not only for reporting events but for full serialization (or BLE HCI layer) then indeed again overhead of all these commands can kill your scanning bandwidth.

endnode ( 2018-01-10 12:46:55 +0100 )editconvert to answer

I have removed stopping scanning when transfer to uart and set SCAN_INTERVAL and scan_window 0x0010 but not get any difference what is full serialization (or BLE HCI layer)?

Dhaval Dalvadi ( 2018-01-10 12:53:02 +0100 )editconvert to answer

Sorry but to me your set-up isn't close enough to ideal. I got you some scenarios what to do if you want to set-up seriously. Minor tweaks won't help you until you are 100% sure what actually is the best achievable scenario. If you don't have time or capabilities to do it then I'm afraid I cannot help you. But maybe someone smarter will go by and drop some wisdom here...

endnode ( 2018-01-10 12:55:20 +0100 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

Question Tools



Asked: 2018-01-09 12:33:30 +0100

Seen: 66 times

Last updated: jan. 12