So we have our RF nodes happily talking to one another, and most often we have one talking, one listening. This is very easy, and facilitated even in poor reception by our built in SendWithRetry function (we’re speaking of the RFM69 library here, of course). This is what a unidirectional communication structure often looks lke:
The Problem : The Retry Loop
The problem arises when we want to have two nodes talk to each other that sometimes have other stuff to do. The following situation arises, which results in failure of at least one of the communication attempts. Essentially, they get stuck in a a retry loop:
The Solution : The State Machine
The solution is rather simple: tell one node to stop retrying until it’s had a chance to listen. In pseudocode, this looks like this:
In Real Life
In real life, this is pretty easily coded using a switch statement, with a delay afterwards to allow enough time for radio messages to show up and complete. 100ms is more than sufficient.