Hello guys,
Let me try to describe my system before I ask you for your opinion…
I am using Particle Boron 2G/3G as a gateway device. The Boron should collect data from BLE-based (nRF52832) sensor nodes around and publish them to the cloud. Every sensor node is most of the time in deep-sleep mode, without any activity. Few times par day, on the pressure of a button, sensor node should wake up, and send a few bytes of data to the gateway in BLE advertisement mode. As I already explained, Particle boron should publish the data from the sensor node as soon as they are received. There will be a few (5-10) sensor nodes around one single Particle Boron gateway.
The system seems to be simple but I see a few challenges here.
-
How to be 100% sure that Boron gateway will properly receive BLE advertising messages from all sensor nodes no matter the moment in time they wake up and advertise. Consequently, Boron board should be continuously scanning (being in BLE observer mode).
-
Being in BLE advertisement mode, sensor node periodically sends advertisement messages (BLE advertising interval can be from 20ms to 10.24s) for some time defined by BLE advertisement duration parameter.
NOTE: My sensor nodes are powered with the coin-cell batteries so I am interested to advertise as short as possible!
I want to be able to publish sensor data only ONCE per BLE advertising from the sensor node, even though my Boron gateway receives a few consecutive (and same) BLE advertising messages from the same sensor node.
I was able to analyze code examples concerning BLE scanning that I found on this forum (e.g. here). The code comprises the following steps:
a) define scan Timeout interval (with BLE.scanTimeout(X)
function).
b) start scan process with BLE.scan()
function. scanResults array will be populated with the elements of BleScanResult type. Each element in scanResults array is actually one BLE device found during the scan time. We can go through the scanResults array and do whatever we want (e.g. extract MANUFACTURER_SPECIFIC_DATA only from specific BLE devices). Once we extract desired data, we can publish them with Particle.publish()
method.
c) wait for some time
d) go to step a)
The above BLE scan approach seems to be reasonable. I was able to implement it and publish some data. However, I see two challenges here:
- How can I make sure I don’t miss BLE advertisement messages from the sensor nodes that will advertise while I am in the process of publishing data from other sensor nodes (in a for loop after
BLE.scan
)? In that sense, I should not have any delay between twoBLE.scan
executions (no step c). - However, when I remove delay between two
BLE.scan
executions, I receive multiple advertisement messages from the same sensor node and, consequently, publish multiple data to the cloud instead of only one. The solution would be that I block publishing data from the single node for some time after I publish first BLE advertisement packet received but I am not sure how to implement it given the fact that I can have a few different nodes.
Do you have any suggestion for me how to avoid missing the data from the sensor node as well as how to avoid publishing too much?
I thought one solution could be to implement a kind of handshaking communication protocol here:
- Sensor node broadcasts BLE advertisement packages
- Boron observer receives BLE advertisement data and sends scan request message to the node
- Once the node receives scan request message, it replies with scan response message and goes to the sleep (stops advertising)
- Once Boron receives scan response message, it publish the data to the cloud.
What do you think about it? How can I send scan request message form the Particle Boron?
Thank you very much, guys, for your time and effort! It is really appreciated.
Sincerely,
Bojan.