Hands-On Internet of Things with MQTT

Book description

Develop a variety of projects and connect them to microcontrollers and web servers using the lightweight messaging protocol MQTT

Key Features

  • Leverage the power of MQTT to build a pet food dispenser, e-ink to-do list, and a productivity cube
  • Learn about technologies like laser cutting, 3D printing, and PCB production for building robust prototypes
  • Explore practical uses cases to gain an in-depth understanding of MQTT

Book Description

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.

What you will learn

  • Explore MQTT programming with Arduino
  • Discover how to make your prototypes talk to each other
  • Send MQTT messages from your smartphone to your prototypes
  • Discover how you can make websites interact with your prototypes
  • Learn about MQTT servers, libraries, and apps
  • Explore tools such as laser cutting and 3D printing in order to build robust prototype cases

Who this book is for

If you are an IoT developer or enthusiast who wants to start building IoT prototypes using MQTT, this book is for you. Basic knowledge of programming with Arduino will be useful.

Publisher resources

Download Example Code

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Internet of Things with MQTT
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Code in Action
      4. Conventions used
    4. Get in touch
      1. Reviews
  6. Section 1: An Introduction to IoT and MQTT
  7. The Internet of Things in a Nutshell
    1. Exploring smart homes
      1. How smart devices connect to the internet
      2. Useful and unnecessary use cases
    2. Exploring smart cars
    3. Exploring industry 4.0 / the Industrial Internet of Things
    4. Prototyping for the greater good
    5. What is a prototype?
    6. Voice control
    7. Why should you invest in IoT?
    8. Summary
    9. Questions
    10. Further reading
  8. Basic Architecture of an IoT Prototype
    1. Building blocks of IoT connectivity
      1. Client-server architecture
      2. Web interface
      3. Application Programming Interface
        1. Representational State Transfer Application Programming Interface
    2. Understanding protocols and communication
      1. ZigBee
      2. CoAP
      3. MQTT
      4. Thread
    3. Exploring microcontrollers for IoT
      1. 3.3V versus 5V
      2. Over-the-air updates
      3. Open source hardware and clones
      4. Microcontroller board recommendations
        1. Particle Argon/Boron/Xenon
        2. NodeMCU
        3. Raspberry Pi 4 Model B+
        4. Arduino MKR WiFi 1010
        5. M5Stack
    4. Summary
    5. Questions
    6. Further reading
  9. Getting Started with MQTT
    1. Introducing MQTT
      1. Problem 1 – dynamic IP addresses
      2. Problem 2 – code changes
      3. Problem 3 – network disturbances leading to lost messages
    2. Understanding the principle of publish and subscribe
      1. Topic names
      2. Wildcards
        1. Multi-level wildcards
        2. Single-level wildcards
      3. Forbidden characters
    3. Exploring MQTT features
      1. Quality of Service
        1. QoS 0 – fire and forget
        2. QoS 1 – at least once
        3. QoS 2 – exactly once
        4. How to choose the best QoS
      2. Last will messages
      3. Keep alive
      4. Persistent sessions/clean sessions
      5. Retained messages
    4. Analyzing the security of MQTT servers
      1. SSL/TSL
      2. Username and password
      3. Message/payload encryption
      4. Security recommendations
    5. MQTT servers and cloud providers
      1. Mosquitto
      2. AWS IoT/Google Cloud
      3. shiftr.io
    6. Comparing MQTT iOS and Android apps
      1. MQTT Dash
      2. IoT OnOff (iOS and Android)
    7. Exploring MQTT desktop apps
      1. MQTT.fx (Windows, macOS, and Linux)
    8. Understanding MQTT libraries
      1. Arduino libraries
      2. MQTT.js (JavaScript library)
    9. Summary
    10. Questions
    11. Further reading
  10. Section 2: Using MQTT in IoT projects
  11. Setting Up a Lab Environment
    1. Hardware shopping list
      1. General components
      2. Project 1 – a smart pet food dispenser
      3. Project 2 – a smart e-ink to-do list
      4. Project 3 – a smart productivity cube
      5. Optional hardware
    2. Installing the essential tools and libraries
      1. Installing Arduino
        1. Installing Arduino on macOS
        2. Installing Arduino on Windows
      2. Installing Arduino MKR WiFi 1010
        1. Testing your Arduino
      3. Installing the WiFiNINA library for Arduino
      4. Installing the MQTT library for Arduino
        1. Understanding semantic versioning
      5. Installing Visual Studio Code
        1. Installing Visual Studio Code on macOS
        2. Installing Visual Studio Code on Windows
      6. Installing Mosquitto
        1. Installing Mosquitto on macOS
        2. Installing Mosquitto on Windows
        3. Testing Mosquitto
    3. Understanding the shiftr.io web service
    4. Troubleshooting
    5. Summary
    6. Questions 
    7. Further reading
  12. Building Your Own Automatic Pet Food Dispenser
    1. Technical requirements
      1. Some additional requirements
    2. Testing the components
      1. Checking Wi-Fi connectivity with Arduino MKR WiFi 1010
      2. Testing Arduino MQTT connectivity
      3. Testing the servo motor
    3. Controlling the servo motor via the Serial Monitor
    4. Building the smart pet food dispenser
    5. Optimizing the dispenser code
    6. Improving the visual appearance
    7. Making the dispenser controllable via MQTT
      1. Sending commands to the dispenser via MQTT
    8. Summary
    9. Questions
  13. Building a Smart E-Ink To-Do List
    1. Technical requirements
    2. Connecting the e-paper module/running the example
    3. Simplifying the e-paper example
    4. Modifying the e-paper example
    5. Making your e-paper device accessible via serial
    6. Preparing the MQTT integration
    7. Making your e-paper device accessible with MQTT
    8. Sending messages via MQTT
    9. Enhancements and building a case
    10. Summary
    11. Questions
    12. Further reading
  14. Building a Smart Productivity Cube, Part 1
    1. Technical requirements
    2. Building the smart productivity cube
      1. Using one tilt switch
      2. Connecting the other tilt switches
      3. Detecting the sides
    3. Building the cube
    4. Detecting orientation changes
    5. Summary
    6. Questions
    7. Further reading
  15. Building a Smart Productivity Cube, Part 2
    1. Making your device smart
    2. Displaying the activity on your smartphone
      1. Using MQTT on Android via MQTT Dash
      2. Using MQTT on iOS with IoT OnOff
    3. Summary
    4. Questions
    5. Further reading
  16. Section 3: Prototypes
  17. Presenting Your Own Prototype
    1. Using household boxes as cases
      1. Designing the front-plate interface
    2. Using laser cutting to build custom cases
      1. Buying a laser cutter
      2. FabLab
      3. Laser cutting services
      4. How to generate a design for a laser cutter
        1. CorelDRAW
        2. Adobe Illustrator
        3. AutoCAD
        4. Inkscape
      5. Laser cutter features
        1. Stroke color guide
    3. Using 3D printing to build custom cases
      1. Buying a 3D printer – things to consider
      2. Using 3D printers in FabLabs
      3. Exploring 3D printing services
      4. Building a case for 3D printing in Tinkercad
    4. Evolution of a circuit – from breadboard to PCB
      1. Breadboards
      2. Solderable breadboards
      3. Printed circuit boards
        1. Electronics design automation or electronic computer-aided design software
          1. Eagle
          2. Altium designer
          3. KiCAD
          4. Fritzing
        2. Ordering a PCB
        3. Pick and place
    5. Summary
  18. Assessments
    1. Chapter 1: The Internet of Things in a Nutshell
    2. Chapter 2: Basic Architecture of an IoT Prototype
    3. Chapter 3: Getting Started with MQTT
    4. Chapter 4: Setting Up a Lab Environment
    5. Chapter 5: Building Your Own Automatic Pet Food Dispenser
    6. Chapter 6: Building a Smart E-Ink To-Do List
    7. Chapter 7: Build a Smart Productivity Cube, Part 1
    8. Chapter 8: Building a Smart Productivity Cube, Part 2
  19. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Hands-On Internet of Things with MQTT
  • Author(s): Tim Pulver
  • Release date: October 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781789341782