Mosquitto (MQTT) Emon Pi (Open Energy Monitor) Forwarding Bridge

Andrew Bolster

Senior R&D Manager (Data Science) at Synopsys Software Integrity Group and Treasurer @ Bsides Belfast and NI OpenGovernment Network

Super quick one this time; I’ve been experimenting with MQTT to act as a central messaging broker for “Farset In-Space Related Stuff” as part of the near continuous renovations and expansions.

We previously had a well configured EMonPi set up with nice dashboards and things, but that died a death at some point during the move, who knows.

Anyway, EmonPi has a built in mosquitto broker, which it uses to keep ‘state’ across several parts of the emonpi ecosystem.

On the other side, I had a relatively easy job getting Mosquitto set up via Docker on our Synology NAS (also NodeRed, but that’s for another day), however I had no idea how to connect the two.

I was expecting the kind of intricate surgury to ‘replace’ a core part of emonpi’s architecture with an ‘off-device’ broker, and all the failure that that would entail, but helpfully, the MQTT protocol has a concept of “bridgeing”, where you can effectively make one Broker ‘publish’ all it’s topics on another broker. Super Easy, Barely an Inconvenience.

TL;DR Create a file called bridge_over_the_river_que.conf* in the mosquitto/config/conf.d/ folder on the source device (in this case the emon pi), with the following contents *

#connection farset

connection bridge-fsl
address 192.168.1.222:1883

topic # out 0

If you want to make the ‘bridge’ bi directional, you can add topic # in 0 to also grab everthing from the ‘destination’ broker, but in this case, we don’t want that.

If we wanted to be pedantic and to only forward emon sensor topic values, or values from a particular device, you can replace the # with the appropriate topic wildcard (you knew that you could do wildcards in MQTT right? Cus I didn’t!)

* Naturally, adjust the values to something that makes sense in your setup….

Published: February 18 2020

  • category:
blog comments powered by Disqus