Mosquitto Setup Help

I wasn’t sure where to post, and I’ve been at this for last several hours and not to frustrated to continue tonight and will try and again tomorrow. But I cant’ seem to get Mosquitto configured correctly. At least I don’t think so. This on a Ubuntu 14.04LTS server VM.

On my Ubuntu setup, I installed Mosquitto mainly following the steps from the Mosquito website, but I can not get seem to get anything to connect to it. To try and show.

This is my etc/mosquitto/conf.d/mosquitto.conf file Yes, I have it in the conf.d file. Believe that is the recommended location.

listener 1883 localhost
listener 8883 localhost
persistence true
persistence_location /var/lib/mosquitto/
persistence_file mosquitto.db
log_dest syslog
log_dest stdout
log_dest topic
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true
allow_anonymous false
password_file /etc/mosquitto/passwd

As you can see I have ports 1883 and 8883 listening. And I did make an owntracks user and password at /etc/mosquitto/paswd as well as follows

mosquitto_passwd -c /etc/mosquitto/passwd owntracks

When I start mosquitto, I get this

root@Ubuntu-Server:~# mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf
1467769510: mosquitto version 1.4.9 (build date Fri, 17 Jun 2016 15:43:08 +0100) starting
1467769510: Config loaded from /etc/mosquitto/conf.d/mosquitto.conf.
1467769511: Opening ipv6 listen socket on port 1883.
1467769511: Opening ipv4 listen socket on port 1883.
1467769511: Opening ipv6 listen socket on port 8883.
1467769511: Opening ipv4 listen socket on port 8883.

So it appears to be running. But when I opening a second terminal and try and connect it fails.

# mosquitto_pub -h localhost -p 1883 -t 'owntracks/test' -m 'hello world'
Error: Connection refused

In another example, I did this to work and appears to connect. But it uses _sub?

~# mosquitto_sub -h localhost -p 8883 -v -t 'owntracks/#' -u owntracks -P MYPASSWORD

I’ve also tried with the program MQTT.fx program to connect to the machine and it fails as well. And I also can’t get the owntracks app to connect with that same username and password.

Does anyone have any clear steps or instructions to maybe purge mosquitto and start over? I’ve up to long tonight messing this and will try again tomorrow. It could be something obvious and maybe I’m just not seeing it tonight.

You are doing the right thing by trying to get simple _pub/_sub working from the command line first. My advice would be to allow anonymous connections to start with and get that working before trying to add authentication etc.

Flip the allow_anonymous config flag and try again.

I changed that to allow_anonymous true.

Now when I enter in 1 terminal of

mosquitto_pub -h localhost -p 1883 -t 'owntracks/test' -m 'hello world'

On the other I see

1467770340: New connection from ::1 on port 1883.
1467770340: New client connected from ::1 as mosqpub/2481-Ubuntu-Ser (c1, k60).
1467770340: Client mosqpub/2481-Ubuntu-Ser disconnected.

I’m not certain if that is correct? Should it be saying Hello world?

But I think that’s progress. Although attempts from a windows machine to connect with MQTT.fx still fail.

1 Like

Open two console windows and in one run the _sub command, and then in the other run your _pub. Assuming you sub/pub’ing to the same topic you should see the messages appearing.

PROTIP - add -v to your _sub command to show the topic of incoming messages.


Ben. That does give further progress. I can now see hello world popping up on the second screen when sending pub.

But I think I should now also be able to both the MQTT.fx windows program to connect and the android owntracks app to connect to that IP address, yet they fail. Both with and without username/pass and correct ports. I did even open up the port on the router as well although still within my LAN currently.


Yes, I can get exactly that so I believe it is working correctly. But why I can’t then get a windows pc with the MQttfx program or owntracks to connect to it. I’m not certain.

You have the services bond to “localhost” That is the loopback on the machine, basically the service will only listen for connections from itself. You need to change, or add (personally I would add) a line with the external facing IP address (external to the server not your house).

listener 1883 localhost
listener 8883 localhost
listener 1883
listener 8883

Obviously you’ll change to the actual IP address of the server.


