Understanding sendWithRetry - preventing duplicated payloads in gateway

Started by st4k, May 25, 2017, 11:40:39 AM

st4k

Hi! I am building a wireless temperature monitoring probe and I use rfm69hw radios and Felix Rusu's RFM69 library. I have following setup:

[1]Node (arduino+rfm69) --> wireless transfer --> [2]Gateway (arduino+rfm69) --> i2c transfer --> [3]Ethernet gateway (arduino+ethernet) --> ethernet -> mysql database

So node sends struct as a payload via rfm69 to other rfm69 gateway and this gateway pass the struct to other ethernet gateway via i2c.
I am currently using just send() function and it works well. I was thinking about changing to sendWithRetry() in my node and handle replying with ACK on gateway side. I already tested it and it also "just works". But I intentionally commented sending of the ACK on [2]Gateway and then I noticed duplicated payloads in [3]Ethernet gateway.
I know this was "forced reproduction of the problem", but this could really happen in real life. I mean payload transmitted from [1]Node will reach [2]Gateway but ACK will not reach the [1]Node due to some interference or whatever issue. It could happen when the signal is on it's edge - so one side can still "hear" other but not the opposite way.

I would like to have sendWithRetry() for better reliability but I do not like the duplicates being stored in my database. I am transferring also "counter" in the payload so I could theoretically send the payload from [2] to [3] only in case last_counter != current_counter but as I plan to use more nodes then maybe some more smart way would be better. How to handle such scenario?

perky

If you're saying the node sends data then looks for an ACK, and if it doesn't get it the data will be repeated and the gateway could end up with multiple copies, then I think you need to maintain separate counters for each node in the gateway. Each node would increment it's own packet counter when sending packets, and the gateway would check whether the counter had incremented or not for that node to determine whether it is new or repeated data. If a node sends data but doesn't get an ACK it will resend the data with the same count value as before. That would allow multiple nodes as the gateway will have separate stored count values for each node.

Mark.