Messaging Interface also known as MQTT is a standard publish-subscribe-based messaging protocol. It works on top of the TCP/IP protocol. It is designed for connections with remote locations where a "small code footprint" is required or the network bandwidth is limited
You can choose any open source MQTT software available out there. We are going to use Mosquitto opensource interface. Mosquitto is a well-kown MQTT server (or broker) that has fantastic open source community help and is simple to install and configure.
Your home IoT device will communicate with your HA server using MQTT.
Install Mosquitto on CentOS:
CentOS 7 doesn't have a mosquitto package by default. To install it, we'll first install a more app repository labelled more packages for enterprise linux, or EPEL. This repository is full of more app that installs well on CentOS
1. Log in with your non-set user, and use the yum package trainer to install the epel-release package.
$ sudo yum -y install epel-release
This adds the EPEL repository information to our system. The -y action automatically responds yes to a few prompts throughout the processes.
2. Install the mosquitto package.
$ sudo yum -y install mosquitto
3. Start the package with default configurations to ensure its working
$ sudo systemctl start mosquitto
4. Enable the service to make convinced it starts up when you reboot the system:
$ sudo systemctl enable mosquitto
5. Test the default configuration. The mosquitto package comes with some regulate line MQTT cases. We'll use one of them to subscribe to a topic on our broker.Topics are descriptions that you announce communications to and subscribe to. They are arranged as a hierarchy, so you could have devices/outside/worker and devices/outside/wetness, for instance. How you arrange topics is up to you and your needs. Throughout this tutorial we will use an uncomplicated test topic to test our configuration actions.
In the brand-new terminal window, use mosquitto_sub to subscribe to the test topic:
$mosquitto_sub -h localhost -t test
-h is used to choose the hostname of the MQTT server, and -t is the topic name. You'll see nothing after hitting ENTER because mosquitto_sub is waiting for communications to arrive.
Switch back to your other terminal windows or open a new terminal window and use mosquitto_pub:
$mosquitto_pub -h localhost -t test -m "hello experience"
The actions for mosquitto_pub are the same as mosquitto_sub, though this moment we use the more -m action to select our message. Hit ENTER, and you should see hello experience sound up in the other terminal. You've sent your first MQTT message!
Enter CTRL+C in the ordinal terminal to exit out of mosquitto_sub, but keep the connection to the server
6. Checking the mosquitto topics
For checking all system/Broker topics
$mosquitto_sub -v -t ‘$SYS/#’
For subscribing all topics in verbose mode
$mosquitto_sub -v -t ‘#’
7. Next, we'll secure our installation (will be publishing shortly) or check out https://mosquitto.org/man/mosquitto_passwd-1.html. We recommend to try at-least one HA device with default configurations working with MQTT.