Upload
sensorup
View
883
Download
4
Embed Size (px)
Citation preview
MQTT and SensorThings API MQTT Extension
sensorweb.geomatics.ucalgary.cawww.sensorup.com
0.23 litre/minute
0.25 litre/minute0.27 litre/minuteRH: 85 %
Temp: 18 Celsius
Dr. Steve Liang, Ph.D., P.Eng. Associate Professor, University of Calgary Founder and CEO, SensorUp Inc.
About Dr. Steve Liang๏Associate Professor, Geomatics Engineering, Uni. Calgary
๏AITF-Microsoft Industry Research Chair on Open Sensor Web (2011~2014)
๏Chair OGC SensorThings API Standard Working Group
๏Rapporteur, ITU-T SG12/11 on Internet of Things Test Specifications
๏ Founder and CEO, SensorUp Inc
๏Calgary’s Top 40 Under 40
About SensorUp๏We are a leader in Sensor Web and
IoT Platforms
๏We are leading several international IoT standard development efforts (OGC and ITU-T)
๏We are proud member of Eclipse and Open Geospatial Consortium
News - Whiskers๏Whiskers, a new Eclipse
open source project proposal for OGC SensorThings API
๏will includes MQTT support
News - Whiskers๏Whisker is
๏ a Javascript Client Library for SensorThings
๏ a light-weight SensorThings Server for IoT gateways (e.g., Raspberry Pi)
๏ First release - 2016 Q2 or Q3
What will be covered
๏MQTT
๏ SensorThings API MQTT Extension
Why isn’t HTTP enough?
๏HTTP: send a request, receive a response
๏ IoT has fundamentally different challenges
๏ IoT needs a event-oriented paradigm
๏distribute information from 1 to many
๏ get notifications whenever they happen
๏distributing minimal packets of data in huge volumes
๏pushing information over unreliable networks
Why isn’t HTTP enough - 2?
๏ IoT has fundamentally different challenges
๏power consumption is a major concern (battery-powered devices)
๏ responsiveness (near real-time applications)
๏ scalability (50 billion devices!!)
MQTT is…
๏ an ISO standard (ISO/IEC 20922)
๏ an OASIS standard
๏probably the most popular IoT messaging protocol (more in next slide)
๏ efficient and scalable
Messaging Protocols for IoT
1.1%
5.4%
6.8%
8.2%
11.1%
11.5%
18.6%
21.5%
53.0%
63.1%
0.0% 10.0% 20.0% 30.0% 40.0% 50.0% 60.0% 70.0%
None
DDS
Don’t)know
Proprietary
AMQP
XMPP
In7house
CoAP
MQTT
HTTP
What)general)messaging)protocols)do)you)use)in)your) IoT)solution?
Eclipse IoT Developer Survey 2015
MQTT vs HTTPS (power consumption)
http://stephendnicholas.com/posts/power-profiling-mqtt-vs-https
MQTT vs HTTPS (power consumption)
http://stephendnicholas.com/posts/power-profiling-mqtt-vs-https
What MQTT is not…
๏use MQTT doesn’t mean IoT interoperability
๏ It’s part of the interoperability solution
๏ It still needs a data model standard, such as SensorThings API to enable data interoperability
MQTT Topics
๏ the central concept in MQTT to dispatch messages are topics
๏ a topic is a simple string that can have more hierarchy levels, which are separated by a slash (/),
๏ e.g., house/living-room/temperature
๏ topics are the routing information for the MQTT broker
MQTT in a nutshell
MQTT BrokerPublisher Subscribers
Subscribers
Subscribers
Instead of client/server, MQTT has the roles of publisher/subscriber
subscribe: topic1
subscribe: topic1
subscribe: topic1
MQTT in a nutshell
MQTT BrokerPublisher
Subscribers
Subscribers
Publish to: topic1
body
msg
Instead of client/server, MQTT has the roles of publisher/subscriber
msg
msg
msg
Subscribers
MQTT Methods (verbs)
๏Connect: client request a connection with the MQTT broker
๏Disconnect: disconnect notification
๏ Subscribe: subscribe to topics
๏UnSubscribe: unsubscribe from topics
๏Publish: Publish message
Let’s try
๏HiveMQ provides a nice web socket-based client
๏http://www.hivemq.com/demos/websocket-client/
๏ Today I’m gonna use an Eclipse open source tool called mosquitto
๏GIST here: http://gist.github.com/liangsteve/bb7468fb9e97060f4676d3e544c11a77
MQTT Topics cont.๏plus sign (+) is the single level wild card
๏ e.g., a subscription of house/+/temperature will receive messages published to both house/living-room/temperature and house/bed-room/temperature
๏# is multi-level wildcard
๏ e.g., house/# is subscribing to all topics begins with house
MQTT wildcard
MQTT BrokerPublisher Subscribers
Subscribers
SubscribersInstead of client/server, MQTT has the
roles of publisher/subscriber subscribe to:
h/+/t
subscribe to: house/b/+
subscribe to: h/b/t
MQTT wildcard
MQTT BrokerPublisher Subscribers
Subscribers
SubscribersInstead of client/server, MQTT has the
roles of publisher/subscriber h/+/t
h/b/+
h/b/s
publish to topic: h/b/t
MQTT wildcard
MQTT BrokerPublisher Subscribers
Subscribers
SubscribersInstead of client/server, MQTT has the
roles of publisher/subscriber h/+/t
h/b/+
h/b/s
publish to topic: h/a/t
MQTT QoS๏QoS-0: fire-and-forget
๏QoS-1: deliver at least once
๏ the broker stores messages on disk and retries until clients have acknowledged their delivery. (Possibly with duplicates.)
๏QoS-2: deliver exact once
๏have a second acknowledgement round-trip, to ensure that non-idempotent messages can be delivered exactly once
MQTT Retain Flag
๏ Second, messages have a ‘retain’ flag, indicating that they should be stored for delivery to new subscribers. For topics that are infrequently updated, it’s often useful to give new subscribers the last-known message right away (with an indication that it isn’t fresh). Newer retained messages replace previously ones.
What not included in MQTT?
๏What does the topic mean?
๏ h/p/t ??
๏How to interpret the data pushed to you??
SensorThings API MQTT Extension!!
๏MQTT Subscribe v1.0/Datastreams(id)/Observations
SensorThings MQTT Extension MQTT + OData URL Pattern + O&M
URL path tells you how to find metadata, entity name tells you how to
interpret the data
Receive Observations via MQTT
Get Notified when new a THING was created
Demo - Client received notifications when new THINGS join a SensorThings server
Summary
๏MQTT is very suitable for IoT!!
๏ SensorThings API provides the greatness of both HTTP and MQTT.
๏ SensorThings HTTP REST is suitable for historical data and analytics.
๏ SensorThings MQTT is suitable for real-time applications.
References
๏ Introduction to MQTT
๏ https://www.oasis-open.org/committees/download.php/49205/MQTT-OASIS-Webinar.pdf
๏ Eclipse IoT Survey 2015
๏http://www.slideshare.net/IanSkerrett/iot-developer-survey-2015
See you next week!