2 mqtt brokers

Hey guys,

I have 2x openhab 2.5 servers working on the same network, and 2 separate mqtt brokers. Can someone point me in the right direction of publishing and subscribing to each broker?

Many thanks

It’s not an identical thread title, but -

Why two brokers? There can be reasons why one might want to run two but typically if they are on the same network it is far easier to have them use the one central broker instead of two separate brokers. Now that we have the XYProblem out of the way, you have several options depending on what you are trying to accomplish.

  1. Configure both OH instances with two Broker Things, one for each MQTT Broker. Then you can create the Things as needed under each broker.

  2. Bridge the two broker instances. Search google for how to do this using your specific MQTT brokers. This is outside the scope of OH so you will find more information elsewhere.

im sure that i could add another broker to my mqtt.cfg file eg mosquitto and mosquitto2? and subscribe to mosquitto2?

Hi Rich,

Thanks for the reply (again), i’m actually having a weird issue with Openhabian for the last week or so, my Openhabian (rpi3) has been crashing? it has been working flawlessly for months. I decided that maybe an upgrade to 2.5 might be a fix but it hasn’t worked out too well. For some reason its still crashing and all the work that i did that day has vanished? but everything before that is still there. I have thermostats all connected via tasmota and thought that adding another rpi0 to just run my heating might be a good idea? but maybe not?

I’m pretty sure have used a second broker before with Openenergy monitor but a can’t remember the set up?

All a bit vague i know, I think I might do another clean install and stick to one broker

Many thanks

A ha, this is why the XY problem is so pernicious. Your real problem isn’t bridging MQTT brokers, it’s that you have a machine that is crashing. Instead of messing around with MQTT, maybe it’s better to figure out why it’s crashing.

First of all, what is crashing? The whole machine or just openHAB? Define “crashed”, there are a ton things that word can mean. Does the machine freeze? Reboot? Are there logs? Does it happen at random or in direct response to some event or time?

This is very often a symptom of a failing SD card. You make a bunch of changes and as soon as the machine reboots or after a few hours, the changes revert back and are lost. I discovered a failing SD card once because the openhab.log file wouldn’t rotate. I’d delete the log file, later OH would reboot, and the multigigabyte log file would return.

It’d be a much better idea to solve the crashing problem rather than trying to work around it.

Use a new SD card for sure.

As I indicated above, you can connect OH to as many brokers as you need to, 1.x and 2.x versions of the binding. It’s definitely possible to connect to more than one broker. And as I hinted at above, there can be some very good reasons to have more than one broker on a LAN. For example, I have a HestiaPi which is a thermostat built using openHAB and an RPi. This setup uses it’s own MQTT broker for OH to communicate with the UI on the touchscreen. I can easily make it use my “main” MQTT broker but I like having the HestiaPi work even when the WiFi may be down. Therefore I have my main OH configured with a connection to both brokers and I’ve defined Things to pub/sub to the HestiaPi to monitor and control it from my main OH.

But in this case it makes some sense because the openHAB, MQTT Broker, and the UI that communicates with OH over MQTT are all on the same machine so it’s all self contained. I would not have added another broker if that broker were running on a separate machine. It adds a lot of complexity over all for dubious reliability gains.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.