Install an MQTT broker on your Raspberry Pi

Not only for home automation purposes, a central MQTT broker can be a good system that connects sensors and control applications. MQTT has been designed especially to be very lightweight. Therefore, it will also work very well on a Raspberry Pi. Installing it is very simple:
sudo apt-get install -y mosquitto mosquitto-clients

Your Mosquitto server should be already running now. You can test this easily.
mosquitto_sub -h localhost -v -t test

This starts a MQTT subscriber waiting for incmoming messages on the “test” channel.

Now open a new connection to your Raspberry Pi and type the following:
mosquitto_pub -h localhost -t test -m "Hello world, Mosquitto"

The first process should now display the “Hello world” message.