Book Image

Hands-On Internet of Things with MQTT

By : Tim Pulver
Book Image

Hands-On Internet of Things with MQTT

By: Tim Pulver

Overview of this book

MQ Telemetry Transport (MQTT) is a lightweight messaging protocol for smart devices that can be used to build exciting, highly scalable Internet of Things (IoT) projects. This book will get you started with a quick introduction to the concepts of IoT and MQTT and explain how the latter can help you build your own internet-connected prototypes. As you advance, you’ll gain insights into how microcontrollers communicate, and you'll get to grips with the different messaging protocols and techniques involved. Once you are well-versed with the essential concepts, you’ll be able to put what you’ve learned into practice by building three projects from scratch, including an automatic pet food dispenser and a smart e-ink to-do display. You’ll also discover how to present your own prototypes professionally. In addition to this, you'll learn how to use technologies from third-party web service providers, along with other rapid prototyping technologies, such as laser cutting, 3D printing, and PCB production. By the end of this book, you’ll have gained hands-on experience in using MQTT to build your own IoT prototypes.
Table of Contents (16 chapters)
Title Page

Making the dispenser controllable via MQTT

Now let's add MQTT functionality. What we want to achieve is the following.

The Arduino should subscribe to the /yourname/feeder/feed topic. The namespace consists of three parts: yourname, which you can freely pick, should unify all of your MQTT experiments; feeder, which is the name of your device (you could also give it a longer name, such as food-dispenser); and feed, which is a command we use to release one portion of food. We could also add other commands here. One command that would be good to add is status, to which the device sends a message when it connects or disconnects to the internet and MQTT server. Its namespace would look like this: /yourname/feeder/status. Feel free to add this functionality later on.

To make our feeder accessible via MQTT, we need to combine our current sketch with the MQTT test code...