MQTT

MQTT & OpenHAB

MQTT is a so simple and widespread messaging system between applications that libraries and examples can be found in every programming language and in many devices.

The openhabian-config includes an installation script for Mosquitto, the most common broker, that allows the CM3-Home to be independent from outside on exchanging data between bindings and applications.

In this distribution it is used in several examples:

  • CM3-OH_sonoff, using the device internal MQTT client
  • CM3-OH_ir, using the CM3-Home mosquitto_pub capabilities
  • CM3-OH_sms,  using the Paho library in a Python script

MQTT

Once the MQTT binding has been installed, it has to be configured with the name to use in the clients:

services/mqtt.cfg

broker1.url=tcp://localhost:1883
broker1.clientId=openhab2


Define also the event bus binding if it’s needed to publish/receive all states/commmands directly on the openHAB eventbus:

service/mqtt-eventbus

 

broker=broker1
statePublishTopic=openhab/out/${item}/state
commandPublishTopic=openhab/out/${item}/command

stateSubscribeTopic=openhab/in/${item}/state
commandSubscribeTopic=openhab/in/${item}/command


The correct working of the system can be verified subscribing:

openhab/in/# 
openhab/out/#

 

with mqtt-spy or with the Google chrome App [MQTTlens

Links

Share