MQTT plays ping-pong and floods my event bus

272 views
Skip to first unread message

Christian Becker

unread,
Jun 30, 2015, 4:44:40 PM6/30/15
to ope...@googlegroups.com
Hi There,

I wanna synchronize two openhab instances with mqtt. But the Event Bus Binding seems to take every message and plays it back to the broker. 

So on one Pi the config looks like this:

mqtt-eventbus:statePublishTopic=/openHAB/in/${item}/state

mqtt-eventbus:stateSubscribeTopic=/openHAB/out/${item}/state


and vise versa on the other 

mqtt-eventbus:statePublishTopic=/openHAB/out/${item}/state
mqtt
-eventbus:stateSubscribeTopic=/openHAB/in/${item}/state



so a message coming from system one is received by system two and send back to the event bus. I don't understand this behavior. I would expect, that messages received from mqtt won't get forwarded to mqtt again. Otherwise it would be impossible to synchronize the two instances, wouldn't it?

How to solve this?

Best regards
Chris

Christoph Wempe

unread,
Jul 1, 2015, 8:23:01 AM7/1/15
to ope...@googlegroups.com
I don't really know mqtt.
But I guess the following could happen.

Item A on openhab1 ist updated.
This creates a mqtt-message, wich is sent to openhab 2.
openhab2 receives this message, processes it and updates item A on openhab2 acordingly.
because item A in oh2 has changed, this creates a new mqtt-message which is sent to oh1.
oh1 receives the message, updates the item, creates a mqtt-message and so on ...

Christian Becker

unread,
Jul 1, 2015, 8:53:55 AM7/1/15
to ope...@googlegroups.com
I agree with this idea. The question here is, how to prevent openhab / mqtt binding from doing this? Or is mqtt-binding only build for read- or write-only? 

Robert Bausdorf

unread,
Jul 1, 2015, 10:39:58 AM7/1/15
to ope...@googlegroups.com
I think there could possibly be an design flaw in the binding. Synchronization of mqtt instances should use something like the bridge protocol (https://github.com/mqtt/mqtt.github.io/wiki/bridge_protocol) and must not repropagate messages received on the configured mqtt-eventbus:stateSubscribeTopic.

But if a rule fires on an event received by mqtt-eventbus it may cause other events which are possibly replayed ... 
So at first glance I think a complete openHAB instance sync wont work without additional item configurations/rules.

Cheers Robert

Greg EVA

unread,
Jul 3, 2015, 6:29:40 AM7/3/15
to ope...@googlegroups.com
Hi Christian,

I just read your message, and then the MQTT wiki documentation on the subject and have an idea for you.

You guys are right about the feedback loop... and for this reason when using MQTT for communications between systems it is important to use seperate topics so that this doesn't happen.  An MQTT client should not publish to a topic that it is listening on for updates....

In your message, there is configuration talk of 'state', and in/out, but no talk of 'commands' as are mentioned in the doc.  Here's the example config from the wiki:

mqtt-eventbus:broker=m2m-eclipse
mqtt-eventbus:commandPublishTopic=/openHAB/out/${item}/command
mqtt-eventbus:stateSubscribeTopic=/openHAB/in/${item}/state

What I am wondering, is perhaps the state updates on both sides are causing the loop. The above example pushes commands on a publish topic, and then updates state on the subscribe topic. What if you just try that example???

I have to say the it isn't super clear, as the doc also talks about both a pub/sub topic for EACH command and state, but then doesn't use it in the example. But I'm guessing it is what I described above.

Reply all
Reply to author
Forward
0 new messages