OpenHab2 - MQTT binding demo
OpenHab2 - MQTT binding demo
This demo demonstrates how to use MQTT binding addon in OpenHAB2 installed into Orange Pi zero. The idea is very basic. A switch is created on default sitemap. When you turn on the switch, it sends "ON" message to Topic
/office/light
via MQTT broker that is installed on Orange Pi. When you turn off the switch, it sends "OFF" message to Topic /office/light
.Require
First, install MQTT binding via paperui
Define all the brokers which you want to connect to, in your
services/mqtt.cfg
file.cd /etc/openhab2/services
sudo nano mqtt.cfg
Edit the file as follow
#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#
# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
mosquitto.url=tcp://localhost:1883
# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
mosquitto.clientId=lion
# Optional. User id to authenticate with the broker.
#<broker>.user=<user>
# Optional. Password to authenticate with the broker.
#<broker>.pwd=<password>
In the file you can see that 'mosquitto" is an MQTT broker name based on eclipse mosquitto. The broker is installed into the Orange Pi running Debian. So that the broker url is "localhost".
Define demo item in demo.items
I define a switch which will be use to send the switch status (ON or OFF) via an MQTT message when a user click on it.
Switch mySwitch {mqtt=">[mosquitto:/office/light:command:ON:1],>[mosquitto:/office/light:command:OFF:0]"}
Define sitemap
Open sitemap file (for example: demo.sitemap) and edit as follow;
sitemap default label="My first sitemap"
{
Switch item=mySwitch label="Office Light"
}
Show log file
Open terminal, then run:
tail -f /var/log/openhab2/openhab.log
I am proud of you for your brief explanation. Your post is very interesting and this is very useful for increasing my knowledge skills. Well said, I like to more post from your blog.
ReplyDeleteLinux Training in Chennai
Linux Course in Chennai
Spark Training in Chennai
Oracle Training in Chennai
Oracle DBA Training in Chennai
Corporate Training in Chennai
Best Linux Training Institute in Chennai
Best Linux Training in Chennai
Thanks for your interesting ideas.the information's in this blog is very much useful for me to improve my knowledge.
ReplyDeleteiOS Training in Chennai
iOS Training in T Nagar
JAVA Training in Chennai
Python Training in Chennai
Big data training in chennai
Selenium Training in Chennai
IOS Training in Chennai
ios training institute in chennai