Setting Up OpenHab and Mosquitto on Pi

How to install OpenHab on Raspberry Pi 2 from scratch

https://www.raspberrypi.org/downloads/raspbian/

Choose the Lite version, you don’t need the GUI desktop…

Username = pi
Password = raspberry
 sudo raspi-config

in the next GUI select option “Expand filesystem” Exit and Reboot…

sudo apt-get update && sudo apt-get install oracle-java8-jdk
java -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

Open a second terminal or Putty window

[Command to key in the first window:] mosquitto_sub -d -t hello/world
[Command to key in the second window:] mosquitto_pub -d -t hello/world -m “Greetings from Terminal window 2!”

You will see the message appear in the First window if everything is OK.

sudo mkdir /opt/openhab
cd /opt/openhab
sudo wget https://bintray.com/artifact/download/openhab/bin/distribution-1.8.1-runtime.zip
sudo unzip distribution-1.8.1-runtime.zip
sudo rm distribution-1.8.1-runtime.zip
cd addons/
sudo wget https://bintray.com/artifact/download/openhab/bin/distribution-1.8.1-addons.zip
sudo distribution-1.8.1-addons.zip
sudo unzip distribution-1.8.1-addons.zip
sudo rm distribution-1.8.1-addons.zip
[Command to key:] cd ..
[Command to key:] cd /opt/openhab
[Command to key:] sudo wget https://bintray.com/artifact/download/openhab/bin/distribution-1.8.1-demo.zip
[Command to key:] sudo unzip distribution-1.8.1-demo.zip
[Command to key:] sudo rm distribution-1.8.1-demo.zip
[Command to key:] sudo chmod +x start.sh
[Command to key:] sudo ./start.sh (/opt/openhab/)

On a computer in an internet browser goto:

http://xxx.xxx.xxx.xxx:8080/openhab.app?sitemap=demo

(replace xxx.xxx.xxx.xxx by your local IP address of your raspberry pi)

[Command to key:] sudo nano /etc/openhab/configurations/openhab.cfg

At the very bottom define a MMQT Broker:

mqtt:broker.url=tcp://xxx.xxx.xxx.xxx:1883
mqtt:broker.clientId=openhab

(replace xxx.xxx.xxx.xxx by your local IP address of your raspberry pi)

Exit, Save

[Command to key:] sudo reboot

Close the Terminal window Wait for the system to reboot, open a new terminal window and login.

[Command to key:] cd /opt/openhab
[Command to key:] sudo chmod +x start.sh
[Command to key:] sudo ./start.sh (/opt/openhab/)

Sources:

https://www.raspberrypi.org/forums/viewtopic.php?f=81&t=135941
https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97422
https://bintray.com/openhab/bin/openHAB/1.8.1/view#files
http://www.instructables.com/id/OpenHAB-on-Raspberry-Pi/
http://repo.mosquitto.org/debian/
https://openhardwarecoza.wordpress.com/category/openhab/