Presented by Bluemix Developer Advocate, Ryan Baxter.
MQTT is a standards-based, lightweight pub/sub messaging protocol ideal for Internet of Things use cases. With implementations in a number of different languages, using MQTT in your applications is simple and straightforward. Ryan Baxter shows how to build an application that connects to an MQTT broker and can receive data from—and issue commands to—a number of different IoT devices.
Topics include:
An overview of MQTT
The different types of messages you can send through an MQTT broker
How to send messages securely through the broker
How you can use MQTT to perform device management
Scalability concerns (how many devices the broker can handle and at what frequency you can send messages)
Ryan will also focus on the cloud. Since the typical scale of IoT applications often requires the cloud, Ryan shows how cloud-based MQTT solutions can make building IoT apps even easier.
2. BUILDING AN IOT APP USING MQTT
ABOUT ME
▸ Developer Advocate -
IBM Emerging
Technologies
▸ @ryanjbaxter
▸ http://ryanjbaxter.com
3. BUILDING AN IOT APP USING MQTT
WHAT IS MQTT?
▸ MQTT is a lightweight pub-sub protocol
▸ MQTT is an open protocol
▸ It is an OASIS standard current version is 3.1.1
▸ The lightweight nature of the protocol makes it ideal in IoT
use cases where battery or bandwidth is a concern
▸ It will also works well where a device has a reliable power
source and plenty of bandwidth
4. BUILDING AN IOT APP USING MQTT
UNDERSTANDING PUB-SUB
Publisher (Device) Broker Subscriber (App)
Sub(topic)
Pub(topic, data)
Pub(topic, data)
5. BUILDING AN IOT APP USING MQTT
UNDERSTANDING TOPICS
▸ Topics are structured using slashes (/)
▸ sensortag/123/temperature - only temperature data from the
SensorTag with the id 123
▸ Wild cards can be used in topics to generalize them
▸ sensortag/+/temperature - temperature data from any
SensorTag
▸ Using a hash (#) allows you to wildcard all remaining levels
▸ sensortag/# - data from any sensor as long as it is a SensorTag
6. BUILDING AN IOT APP USING MQTT
QUALITY OF SERVICE
▸ MQTT defines three levels of Quality of Service (QoS)
▸ Defines how hard the broker will ensure the message is received
▸ 0: The broker will deliver the message once with no confirmation
▸ 1: The broker will deliver the message at least once with
confirmation required
▸ 2: The broker will deliver the message exactly once by using a
four step handshake
▸ Subscribers dictate the maximum QoS they will receive
7. BUILDING AN IOT APP USING MQTT
RETAINED MESSAGES
▸ Messages may be set to be retaining
▸ If a message is set to retained and a new client subscribes
to a topic with a retained message than the client will
receive that message
8. BUILDING AN IOT APP USING MQTT
CLEAN SESSIONS
▸ When a client does not use clean sessions than all topic
subscriptions are retained and subscriptions with QoS 1
and 2 will be retained when the client disconnects
▸ When a clean session is used all subscriptions are
removed
9. BUILDING AN IOT APP USING MQTT
EVENTS VS COMMANDS
▸ Devices typically publish data as an event through the
broker
▸ I.E. A temperature sensor may publish the current
temperature as an event
▸ Devices may also listen for commands
▸ I.E. A temperature sensor may subscribe to a command
topic allowing an application to switch the temperature
reading from Farenheight to Celcius
10. BUILDING AN IOT APP USING MQTT
SECURITY
▸ MQTT brokers MAY require a username and password
▸ Can optionally encrypt the TCP connections with SSL/TLS
11. BUILDING AN IOT APP USING MQTT
IMPLEMENTATIONS
▸ There are many open source client and broker implementations
▸ Client libraries exist for most popular languages
▸ Brokers also exist that can easily be deployed for your IOT
solutions
▸ Docker images available for various MQTT brokers
▸ Cloud Brokers
▸ IBM, Amazon, and others
12. DEMOUse sensor tag from laptop
Build client side web app to do
something with the data
13. BUILDING AN IOT APP USING MQTT
RESOURCES
▸ MQTT - MQTT.org
▸ IBM Internet of Things Foundation -
internetofthings.ibmcloud.com
▸ MQTT App Code - http://codepen.io/ryanjbaxter/pen/
JXjGyG
▸ MQTT Device Code - http://bit.ly/fluent-mqtt-device