[solved] Local Mosquitto broker - CloudMQTT bridge

Hey there,

I’m in the process of moving from Hassbian to Hass.io
In my Hassbian setup I use a MQTT bridge connection to sync my Owntracks data with my local MQTT broker (link). Now I was wondering if and how I can accomplish the same with Hass.io.

Any help would be appreciated

+1 Would also greatly appreciate any help with this

Hey, I was trying to extend the stock mosquitto addon to include the necessary file.

How can I check the mosquitto.conf file on the raspberry pi? When SSHing into the /etc folder, it’s not there. Is there a “developer” SSH version where I see all the files of the filesystem?

Thanks!

This file would be inside docker which is kind of small virtual machine. You’ll need to

  1. SSH to host
  2. View running containers docker ps
  3. Find Image Id of your container (local/mosquitto something)
  4. docker exec -it <container id> bash

Another option is to change location of your conf file and to serve it from, for example, share folder (refer to hassio documentation describing linking folders)

1 Like

It seems I’m having difficulties with the second step already.
I followed xbmcnut’s tutorial here for setting up ssh.

Judging by ASCII-art it’s not a host ssh, but rather ssh add-on you’ve installed :slight_smile: You need connect to resin itself https://home-assistant.io/hassio/debugging/

1 Like

Hey @vkorn,

I’m using a windows machine, so except the boot partition I cannot access anything if I put the sd card into my reader. Do you know any solution to get the public key onto the root partition?

You won’t need anything. To enable ssh you have to drop key into the /boot partition

1 Like

So, I managed to modify it and get it running properly, big thanks to @vkorn!
If anyone is interested, here is the repository.

This is an example Options configuration:

{
  "plain": true,
  "ssl": false,
  "anonymous": false,
  "logins": [
    {
      "username": "Testuser",
      "password": "testpw"
    }
  ],
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem",
  "bridges": [
    {
      "connection": "cloudmqtt",
      "address": "cloudmqtt.com_address:port",
      "remote_username": "bridge_testuser",
      "remote_password": "bridge_testpw",
      "clientid": "HomeAssistant",
      "try_private": "false",
      "start_type": "automatic",
      "topic": "# in"
    }
  ]
}

It is possible to create more than one bridge.
Maybe someone can test it and merge it with the official addon (I’m not a programer)?

This did not work for me… any thoughts?

You don’t need it anymore. It’s now implemented in the official mosquitto broker plugin.

check https://home-assistant.io/addons/mosquitto/ for further details

What should the ‘clientid’ be? Can it be anything? I’ve used ‘hassio’ but I get the following error when in MQTT.

starting version 3.2.2
1502536497: mosquitto version 1.4.12 (build date 2017-06-01 13:03:48+0000) starting
1502536497: Config loaded from /etc/mosquitto.conf.
1502536497: Opening ipv4 listen socket on port 1883.
1502536497: Opening ipv6 listen socket on port 1883.
1502536497: Warning: Mosquitto should not be run as root/administrator.
1502536497: Connecting bridge cloudmqtt (m11.cloudmqtt.com:11576)
1502536498: Socket error on client local.hassio, disconnecting.
1502536528: Connecting bridge cloudmqtt (m11.cloudmqtt.com:11576)
1502536528: Socket error on client local.hassio, disconnecting.

I can log on to m11.cloudmqtt.com:11576 using MQTT.fx so I know the connection and account is OK.

Do you have an exposed port so that it can connect?

Not sure what you mean? I’m getting the local MQTT add-on trying to connect to a remote CloudMQTT instance using the customize option. I have no outbound port firewalls.

I’m not at home right now, but in cloudmqtt you’ve to create a new user with access rights to the topics you want to sync. I used this user as my client id

I created three users and I tried using the name for the first user as the clientid and I get the same error.

Hello all, I added the MQTT addon to Hassio, and my options currently look like this:

{
“plain”: true,
“ssl”: false,
“anonymous”: true,
“logins”: [
{
“username”: “username”,
“password”: “password”
}
],
“customize”: {
“active”: false,
“folder”: “mosquitto”
},
“certfile”: “fullchain.pem”,
“keyfile”: “privkey.pem”
}

I then added this to my config:

mqtt:
broker: 172.17.0.1

I then saved it, restarted the addon and rebooted the Pi. How can I tell if it is running properly? I am trying to set it up to get an addressable LED strip working through Hass (from Ben’s video).

Thanks!

Download MQTT.fx, it’s a life saver. Create a connection to your broker using the IP, username and password you set and then subscribe to # (everything). You can then use that to publish commands and to see what is happening at the broker. Great tool if you’re not into the command line stuff.

1 Like

Wondering if you can confirm your config for me? If I use CloudMQTT as my broker (instead of the local IP) I connect to CloudMQTT and see that my position reported by Owntracks is being updated. If I then revert to the hassio MQTT add-on with a customize option using the same credentials as before (but now in a conf file), I get socket errors and disconnection.

Hey @xbmcnut,

this is the config in the mqtt addon:

{
  "plain": true,
  "ssl": false,
  "anonymous": false,
  "logins": [
    {
      "username": "REDACTED",
      "password": "REDACTED"
    }
  ],
  "customize": {
    "active": true,
    "folder": "mosquitto"
  },
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"
} 

This is my *.conf file (located in share\mosquitto)

connection cloudmqtt
address REDACTED
remote_username me-Hassio
remote_password REDACTED
clientid me-Hassio
try_private false
start_type automatic
topic # in

And these are the users for owntracks

2 Likes