I got everything working properly on the 0.9beta, on a nodemcu with bme280,bh1750, and srx882/stx.
The problem is that although the “debouncing” works sometimes (i.e. the OMG will only publish an RF code once and then ignore it for a few seconds), other times it sends the same code rapidly 2-4 times in less than a second. The result is my HASS turning the light rapidly on and off since the mqtt switch toggles my light.
In this mqtt gateway client screenshot you can see the code being sent once and then the HASS sending the light ON command, and then on the next time i press the RF button, the code is sent 4 times rapidly and then the HASS sends light ON/OFF commands rapidly 4 times (the last one is another time where the receiver picked it up wrongly)
Ok, i got a chance to take a look at the code on the RF and MQTT publishing, and correct me if im wrong:
You read the RF data
You check if the MQTT data with the RF value is a duplicate by checking the ReceivedSignalArray
You publish the MQTT message
Only when the MQTT message is received back in the gateway you store it in the ReceivedSignalArray via the receivingMQTT method
If that is so, that means you could send many MQTT messages for a single RF value by the time the MQTT message is received back and logged for avoiding duplicates. Wouldnt storing it as soon as you publish it be a better method and solve the duplicates?
In multiple gateway scenario, if the 433mhz data arrives to multiple gateways, more than 1 gateway may manage to send the same MQTT message before the MQTT broker “RFToMQTT” message arrives to the gateways. I dont know how to solve this, and i dont know how common this scenario is.
In single gateway scenario like the one i have, the 433mhz data which is continuously sent by switches can be picked up multiple times in the gateway before it gets the message back from the broker and stores it in the ReceivedSignalArray. The solution im offering for this scenario is to store the RF data in the ReceivedSignalArray both when the MQTT message arrives (for the multiple gateway scenario like you said), and as soon as the MQTT message is sent from the gateway. If im not wrong, this will keep the multiple gateway unchanged, and prevent the multiple CQTT messages i’ve shown in the screenshot
In my setup this is not really an issue mainly due to the fact that the chain with the broker is quite fast. Maybe due to the fact that I’m using ethernet and not wifi.
Yes good idea it should work both case if we do it this way. I will open a PR
2 weeks in, no duplicates.
By the way, it seems to be closely related to the load on the program (without the change), not the network speed. for example if i run the code without the change on an esp8266 the duplicates happen a lot, whereas the esp32 which has the RF read on a separate core almost never has the issue unless i also run the BT gateway on it, and then the duplicates happen more, and also cases where the RF message is completely missed due to a large delay between RF read cycles caused by the BT read cycles.