Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying MQTT Essentials - A Lightweight IoT Protocol
  • Table Of Contents Toc
  • Feedback & Rating feedback
MQTT Essentials - A Lightweight IoT Protocol

MQTT Essentials - A Lightweight IoT Protocol

By : Gaston C. Hillar
4.1 (7)
close
close
MQTT Essentials - A Lightweight IoT Protocol

MQTT Essentials - A Lightweight IoT Protocol

4.1 (7)
By: Gaston C. Hillar

Overview of this book

This step-by-step guide will help you gain a deep understanding of the lightweight MQTT protocol. We’ll begin with the specific vocabulary of MQTT and its working modes, followed by installing a Mosquitto MQTT broker. Then, you will use best practices to secure the MQTT Mosquitto broker to ensure that only authorized clients are able to publish and receive messages. Once you have secured the broker with the appropriate configuration, you will develop a solution that controls a drone with Python. Further on, you will use Python on a Raspberry Pi 3 board to process commands and Python on Intel Boards (Joule, Edison and Galileo). You will then connect to the MQTT broker, subscribe to topics, send messages, and receive messages in Python. You will also develop a solution that interacts with sensors in Java by working with MQTT messages. Moving forward, you will work with an asynchronous API with callbacks to make the sensors interact with MQTT messages. Following the same process, you will develop an iOS app with Swift 3, build a website that uses WebSockets to connect to the MQTT broker, and control home automation devices with HTML5, JavaScript code, Node.js and MQTT messages
Table of Contents (8 chapters)
close
close

What this book covers

Chapter 1, Lightweight Messaging with MQTT 3.1.1 and Mosquitto, starts our journey towards understanding the MQTT protocol. You will learn convenient scenarios for this protocol, the details of the publish-subscribe pattern, and message filtering. You will learn basic concepts related to MQTT and understand the different components: clients, brokers or servers, and connections. You will learn to install a Mosquitto broker or server on Linux, macOS, and Windows. You will learn best practices related to topics and single-level and multilevel wildcards. We will study in detail the different Quality of Service levels supported by MQTT and when it is convenient to use each of them. We will analyze their advantages and disadvantages.

Chapter 2, Securing an MQTT Mosquitto Server, covers generating a private certificate authority, a server certificate, and client certificates to enable TLS transport security and TLS client authentication with Mosquitto. Communications between the MQTT clients and the MQTT server will be encrypted. We will work with OpenSSL to generate the digital certificates. We will test the MQTT TLS configuration with MQTT.fx, MQTT-spy, and the Mosquitto command-line utilities. We will force Mosquitto to use only a specific TLS version. This way, we will understand how to encrypt communications between the MQTT clients and the Mosquitto MQTT server.

Chapter 3, Controling a Drone with Python, analyzes the requirements for controlling a drone with MQTT messages. We will define the topics that we will use and the commands that will be part of the messages’ payloads to control a drone. Then, we will work with the Paho Python Client to write Python code that connects an MQTT client to the MQTT server. We will understand the methods we need to call for the Paho Python Client and their parameters. We will analyze how callbacks work and we will be able to publish messages to topics, subscribe to topic filters, and receive and process messages. We will write code that processes commands for a drone with Python. The code will be able to run on different IoT platforms, including Intel Joule boards and Raspberry Pi 3, and also on any computer that is capable of executing Python 2.7.x or Python 3.x. We will work with the network loop for the MQTT client in Python. We will work with a GUI utility, command-line-based utilities, and, finally, with Python code to control the drone and display the feedback provided by the drone.

Chapter 4, Interacting with Sensors in Java, analyzes the requirements for controlling sensors wired to different IoT boards with MQTT messages and Java code. We will define the topics that we will use and the commands that will be part of the messages’ payloads to control sensors. We will take advantage of the last will and testament feature of MQTT with Java. We will work with the Eclipse Paho Java Client to write Java code that will connect a non-blocking (asynchronous) MQTT client to the MQTT server. We will create a security helper class to establish a TLS secured connection, and we will work with asynchronous notifications and callbacks in Java. We will subscribe to topics, understand how notification events work, and we will write code that processes commands that interact with sensors. Finally, we will work with a GUI utility to interact with our Java application through MQTT messages. We will be able to turn on and turn off the sensors and retrieve data from them.

Chapter 5, Controlling Home Automation in JavaScript, analyzes the requirements to control LEDs wired to different IoT boards with MQTT messages over WebSockets. We will define the topics that we will use and the commands that will be part of the message’s payloads to set the colors for LEDs. Then, we will create an HTML 5 web page combined with JavaScript and the Eclipse Paho JavaScript asynchronous client to control LEDs. We will write code to publish messages to target remote devices in JavaScript and we will be able to process received messages to provide feedback to the user. We will work with MQTT.js to write a Node.js script to process commands that simulate the interaction with LEDs on different IoT boards. We will be able to run the home automation web application and understand how all the pieces work together by exchanging MQTT over WebSockets messages. Finally, we will understand the necessary steps to work with MQTT over WebSockets with TLS.

Chapter 6, Interacting with Actuators in Swift, analyzes the requirements for controlling actuators wired to different IoT boards with MQTT messages. We will define the topics that we will use and the commands that will be part of the message’s payloads to turn on and turn off motors. Then, we will create an iOS app with Xcode and Swift 3, combined with the CocoaMQTT client, to control a motor. We will write code to publish messages to target remote devices in Swift 3 and we will be able to process received messages to provide feedback to the user. We will work with MQTT.js to write a Node.js script to process commands that simulate the interaction with motors on the different IoT boards. We will be able to run the iOS app and the Node.js script and understand how all the pieces work together by exchanging MQTT messages.

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY