Hi guys, I get stuck at implementing a synchronization protocol for wireless transmission and I’m seeking some advice here. This is what I’m planning to do:
Two Audrino boards with sensor A and sensor B and RF module nRF24L01. They don’t know each other’s existence. The transmission mode is a sleep-wake up mechanism (let’s assume the wake up time is 50 ms and sleep time is 500 ms)
Audrino A and B are powered on separately and start scanning. Once they know the other node’s existence,
they will try to synchronization and start get the sleep-wake up mechanism synchronized.
My problem is: how can I achieve this goal? Should I use a RTC module? Or the build in function millis() is good enough? Any tip would be appreciated.
My problem is: how can I achieve this goal?
You probably can't.
Should I use a RTC module?
If you get each one a clock, you have no way of knowing that the two clocks will, accidentally, once in a while, return exactly the same time.
Or the build in function millis() is good enough?
You have a "clock", on each Arduino, that tells you how long the Arduino has been running. How will THAT be useful for synchronizing anything?
In general, if Arduino A can't miss anything that Arduino B sends, and Arduino B can't miss anything that Arduino A sends, neither can go to sleep.
if the purpose of the sleeping is to save energy then you can implement a simple system which does not need any clock (apart from millis() ).
Treat one of the Arduinos as Master and have it send a signal at regular intervals - say every 50 msecs. If it gets no response it repeats the message at 1 msec intervals for a max of 5 msecs. (thus it only needs to be awake for 10% of the time).
The other Arduino (the Slave) needs to wake occasionally to detect the message from the master. If the slave is awake for a max of 55 msecs on any one occasion it MUST overlap with one of the transmissions from the master. If you use the ackPayload feature it will automatically send the data and can then go back to sleep for (say) 500 msecs so it is also only awake for 10% of the time.
Or some variation on the above.
Simple nRF24L01+ Tutorial
in thinking about this, how vital is the data that is being sent ?
if you can miss a bunch of readings, such as soil moisture for plants, then life gets easier.
Robin2 offered the overlapping wake/sleep
if the slave wakes up 2ms early and re-sets it's time to sleep by the leading edge of the receip of the message, then they willl be paired .
if the slave wakes up 2ms early, and does not get a message, it can either stay awake for an entire loop (or two) before it decides the master is not broadcasting.
you need to decide the requirement and value of missing the link
and create a scheme where the slave will be awake in longer than normal times, but sleeping, in such a way that the wake/sleep will overlap the send from the master if they are way out of sync. should not be that hard. wake/sleep 50% for 2 cycles, then reverse and sleep/wake 50% for the next 2 cycles.