6

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.

dsarge
  • 83
  • 1
  • 1
  • 4

2 Answers2

5

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!)

Matt.
  • 1,043
  • 1
  • 12
  • 20
  • Yeah, this is a great site, I've actually been referencing it a lot for this setup. Near the bottom, a test is run using the command `mosquitto_pub --cafile ca.crt -h 127.0.0.1 -p 8883`. Disregarding the cafile for the time being, does the use of 127.0.0.1 -p 8883 for the IP mean that I can run this all from the local machine and not worry about connecting to test.mosquitto.org? – dsarge Dec 18 '14 at 05:45
  • Little confused at what you are saying, but this might help. Once you have Mosquitto running and you have also installed mosquitto-clients, run ```mosquitto_sub -t hello/world``` then open another terminal to the pi and type ```mosquitto_pub -t hello/world -m "testing"``` the message should apeAr. The default port on mosquittto is 1883, 8883 is typically the TLS port which you need to setup with certificates etc, I would ignore this part to start off with, gets a bit complicated. Don't worry about test.mosquitto.org if you have already installed mosquitto locally. – Matt. Dec 18 '14 at 09:43
  • Ah, okay, that makes sense. I think that last sentence answers what I was looking for. I didn't know what all was required for actually publishing information. Thank you – dsarge Dec 18 '14 at 17:41
3

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

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • This will install v0.15 from memory. It will work but not that well with some of the newer things. – Matt. Dec 18 '14 at 03:40
  • You need to add an additional source list as written at http://mosquitto.org/2013/01/mosquitto-debian-repository/: wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key sudo apt-key add mosquitto-repo.gpg.key cd /etc/apt/sources.list.d/ sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list or sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list – Tobias Nov 12 '15 at 14:03