So simple and was overlooking it the entire time. I wasn’t aware it actually needed the actual IP address of the machine. I’m here at work connecting into home. And port forwarding is setup and I could connect with owntracks as well.

Now tonight hopefully I can start doing some more getting the binding setup and doing some further testing.

I also stumpled across something called Pista, a back end for owntracks for possible live tracking?

You might want to test by subscribing to everything by using this command

mosquitto_sub -t /#

You may enter the command once you SSH’ed into your openHAB instance

It is also possible that you publish something using a second connection

mosquitto_pub -d -t hello/world -m "Hello from MQTT"

You should catch this one in the subscribing side

FYI - pista is end-of-life, have a look at instead. This is the new backend for Owntracks and useful for live and historical tracking etc.

Just wanted to say thank you to everyone with their help with this and hopefully it help others.

In trying to learn more, I think or may have done something where my location is no longer showing in OwnTracks? I had changed the Device ID in owntracks, but have have done something wrong on the broker side in trying to ‘remove’ the old Topic?

I think I need to perhaps tell the broker to publish that information?

I wonder if also perhaps has to do with setting ‘clean’ in the App for a minute and not having moved very far here, stuck in my office all day?

1 Like

I’m not sure I follow what you’re saying but If I reload my item file with the MQTT switches or restart OH my presence switches based on regions turn off until I leave and reenter the region. The manual switches appear to recalculate and turn on if i’m in the region. Makes sense?

My understanding is the switch reacts to the event being published from the phone so the switch defaults to off until it gets an event to turn on. That’s my take anyways, either that or my persistence isn’t working. However, I have quite a few rules that depend on working persistence so I’m guessing my first theory is correct… someone correct me if i’m wrong.

Right now I haven’t even started yet with OpenHab, and just have MQTT installed on the server and the owntracks app on an android phone.

Yesterday I was able to see my phone’s location in owntracks. But today its not showing up. I think it is because I messing with the Device ID name in owntracks or did something in trying to clear an old ‘topic’ on the server. I’m still learning the ins and outs of MQTT, so not sure what I actually did.

In Owntracks you can manually publish your location with one of the buttons on the top right of the screen.

This might be all you need to do as I’ve noticed my Owntracks doesn’t always update for me. If you have MQTT installed and setup with the right user credentials, then check the Owntracks app is connected. If so, then it’s just a case of subscribing to the right topic.

I can manually subscribe in a console with:
mosquitto_sub -d -t owntracks/paul/S7

Where ‘Paul’ is my DeviceID, and ‘S7’ is my TrackerID in the Owntracks app.

I could also use:
mosquitto_sub -d -t Owntracks/#

And it’ll pick up any other devices that I have set up with Owntracks (i.e. my wife’s phone).

If I want to publish from another console window I can use:
mosquitto_pub -d -t owntracks/paul/S7 -m "Hello from my Galaxy S7"

Or any variation of 'owntracks/# ’

Clear as mud?

EDIT: I still haven’t got mqtt working in OH2 so I can’t help with that side of things i’m afraid.

Definitely clear as mud :slight_smile: But the fog may be slowing lifting.

I think things started when I tried to get rid of an old device id by reading something out publish a blank message. forget where i read, but something like this:

mosquitto_pub -t 'owntracks/owntracks/pauls phone' -r -n

Now somehow after trying again, I see on the map my device ID showing in 2 spots from my old device id’s, but not the new current one.

I think also perhaps your Device ID has be one word? From the Sample’s I have set my Device Id as “paul/s6edgeplus” and the Tracker ID as “PM”

But I don’t see that on the Map. I think when I went back to just using “paul” in the device id I got the old one to show?

Yep… clear as mud for me. but i’m learning

I’ve never tried to get rid of an old devide ID. (My map has a few lingering around my home location from when I was tinkering). I just assumed they’d disappear if/when I reinstall Owntracks…

I don’t think MQTT cares about what old ID’s were used, it just listens for what is being published on whatever topic you are publishing on.

Or maybe i’m a blind donkey leading a lame horse.