Install a raspberry pi with the latest OpenHABian version.
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
.
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!"
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
.