INTERNET OF THINGS
(DESIGN PRINCIPLES FOR
WEB CONNECTIVITY)
By: Dr. Raj Kamal
Copyright © 2017 McGraw Hill Education, All Rights Reserved.
PROPRIETARY MATERIAL © 2017 The McGraw Hill Education, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced
or distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers
and educators permitted by McGraw Hill for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without
permission.
Chapter 3
Web Connectivity of Devices
and Devices Network
Application
Application: A software (S/W) for an application, such as,
creating and sending an SMS, measuring and sending the
measured data, receiving message from specified sender
App: Short abbreviation for Application S/W in mobiles or
devices
Application Programming Interface (API)
Software (S/W) component which receives messages
from one end and send those to other end that execute
an Application
Example: an API consisting of GUI (Button, Check Box,
Text Box, Dialog Box) for input(s) and send command(s)
to other end S/W for running the Application for graphics
Web Service
A service using the web protocols, web objects or webSockets
For examples: weather-reports communication service,
traffic-density reports communication service,
streetlights monitoring and controlling service
4
Resource
One that can be read, written or executed.
A path specification also a resource
The resource is atomic (not further divisible) information
which is usable during computations, for example,
temperature
A resource may have multiple instances or just a single
instance
Resource Directory
Resource Directory (RD) maintains information and values
for each resource-type.
A resource of a resource-type accessed from an RD using a
URI for that resource.
Object
A collection of resources, for example, collection of data and methods
(also called functions; procedures) to operate on that data.
Example: Time_Date object with second, minutes, hour, day, month,
and year fields and update methods (field means a memory address
for the value)
Object Instance
Can be just one for an object which is instance of a Class as in Java
An example of object instance is weather report object for reporting
the rains.
Multiple Object instances
Java uses concept of class
Class creates one or more object- instances
JavaScript creates multiple object instances from an object itself
URI (Universal Resource Identifier)
Used for retrieving saved resources, such as Contacts or
address book
An URI example: /Contacts/First_Character_R/ for a set a
resource directory Contacts having resource repository
First_Character_R for the contacts with first character R
Examples
sensorNetwork_J/sensorID_N/ temperature for a temperature
value
The value is at a resource directory sensorNetwork_J for a
sensor network
Identifies the stored sensors data for a sensor of the id
sensorID_N.
URL
Generally used for resources retrieval at a client from the
saved resources at a remote server on Internet
Example: http://www.mhhe.com/ for a set of resource
directories, resource repositories and resources
Representational State Transfer
(REST)
A software architecture with following characteristics; an
architecture used during design of software components
Uses the identifiers for the resources and methods
Specifies the access-methods and data transfer methods
during interactions
Specifies the practices, constraints, characteristics and
guidelines
Used for Creation of the scalable web services
Scalable means can be used as per the size
Constrained Environment for
Connected Devices
Data is limited in size
10s of Bytes from a device
Limited compared to data interchange of 1000s of bytes
between web clients and web servers when using HTTP, TCP
and IP
Data routes over the low power and lossy (ROLL) network
Devices may sleep most of the time in low power
environment
Awakes when required (when a client initiates)
The connectivity breaks for long periods
Have limited up intervals in lossy environment
CoAP (Constrained Application
Protocol)
An IETF recommended protocol for constrained environment
devices
A web-object’s data transfer standard protocol for sending a
request or response
For example, RESTful CoAP
Client and Server
Object or resource uses CoAP
CoAP client at a device, IoT/M2M Area Local Network or
Gateway sends requests to a server
CoAP server sends the responses, messages, resources and
notifications
CoAP Features
Standard organisation IETF defined Application support layer protocol
CoAP web-objects communication using request/response interactions
model
A specialized web transfer protocol used for CoRE using ROLL network.
Use of object model for resources, and each object can have single or
multiple instances.
Each resource can have single or multiple instances
Supports resource directory and resource discovery functions.
The resource identifiers use the URIs coap://…
Small message-header of 4 bytes.
CoRE communication is asynchronous communication over the ROLL
Integrates easily with the web using the CoAP application cross-protocol
proxies.
Because HTTP and CoAP both share the REST model
Lightweight in LWM2M (Lightweight
Machine to Machine)
Transfers up to 100s of bytes unlike the web-pages of 1000s of bytes
Data transfer formats between client and server: Binary and has TLV
(Tag Length Value) or JSON (Java Script Object Notation) batches of
objects arrays or resource arrays or MIME (Multipurpose Internet Mail
Extensions) Type file
Protocol
An Application-layer protocol specified by OMA (Open Mobile Alliance)
for transfer of service data between the machines
Uses Compact and Efficient data model
A M2M Gateway protocol generally interface to CoAP for the web
connectivity
Features of LWM2M Objects and Resources
An object or resource use CoAP, DTLS, and UDP or SMS
standard protocols for sending a request or response.
Use of
Plain text for a resource or
Use of JSON (Java Script Object Notation) during a single
data transfer
Uses binary TLV format data transfer for a package for a
batch of resource-representations in a single data
transfer
Objects or its resource access using URI (Universal resource
identifier)
Request/Response (Client/Server)-based
Messaging Protocol
An object (client) requests for a resource(s)
Another end object (server) sends the response
Both client and server using REST functions.
Request adds the header words.
Pub/Sub (Publish/Subscribe)-based
Messaging Protocol
An object (server) publishes the a resource(s) for the
clients
Another end object (client) receives the resource on
subscription
Numbers of clients can subscribe to a published resource,
for example, weather report or location information
A separate subscription required for each resource-type or
topic
Provisions for publication of messages and their reception
on subscription
PUT method used by Pub and GET Method by the registered
or authenticated devices.
Publisher registers or deregisters a device for a resource
type
Registration
Registration means a receiver registers with a service, for
example, a resource directory service (RD).
When one or more end-points or devices or nodes registers,
then that gets the access to the resources and receives
published messages.
Security considerations may require authentication of both
ends (service provider and receiver) before registration.
A separate registration required for each end-point (client or
server)
Registration Update
Updating registrations for one or more end-points or devices
or nodes
Also includes unregistering for one or more end-points.
Polling or Observing
Finding from where new messages available
Finding whether new messages available
Finding updates available
Finding whether or not a need for refresh of information
Finding the state information changed or same.
A Polling method client uses REST architecture GET method and server
uses POST method.
A state may mean connection, or disconnection, sleep, awake, created,
alive (not deleted), old values persisting or updated with new values..
(OBSERVE method)
GET + OBSERVE method
Observing means looking for change, if any, of a state at periodic
intervals
Message Queue
Stores in sequences the messages (data) from devices or end-
points
When sought or when connection state changes then forwarding
the messages
Forwarding is in first-in first-out methods for a resource-type
A message forwards once only from a queue
Separate queue forms for each resource-type
The messages forward to the registered devices or end points and
to the subscribed devices or end points
A separate registered devices or end points list and a separate
subscription list maintained and used for each resource type
Forwarding takes place after matching the subscription from a list
MQTT (Message Queuing Telemetry
Transport)
An open source protocol for machine-to-machine
(M2M)/"Internet of Things" connectivity
(Telemetry dictionary meaning is measuring and sending
values or messages to far off places by radio or other
mechanism)
Created by IBM
The objects communicating using the Connected devices
network protocols, such as ZigBee.
Web objects also using MQTT library functions and
communicate using IP network and SSL and TLS security
protocols
MQTT Features
Constrained environment protocol,
PubSub messaging architecture in place of request-response
client-server architecture
publisher (message sender at the device domain or web
object at network and application domain) sending the
messages on a topic
Extensible Mark up Language (XML)
An open source popular language which uses the markups
Markup means marking by some signs and characters or
tags so specify the contents between the markups.
Markup can be at the beginning as well as end of the
contents within. Each markup in XML language has text
within a pair of tag and end-tag.
For eaxmple, <Contact_Name> Raj Kamal </Contact_Name)
Example of an XML message
<SensorTemp ID = ‘250715’ TimeDate = ‘19:28:33 Jul 17
2015’> 22 </SensorTemp>.
Java or C++ or other langauge Parser reads the XML and
finds that sensor of ID = 250715 had T = 22 C on
17.07.2015 at 19:28:33
XMPP
XMPP specifies the Instant Messaging (IM) and Presence,
RFCs are for Internet, protocols, procedures, programs, and
concepts and other related aspects
RFC 6122 XMPP specifies the Address format
Enables communication
Interoperable, for example, Google Talk.
XMPP enables IMs (Instant Messaging) between many using
presence notification and Chat features
Anyone can set XMPP server by following the standards
recommended and using the XSF xeps
for example, XMPP-IoT server, XMPP M2M server for messaging
between the machines.]
MQTT Features
Subscriber (message receiver at the device domain or web object at
network and application domain) receiving the messages on a subscribed
topic,
Lightweight, running on limited resources of processor and memory
processor or memory resources
Header of fixed-length header and two bytes only
M2Mqtt library providing a set of functions for coding
M2Mqtt library functions in Java needing just 100 kB and in C# is 30 kB,
Minimum number of exchanges, and therefore lessening the network traffic
Three Quality of Services
MQTT TCP/IP Connectivity
Broker-based publish/subscribe messaging protocol,
publish/subscribe functions enable one-to-many message distribution
decoupled with the applications (unconcerned about the payload),
MQTT Features .. Contd.
Notifying on an abnormal disconnection of a client, notified all nodes
subscribing to the message, also notifies Will message, means last will
The last will specifying the final action to be taken on failure to send the
messages
MQTT Broker Functions
1. Store and forward,
2. Clients publish topics and receives topics on subscription,
3. Recovers subscriptions on reconnect after a disconnection, unless
client explicitly disconnected
4. Acts as a broker between publisher of the topics and subscribers of
the topics
5. Finds client disconnection until DISCONNET message receives
6. keeps message alive till explicit disconnection
7. retains the last received message from a publisher for a new
connected subscriber on same topic, when retain field in the header
is set.
Communication Gateway
Connects two application layers, one at sender and other at
receiver
Gateway enables use of two different protocols at sender
and receiver ends
The HTTP server posts and devices network gets the data
using the Gateway
Facilitates the communication between IoT devices and web
server, for example,
1. ZigBee to SOAP and IP or
2. CoAP protocol conversion gateway for RESTful HTTP
Connects the sender and receiver ends using two different
protocols
SOAP
Facilitates for exchange of objects between the Applications
using the XML
Facilitates access to a web Service
Specifies the formats and a way of sending messages
Usage in independent of Application language and platform (OS
and hardware).
Extensible
Also used for APIs for the web services and SOA (service-
oriented architecture)
REST (Representational State Transfer)
CoAP, HTTP and XMPP use REST architectural style
REST style developed by W3C Technical Architecture Group
(TAG)
Simpler than SOAP and WSDL (Web Services Description
Language)
HyperText Transfer Protocol (HTTP)
Most-widely used Application layer protocol for
communication over TCP/IP
An HTTP client first connects to an HTTP server using TCP
transport layer and then other lower layers
The client then sends a resource after establishing a HTTP
connection
HTTP Request Message Example
POST /item HTTP/1.1Host:
ii.jj.kk.mmContent-Type: text/plain
Content-Length: 200
Means use version 1.1 of HTTP and send using POST ( )
methods
Content type is plain text and length =
200 B
HTTP Response on Processing of Request
200 OK Content-Type: text/plain
Content-Length: 200
200 is standard code in an HTTP
connection which conveys successful
receipt of 200 B contents
HTTP Polling
A method for receiving new message or update from an
HTTP server
Polling means finding whether new message or update
available and receive that in case available
HTTP long polling
API sends a request to the server, server keeps the request
open for a set period, and
Stream hidden in iframe
The polling methods have high latencies and header sizes of
100s B.
HTTP Transfer Characteristics
Stateless, which means, each data transfer is an
independent request
Header overhead information and meta-data of previous
state needs to be resent with each HTTP request
Meta Data describe the data for later on interpretation at
the other end
Usages of HTTP Transfers both directions at same instance
Multiple TCP connection,
HTTP requests at short regular intervals so that
responses are nearly in real time
Polling at successive intervals
Stateless, Client-Server, Cacheable
communication
REST design depends on the characteristics of stateless,
client-server, cacheable communication
Client or server or intermediate systems can cache the
responses
Cacheability Scalability
• Clients or intermediate Ability to support greater
layers can cache the number of interactions
responses among components and
• Server Responses must greater number of
therefore be implicitly components
or explicitly, define
themselves as
cacheable, or not
REST Feature of usages
… of Intermediate
… of Layered System system(s)
A client can connect Client may not ordinarily
through intermediate be made aware whether it
(proxy or firewall or is connected directly to the
Gateway intermediary end server
server) layers enables assistance in
REST enables intermediate transcoding and different
layer processing by protocols at two ends.
constraining messages to Improves performance
be self-descriptive
when using bigger scales
interaction.
and shared caches.
REST Feature of Simplicity of Interfaces
1. Modifiability of components enables the changes according
to the needs, even while an App is running,
2. Visibility of communication between components by service
agents,
3. Portability of components by moving the objects, Object
means program code with the data
4. Reliability is the resistance to failure at the system level in
the presence of failures within data elements, components
or connectors,
Formal REST Constraint of Uniform
Interfaces
Identification of individual resources, identified in requests, for
example, using URIs in web-based REST systems,
Separation of concerns which means Client–server interactions are
such that a uniform interface separates clients from servers.
Client holding representation of a resource including any metadata
attached then it means it has enough information to modify or delete
the resource.
Manipulation of resources through representations sent to the
client,
Stateless client–server communication which means that
constraints are such that client context does not store at the server,
each request from client is considered independent of previous one
WebIDL and Instant Messaging
Web Interface Definition Language (Web IDL)
(http://www.w3.org/TR/WebIDL/ )
Instant messaging and many applications needs bi-direction data
exchanges over same connection
WebSocket enables bi-directional communication over a single
TCP connection
WebSocket Protocol
An independent TCP-based protocol
Intended to be compatible with HTTP-based server-side software
and intermediaries,
Single port can be used by both HTTP clients talking to that
server and WebSocket clients talking to that server.
An IETF standard protocol
RFC 6455 specifications of the web protocol.
(www:/tools.ietf.org/ html/rfc6455) [December 2011]
WebSocket API (WSAPI) W3C standard
WebSocket Features and WSAPIs
Small header size (2 Byte) [Over 500 Byte for HTTP request and
response headers]
WSAPIs facilitate live content and the creation of real-time
games.
Therefore, much smaller latency in message interchanges
Small header size (2 Byte) [Over 500 Byte for HTTP request and
response headers]
WSAPIs facilitate live content and the creation of real-time
games.
Therefore, much smaller latency in message interchanges
Types in WebSocket
These types are
1. textual data (UTF-8)
2. binary data (whose interpretation is left up to the
application)Ten additional reserved for future use
(version 13)
Clients and servers exchange the “messages” after success
of handshake
Associated Type Frame Control frame
Each frame belonging to the same • Frame not intended to carry data
message contains the same type for the application
of data. • Used for protocol-level signaling,
such as to signal that the
connection should be closed
• Supports HTML5 WebSocket
when the client and server
support HTML5,