Message Queue Telemetry Transport is a lightweight publish / subscribe message transport. For example Sensor hardware publishes values which the MQTT Broker passes on to all subscribers.
Alternatively a client can publish an instruction (topic) which wll be passed on by the MQTT Broker to all subscribers for action.
There are lots of MQTT resources/tutorials, for example at mqtt.org
Home Assistant has an integration for an MQTT Broker which can be utilised with a wide variety of devices. Typically, for me, the client will be an ESP8266 or ESP32. For testing I use a NodeMCU ESP8266 and the Arduino IDE.
HA has an integration for the Mosquitto MQTT Broker which is widely used and very easy to install on HA. I used a good video by EverythingSmartHome. Once the install has completed the broker provides you with a screen where you can experiment, sending packets and listening to Topics. This will be very useful going forward to watch messages flowing through the system.
I followed a good tutorial from emqx.com to setup a NodeMCU ESP8266 as an MQTT client. It uses the ESP8266WiFi library and PubSubClient which is allows messages to be published / received.
Our inital sketch simply sets up wifi, sets up MQTT client and publishes a "hello" message which is promptly displayed on the Broker Topic Monitor.
The sketch is very straightforward so I have included it below.
The sketch is very straightforward so I have included it below.
We dont have sensors attached on functions to carry out yet but you can see how easy they will be to add.
No comments:
Post a Comment