Because the HTTP protocol is most common protocol on the Internet it has become the main protocol for controlling first generation smart home devices.
However HTTP is not the main protocol for IOT (Internet of things) devices.
The choice here is MQTT (MQ Telemetry Transport ) and this will also most likely become the main control protocol for home automation.
Many second generation smart home devices will be bi-lingual in that they will support both protocols.
Using MQTT on a Home Network
MQTT is a very simple and fast messaging protocol that uses the publish and subscribe model.
This model relies on a central broker that is used to exchange messages as shown in the diagram below.
This model is very similar to the radio/TV broadcasting model.
In this model a publisher publishes on a topic (radio =channel) and a subscriber simply subscribes to that topic to receive the messages.
You can learn more about MQTT on my other site See- How MQTT Works.
MQTT Brokers or Servers
Although there are cloud based test and commercial brokers available See MQTT Brokers/Servers and Cloud Hosting Guide the best choice for a home network is a locally installed broker.
The most popular one is mosquitto and is the one I use and will use in the tutorials on this site.
You can install Mosquitto on Linux and Windows and also on the Raspberry Pi.
There are clients for almost all programming languages.
Node-red as an MQTT publish and subscribe node built in and on this site I will concentrate on using this client.
Here is a detailed tutorial on Using the Publish and Subscribe nodes on node-red.
I also did a video here
I cover the Python client in detail on my other site here.
Important MQTT Properties
- There is no direct connection between subscriber and publisher.
- MQTT is a 1 to many protocol by default
- MQTT supports QOS levels to guarantee message delivery.
- MQTT can use SSL for security
- MQTT can be used in a web browser Using MQTT over Websockets.
- Any message restrictions are set on the MQTT broker.
- MQTT brokers don’t normally store Messages.
Related Tutorials and Resources: