-
Hi, for an application, I need to always be monitoring a set of BLE devices (identified by their MACs), which move around the ESP32 running the NimBLE instance. The ESP32 is stationary. I would need to figure out in the most real time possible, when one of such devices is close enough to the ESP32, and I thought that RSSI is a good enough approximation. The ESP32 also does other tasks in the mean time, so I thought that scanning in a non blocking way would be the way to go. But I find it difficult to debug, i.e. I see discontinuity or delays in RSSI updates, and I am not sure, even with active scan on, if I am doing it right. What is the intended behavior of NimBLE in this case, ie. continuous nonblocking scan? when does it call the callback for a specific MAC/device? Many thanks to anyone who can shed some light on this / can suggest the right way to achieve my needs. As to why Real time is needed, it's a toy for kids of a friend, some kind of Red Light / Green light game. They have a mifit band each and the one which gets within a certain radius of the esp32 scores one point :-) |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 27 replies
-
Hi @mbariola, the continuous scan is intended to simply keep scanning and provide data through the callback provided. There is an internal cache that is configurable and that will filter recently seen devices until the cache is full, at which time it is cleared and the previous devices will be reported again. For your purposes I suggest not using active scan. That has the effect of delaying scan reports until scan responses are recieved, unless there is data you're interested in from those scan responses of course. |
Beta Was this translation helpful? Give feedback.
-
This is a good start, there are a few things to incorporate to make this more robust though. Have a look at https://github.com/h2zero/NimBLE-Arduino/blob/master/examples/NimBLE_Scan_Continuous/NimBLE_Scan_Continuous.ino In the callback you should not call In the callback you can retrieve the RSSI from the advertised device using |
Beta Was this translation helpful? Give feedback.
-
Hi @h2zero , here's the results of the new sketch including the setScanDuplicateCacheSize(10) and the setMaxResults(0) statements
A heads up: NimBLEDevice::setScanFilterMode(....) does not appear in the doxygen documentation;
|
Beta Was this translation helpful? Give feedback.
-
Awesome! thanks for the confirmation! |
Beta Was this translation helpful? Give feedback.
-
Sorry to bother you again. I am stumped again. I am trying to build a beacon scanner. The user will input the target MAC address, and the scanner sketch will do something when it "sees" the target beacon. I want the target MAC to be placed on the whitelist. OK, so far, so good. mbariola's sketch does that perfectly for public address MACs. The problem I am having is that the user will not know if their beacon MAC is a public address or random static address. So if they input a random static MAC address such as dd:34:02:06:34:17, mbariola's code won't work because the MAC will be missing the beacon type indicator: , 1. Searching for clues, I looked at your sample sketch "NimBLE_Scan_Whitelist demo" which is able to scan, see, and add a random static address to the whitelist, but I am not sure why it works there. This works for random static address beacons in Whitelist Demo sketch: But this doesn't work in mbariola sketch: Thanks for any suggestions! |
Beta Was this translation helpful? Give feedback.
Hi @h2zero , here's the results of the new sketch including the setScanDuplicateCacheSize(10) and the setMaxResults(0) statements
So apparently either I am making some mistake / don't understand something, or I need to clear or remove the specific scan from the results set. The idea of a possible exception is quite scary though! Maybe you can run this sketch with one device, and see if you have different results than mine
A heads…