Skip to content

Instantly share code, notes, and snippets.

@mirhec
Created October 2, 2017 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirhec/27e8df1b2ff52196fabb0f9ea5f4313f to your computer and use it in GitHub Desktop.
Save mirhec/27e8df1b2ff52196fabb0f9ea5f4313f to your computer and use it in GitHub Desktop.
Setup mosquitto broker on raspberry pi with openhab

Install Mosquitto on Raspberry Pi with OpenHAB

Install a raspberry pi with the latest OpenHABian version.

Install Mosquitto

wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
rm mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list
sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients

Edit the mosquitto config file at /etc/mosquitto/mosquitto.conf and add the following line:

listener 1883

Now restart the service with sudo /etc/init.d/mosquitto restart.

Test Mosquitto

mosquitto_sub -d -t hello/world

Connect to another ssh session and run

mosquitto_pub -d -t hello/world -m "Hello from terminal window 2!"

Configure OpenHAB

Now install Mosquitto binding and enter binding-mqtt1 in the binding list in the addons.cfg file. Create a new file services/mqtt.cfg and enter the following content:

mosquitto.url=tcp://localhost:1883
mosquitto.clientId=OpenHAB2
mosquitto.user=<user>
mosquitto.pwd=<password>

Then restart openhab with sudo /etc/init.d/openhab2 restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment