IoT Week5 Day1 Lecture
IoT Week5 Day1 Lecture
Acknowledgement
University of Notre Dame
Course Overview
Lecture Lab
Fundamentals of IoT, basic Basic Python & Raspberry Pi
Week 1 concepts, applications programming
Week 1 Week 1
Simple example:
• IaaS: barebones computer
• PaaS: computer + OS (incl. development environment)
• SaaS: complete solution including application(s)
IaaS, PaaS, SaaS
• IaaS: Amazon Web Services (AWS), Microsoft
Azure, Google Compute Engine
Hardware
Denali
etc.
Cloud Example: S3
• Amazon Simple Storage Service (S3)
• Unlimited storage
• Pay for what you use
Cloud Example: EC2
• Amazon Elastic Compute Cloud (EC2)
– Virtual computing environments (“instances”)
– Pre-configured templates for instances
– Launch as many virtual servers as needed (“elastic”)
– Xen and KVM hypervisor
Do You Use The Cloud?
Cloud for IoT
HyperText Transfer Protocol (HTTP)
• Clients and servers communicate using the HyperText Transfer
Protocol (HTTP)
– Client and server establish TCP connection
– Client requests content
– Server responds with requested content
– Client and server close connection (usually)
HTTP request
Web
Web
client
server
(browser)
HTTP response
(content)
Web Content
• Web servers return content to clients
– a sequence of bytes with an associated MIME
(Multipurpose Internet Mail Extensions) type
• Example MIME types
– text/html HTML document
– text/plain Unformatted text
– application/postscript Postcript document
– image/gif Binary image encoded in GIF
format
– image/jpeg Binary image encoded in
JPEG format
Static & Dynamic Content
• The content returned in HTTP responses can be
either static or dynamic
– Static content: content stored in files and retrieved in
response to an HTTP request
• Examples: HTML files, images, audio clips
– Dynamic content: content produced on-the-fly in
response to an HTTP request
• Example: content produced by a program executed by the
server on behalf of the client
• Bottom line: all web content is associated with a
file that is managed by the server
URLs
• Each file managed by a server has a unique name called a
URL (Universal Resource Locator)
• URLs for static content:
– http://www.cse.nd.edu:80/index.html
– http://www.cse.nd.edu/index.html
– http://www.cse.nd.edu
• Identifies a file called index.html, managed by a web server at
www.cse.nd.edu that is listening on port 80
• URLs for dynamic content:
– http://www.cse.nd.edu:8000/cgi-bin/adder?15000&213
• Identifies an executable file called adder, managed by a web server at
www.cse.nd.edu that is listening on port 8000, that should be called with
two argument strings: 15000 and 213
Anatomy of an HTTP Transaction
unix> telnet www.aol.com 80 Client: open connection to server
Trying 205.188.146.23... Telnet prints 3 lines to the terminal
Connected to aol.com.
Escape character is '^]'.
GET / HTTP/1.1 Client: request line
host: www.aol.com Client: required HTTP/1.1 HOST header
Client: empty line terminates headers.
HTTP/1.0 200 OK Server: response line
MIME-Version: 1.0 Server: followed by five response headers
Date: Mon, 08 Jan 2001 04:59:42 GMT
Server: NaviServer/2.0 AOLserver/2.3.3
Content-Type: text/html Server: expect HTML in the response body
Content-Length: 42092 Server: expect 42,092 bytes in the resp body
Server: empty line (“\r\n”) terminates hdrs
<html> Server: first HTML line in response body
... Server: 766 lines of HTML not shown.
</html> Server: last HTML line in response body
Connection closed by foreign host. Server: closes connection
unix> Client: closes connection and terminates
HTTP Requests
• HTTP request is a request line, followed by zero
or more request headers
REST
Verbs Representations
constrained constrained
i.e., GET i.e., XML
Resources
• The key abstraction of information in REST is a
resource
– http://www.boeing.com/aircraft/747
Naming Resources
• REST uses URI to identify resources
– http://localhost/books/
– http://localhost/books/ISBN-0011
– http://localhost/books/ISBN-0011/authors
– http://localhost/classes
– http://localhost/classes/cs2650
– http://localhost/classes/cs2650/students
• HTTP GET
• HTTP POST
• HTTP PUT
• HTTP DELETE
HTTP GET
• How clients ask for the information they seek
• GET http://localhost/books
– Retrieve all books
• GET http://localhost/books/ISBN-0011021
– Retrieve book identified with ISBN-0011021
• GET http://localhost/books/ISBN-0011021/authors
– Retrieve authors for book identified with ISBN-0011021
HTTP PUT & POST
• HTTP POST creates a resource
• HTTP PUT updates a resource
• POST http://localhost/books/
– Content: {title, authors[], …}
– Creates a new book with given properties
• PUT http://localhost/books/isbn-111
– Content: {isbn, title, authors[], …}
– Updates book identified by isbn-111 with submitted properties
Representations
• How data is represented or returned to the client for
presentation.
– XML
• JSON
{course
{id: CS2650}
{name: Distributed Multimedia Software}
}
CoAP
• Constrained Application Protocol
– REST-based web transfer protocol
– manipulates Web resources using the same methods
as HTTP: GET, PUT, POST, and DELETE
– subset of HTTP functionality re-designed for low
power embedded devices such as sensors (for IoT and
M2M)
CoAP
• TCP overhead is too high and its flow control is not
appropriate for short-lived transactions
• UDP has lower overhead and supports multicast
CoAP
• Four message types:
– Confirmable – requires an ACK
– Non-confirmable – no ACK needed
– Acknowledgement – ACKs a Confirmable
– Reset - indicates a Confirmable message has been
received but context is missing for processing
CoAP
• CoAP provides reliability without using TCP as
transport protocol
• CoAP enables asynchronous communication
– e.g., when CoAP server receives a request which it
cannot handle immediately, it first ACKs the
reception of the message and sends back the response
in an off-line fashion
• Also supports multicast and congestion control
CoAP
What CoAP Is
• CoAP is
– A RESTful protocol
– Both synchronous and asynchronous
– For constrained devices and networks
– Specialized for M2M applications
– Easy to proxy to/from HTTP
BREAK
MQTT
• Message Queuing Telemetry Transport
• In a nutshell, MQTT consist of three parts:
– Broker
– Subscribers
– Publishers
MQTT
MQTT
• MQTT was invented by Andy Stanford-Clark (IBM) and
Arlen Nipper (Arcom, now Cirrus Link) back in 1999,
where their use case was to create a protocol for
minimal battery loss and minimal
bandwidth connecting oil pipelines over satellite
connections. They specified the following goals, which
the future protocol should have:
– Simple to implement
– Provide a Quality of Service Data Delivery
– Lightweight and Bandwidth Efficient
– Data Agnostic
– Continuous Session Awareness
MQTT
• Built for proprietary embedded systems; now
shifting to IoT
• You can send anything as a message; up to 256
MB
• Built for unreliable networks
• Enterprise scale implementations down to hobby
projects
• Decouples readers and writers
• Message have a topic, quality of service, and retain
status associated with them
Publish/Subscribe Concept
Decoupled in space and time:
The clients do not need each others
IP address and port (space) and
they do not need to be running at
the same time (time).
/home/rooms/kitchen/temperature
sub-topic sub-topic sub-topic sub-topic
Durable/Transient Subscriptions
• Subscriptions
– Durable
• If the subscriber disconnect messages are buffered at the
broker and delivered upon reconnection
– Non-durable
• Connection lifetime gives subscription lifetime
M1 M2 M3 M4 M5 M6
Subscription Durable
Application
MQTT
SSL
optional
TCP
IP
TCP/IP Port: 1883
When running over SSL, TCP/IP port 8883
SSL: Secure Socket Layer (encryption)
Publishing “QoS” (Reliability)
• 0 – unreliable (aka “at most once”)
– OK for continuous streams, least overhead (1
message)
– “Fire and forget”
– TCP will still provide reliability
Publishing “QoS” (Reliability)
• 1 – delivery “at least once” (duplicates possible)
– Used for alarms – more overhead (2 messages)
– Contains message ID (to match with ACKed message)
Publishing “QoS” (Reliability)
• 2 – delivery “exactly once”
– Utmost reliability is important – most overhead (4
messages) and slowest
Publishing “QoS” (Reliability)
• Reliability maintained even if the TCP
connection breaks (intermittent connections)
• Separate QoS for publishing and for subscribing
MQTT Message Format
Shortest Message is Two Bytes
Message Types
Message Types
Comparison CoAP & MQTT
Both used in IoT
• CoAP:
– one-to-one communication
– UDP/IP
– unreliable
– lightweight and easy to implement
• MQTT:
– many-to-many communication
– TCP/IP
– focus on message delivery; reliable
– higher overheads (protocol data, processing costs)
BREAK