Bridge 2 MQTT Brokers and rename topics


I have Solar Assistant running on my network and i can subscribe to its broker.

when i run mosquitto_sub -h -p 1883 -v -t '#' i get a stream of output data

I would like to have that MQTT data show up in emoncms running locally.

Please where do i enter the Solar Assistant broker details and what do i need to do to have them show up as input in emoncms?

tried editing the settings.ini as read in some other posts but nothing shows up

can’t find a place to input broker detains in INPUT/AddDevices

Thank you


Please help

Have you seen the MQTT docs: MQTT — OpenEnergyMonitor 0.0.1 documentation

For data to appear in emoncms, the broker emoncms is connected to must be receiving the data. emoncms cannot connect to 2 brokers simultaneously.

The data sent to the broker emoncms is connected to, must be sent on the base topic emon/

You need to extract the data from your Solar Assistant MQTT Broker, reformat for emoncms and then send to the emoncms Broker.

I do this sort of thing in Node-RED. If the data is in HomeAssistant, you could just send it from there.

On my computer running Ubuntu

I have installed emoncms using the instructions/script

I have solar assistant running.
its broker is publishing, and i can subscribe to it as in the following example:

$ mosquitto_sub -v -h -p 1883 -t 'solar_assistant/inverter_1/#'

solar_assistant/inverter_1/grid_frequency/state 0.0
solar_assistant/inverter_1/pv_current_1/state 0.0
solar_assistant/inverter_1/pv_power/state 662
solar_assistant/inverter_1/battery_voltage/state 25.6
solar_assistant/inverter_1/load_apparent_power/state 235
solar_assistant/inverter_1/pv_current_2/state 4.8
solar_assistant/inverter_1/temperature/state 33.0
solar_assistant/inverter_1/load_percentage/state 6
solar_assistant/inverter_1/battery_current/state 26.0
solar_assistant/inverter_1/grid_power/state 0
solar_assistant/inverter_1/pv_voltage_1/state 4.8
solar_assistant/inverter_1/pv_voltage_2/state 138.0
solar_assistant/inverter_1/pv_power_1/state 0
solar_assistant/inverter_1/device_mode/state Solar/Battery
solar_assistant/inverter_1/grid_voltage/state 2.0
solar_assistant/inverter_1/ac_output_frequency/state 49.9
solar_assistant/inverter_1/ac_output_voltage/state 229.0
solar_assistant/inverter_1/load_power/state 235
solar_assistant/inverter_1/pv_power_2/state 662

After reading up, i setup a MQTT bridge in /etc/mosquitto/conf.d/ as follows:

#Begin MQTT Bridge
connection bridge01
topic # out 0
topic # in 0

the Solar Assistant broker does not have user/password for now.

my emoncms settings.ini file has the following entry:

enabled = true
user = 'emonpi'
password = 'emonpimqtt2016'

what have i done wrong?

what do i need to do?

where do i edit the broker emoncms is connected to?

Are both on the same machine?

Is this the IP of the server running both Solar Assistant and Emoncms?

You didn’t read this :point_down:

emoncms will only read data on the emon base topic.

Solar Assistant is on a Pi,
emoncms is on the Ubuntu PC
the Pi and PC are linked by tailscale, so i can access the Pi directly as though they are on the same PC

I can access it freely and subscribe and publish to it.


Clearly it isn’t the IP of both as they are on separate machines.

Let us assume the IP of SA is .157

So this has been done on the emoncms server - correct?

If so, it is pulling the data from the SA Broker to the emoncms Broker.

so run this command but with the emoncms IP address

and you should see the same topic present as on the SA server.

Just bridging the Brokers will not solve anything as the Solar Assistant Broker is publishing the data on the base topic of solar_assistant.

I think that as part of the bridge instruction you can change the topic in setting so it will modify the incoming topics to emon/solar_assistant

You will need to read up on that yourself.

You only need to be either pulling the SA stuff, you don’t need to be pushing the emoncms data to the SA Broker so the topic # out instruction is not needed.


I think

topic # in 0 "" emon/

will do it :slight_smile:

when i try this with the emoncms tailscale IP, i get a connection refused.

so it would appear that the bridge isn’t working?

You need a user and password to the Broker on emoncms. Check the docs for it.

> Oct 04 09:02:41 fountain mosquitto[63762]: 1696410161: Loading config file /etc/mosquitto/conf.d/solar-assistant.conf
> Oct 04 09:02:41 fountain mosquitto[63762]: 1696410161: Error: Invalid bridge topic direction '0'.
> Oct 04 09:02:41 fountain mosquitto[63762]: 1696410161: Error found at /etc/mosquitto/conf.d/solar-assistant.conf:6.
> Oct 04 09:02:41 fountain mosquitto[63762]: 1696410161: Error found at /etc/mosquitto/mosquitto.conf:11.

it seems my bridge is still wrong. mosquitto.service would not start

Did you read through the link to specifying a Bridge config?

I’d missed the #, but I did say I Think - it wasn’t tested :rofl:

yeah, made that correction and it now starts.

i’m looking through that MQTT page and and it would appear i have mucked something else up

1696410647: mosquitto version 2.0.18 starting
1696410647: Using default config.
1696410647: Starting in local only mode. Connections will only be possible from clients running on this machine.
1696410647: Create a configuration file which defines a listener to allow remote access.
1696410647: For more details see
1696410647: Opening ipv4 listen socket on port 1883.
1696410647: Error: Address already in use
1696410647: Opening ipv6 listen socket on port 1883.
1696410647: Error: Address already in use

$ ps -ef | grep mosquitto
mosquit+ 64077 1 0 09:08 ? 00:00:00 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

ubuntu 64392 60938 0 09:13 pts/0 00:00:00 grep --color=auto mosquitto

which one is the emoncms one?

A recent change to Mosquitto means that by default the bBroker only listens on Localhost (security).

the sledgehammer is to specify

listener 1883

in the config file.

Better security is to bind to specific IPs

still getting a not authorised error

connection bridge01
remote_username emonpi
remote_password emonpimqtt2016
topic # in 0 "" emon/

$ mosquitto_sub -v -h -p 1883 -t ‘solar_assistant/inverter_1/#’
Connection error: Connection Refused: not authorised.

You still do not have a Username and Password :frowning:

And if the redirect of topic is correct, you should see no topics starting solar_assistant

i should set

user emonpi
password emonpimqtt2016

in Solar Assistant?

i tried that and its the same error

No, on the command line you need a password an username as per the docs


$ mosquitto_sub -v -u ‘emonpi’ -P ‘emonpimqtt2016’ -t ‘test’
Connection error: Connection Refused: not authorised.

well obviously as you have not specified the target machine.

you need to add the -u and -P to your original command (and remove the topic spec).