Time to cook: 30min
This recipe covers the installation of an MQTT broker on our Smart HUB.
As mentioned before MQTT is the ideal glue to build a system-of-systems architecture.
The MQTT message broker has been explained in chapter 2 and the MQTT technology in chapter 3 of the connected house cookbook. If you are not familiar with MQTT and did not read the topic in chapter 3, I would advise you to do so first.
Although this recipe does not deliver a concrete outcome or use case such as connecting a new device, it is an important recipe as if forms the basis for other recipes
A Raspberry Pi with OpenHabian installed
The Building Plan
Installing the MQTT Mosquitto Broker
login to your Raspberry-Pi with openHABian installed using an SSH connection
start the openHabian config by entering the following command:
Select Optional Components (20)
Select Mosquitto (23)
The Mosquitto installation will ask to provide a password, i would advise you to do so. remember the password, as you will need it later for each client to connect.
The installation of Mosquitto is started. Respond to the installation options. After a few minutes, the installation will be completed.
Installing the MQTT Binding
After we installed the Mosquitto MQTT broker, we need to install the binding within OpenHAB.
Open Paper UI
Select Add-ons from the left menu
Select Bindings from the top menu
Search or scroll down for the MQTT Binding (2.0)
More information about the MQTT binding can be found here
Add the Mosquitto MQTT broker
Now we have installed the MQTT binding, we can add our Mosquitto MQTT broker as a Thing in OpenHAB.
Select Configuration -> Things from the left menu
Click the + sign
Select the MQTT Binding
Click ‘ADD MANUALLY’
Select MQTT Broker
Give your Broker a logic name (example My Mosquitto broker)
In configure Parameters, enter the local IP address: 127.0.0.1
Click on SHOW MORE
Enter the username: openhabian
Enter the password: <<this is the password you have set during the Mosquitto installation>>
Click on the V sign to save the configuration
If everything is configured correctly, the Broker status should show ONLINE as you can see in the image below.
If it’s not the case, verify your settings.
We have now set up our own MQTT broker which can be used to interact with other systems.
This cookbook includes a number of recipes which make use of MQTT such as the Sonoff device. If you want you can try out those recipes.
The next recipe covers the configuration of the MQTT client on our Smart HUB. This allows us to connect our Smart HUB to other MQTT brokers. As an example we will connect to the AllThingsTalk MQTT broker.