Connecting to a separate MQTT broker

Hi - I have a fresh install of EmonCMS on a Rpi B. I have MQTT working to the emoncms broker inside the RPi but I would like to direct the messages to my MQTT broker on my HomeAssistant instance on another Pi.

I am successfully connecting to both mqtt brokers using the mqtt exploer app so I know both brokers are working fine.

I seem to have read and re-read all the docs/online but must be missing something as I can’t seem to get the mqtt messages to go to my existing broker. I’ve tried:

  1. Editing the emonhub config and pointing to my existing broker by IP etc
  2. Editing the example-settings.php file to my my existing broker by IP etc (rebooting)

in both cases the mqtt messages still go to the emocms broker. I see the documents refer to a settings.php file in the /var/www/emoncms directory but the closest I have are:


[email protected]:~ $ ls -la /var/www/emoncms/scripts/services/emoncms_mqtt/            total 32
drwxr-xr-x 2 pi pi  4096 Jan 12 21:55 .
drwxr-xr-x 5 pi pi  4096 Jul 21  2021 ..
-rw-r--r-- 1 pi pi 16727 Jan 12 21:55 emoncms_mqtt.php
-rw-r--r-- 1 pi pi  2266 Jul 21  2021 emoncms_mqtt.service

I have also read in another post that you can also ‘bridge’, I’d be happy doing that also but need to know where to put the configuration for the mqtt bridge. The youtube video by Steve Cope refers to a specific mqtt.conf file but cant find that file either.

ok -so to answer my own question, (in the hope it helps others out there).

The correct file to update is settings.ini located in /var/www/emoncms

I did find other posts indicating that the settings.ini file is the one to update. I now understand the settings.php files are deprecated?

I added/modified the following lines


enabled = true

host = ''

port = 1883

user = 'mymqttuser'

password = 'mymqttpassword'

basetopic = 'emon'

client_id = 'emoncms'

…now to get on with other work :crazy_face:

1 Like

Yes, there needs to be a ‘Settings’ section in the docs.

I know you’ve solved this now, but as you mentioned bridging, I thought I would respond.

I chose to leave emonhub running its own broker and bridged it to the broker on my home assistant server. To do this, you need to edit the config for Home Assistant’s Mosquito Broker.

  1. enable customization in the config
  2. use SMB or ssh to access the host folder /usr/share/hassio/share/mosquitto
  3. Create the file bridge.conf with the contents:
connection <name>
address <ip address>
remote_username <user>
remote_password <password>
topic # out 0
topic # in 0

the remote_username and password are only needed if the emonhub broker requires it.

With this setup, when the HA broker starts it will connect automatically to the emonhub broker and exchange all messages.

1 Like

Thanks for your input Gareth - I might give this a go this weekend. As things have stabilized I’ll make backup’s before experimenting! :smile:

Just as an side, I use WinSCP to get access to files on RPi’s on my network. Very useful tool.