How do I set up my own MQTT Server with Mosquitto?

38.6k views Asked by At

I am setting up a sensor network for my new diy home automation system and am running into a major roadblock. I am using OpenHAB as the "home base" for the system, and since it has an MQTT binding, I figured that would be a good way to have all of the nodes talk with it. I know that I can connect to test.mosquitto.org, which is great for testing. But, obviously, this is not secure enough by far for the permanent server (also, I'm pretty sure they specifically say not to use that server for permanent things).

After a lot of Google-ing I have found a decent amount of info on Mosquitto and MQTT, but honestly most of it is over my head since I am just starting. My question here, that most seem to assume is known already, is how do I actually go about setting up my own MQTT server on the Raspberry Pi that will be running everything? Or is this not the norm, and should I find a public server (like test.mosquitto.org)? That just doesn't seem like the most practical method.

Thanks in advance for your help.

2

There are 2 answers

3
Matt. On BEST ANSWER

Mosquitto is light enough that you can install it anywhere. I would only use test.mosquitto.org if I was testing as it is public (ie. anyone can see your data!) and isn't always up and working.

When running on the pi I normally add the Mosquitto Debian Repo as it is more upto date. Has v1.3.5

Good instructions on mosquitto.org site or a good beginnners howto over at jpmens, just do the installation upto the TLS part (unless you need it!)

2
hardillb On

On a raspberry pi

If you just run the following commands:

sudo apt-get update

sudo apt-get install mosquitto

sudo update-rc.d mosquitto defaults

(I'm not 100% sure you need this one but it won't hurt)

sudo /etc/init.d/mosquitto start

(only needed this time, as it should start automatically on reboot)

That will give you a mosquitto broker running on your pi