The more I integrate a Raspberry Pi into my smart home, the more I need a communications solution to be able to talk between my Raspberry Pi and other Home Automation Hubs (SmartThings…I’m talking about you). That is where MQTT comes in, for those that do not know MQTT is a lightweight messaging protocol designed to minimize network bandwidth usage while ensuring reliability, because of this MQTT is perfect for the Internet of Things.
With MQTT you have “Clients” and “Brokers”. In my use case I have a Raspberry Pi that is a Client and Mosquitto which is a Broker. Mosquitto is an open source MQTT Broker and who does not like open source?
Setting up Mosquitto on a Raspberry Pi is simple and is something that I think every Raspberry Pi user should do as I am sure at one point or another you will have a need for MQTT. To get your Raspberry Pi setup with Mosquitto simply follow the steps below.
First what will you need?
- Raspberry Pi 3+B (nice to start with a kit as they will typically include a case and power supply)
- MicroSD Memory Card
- Micro USB Power Supply
- Raspberry Pi Case
To begin the installation process you will need a MicroSD Memory Card, and the ability to format and burn an image to that MicroSD Memory Card. I am sure most of you know how to do these steps already, but I will give my recommendations, for formatting I prefer to use SD Memory Card Formatter for Windows and to burn the image Etcher.
Memory Card Preparation:
- Insert MicroSD Memory Card into a computer
- Open SD Memory Card Formatter for Windows
- In SD Memory Card Formatter for Windows Select the Drive that corresponds to your Memory Card
- In SD Memory Card Formatter for Windows Click Format and wait for it to finish
- Download the Raspbian disk image from https://www.raspberrypi.org/downloads/raspbian/
- Open Etcher.
- In Etcher Select the previously Downloaded Image
- In Etcher Select the Drive that corresponds to your Memory Card
- In Etcher Click Flash and wait for Etcher to Finish
Raspberry Pi Setup:
- From the Raspbian Desktop launch Terminal
- From Terminal you need to update the signing key using the follow commands,
- sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
- sudo apt-key add mosquito-repo.gpg.key
3. Add the Mosquitto Repo to apt-get by running the following commands in Terminal
- cd /etc/apt/sources.list.d/
- sudo wget http://repo.mosquitto.org/debian/mosquitto-stretch.list (if you are not using Rasbian Stretch replace “stretch” with the version you are using)
4. Install Mosquitto by running the following commands in Terminal
- sudo apt-get update
- sudo apt-get install mosquito mosquito-clients
Anyone doing anything interesting with Mosquitto or MQTT in general? Let me know in the comments below.
I am passionate about the IoT and connected devices. Using connectivity to automate our lives will empower civilization to achieve greatness.