You are on page 1of 38

Internet of Things

Programming
Andrea Acquaviva
Lesson 1

Andrea Acquaviva IoT programming

Course introduction
Organization
40 h classes
20 h labs (5 labs)

Video recordings
Classes
Lab intro (not the whole lab)

Exam
Written text (multiple choice): 10/30
Project discussion (slides + code): 20/30
Project discussion date is flexible (no time constraints, even in another
session, but raspberry kit must be returned within 3 months from the
end of the course, unless you use yours)
Code + slides (draft) must be sent to TA at least 2 days before
discussion

Andrea Acquaviva IoT programming

Projects
Two types of projects:
Proposed by TA
Proposed by students

Project team
members: 1-3
team building: autonomous
1 raspberry kit for each team

Project selection

TA Projects proposals presented on Oct 30


TA Projects allocation by Nov 5
Student projects proposals by Nov 5
Student projects acceptance by Nov 12

Andrea Acquaviva IoT programming

Course purpose
To learn how to program embedded devices (things)
connected to the internet
How to get data from sensors and give commands to
actuators
How to communicate with other devices
How to write applications to collect data from devices
What is different from standard PC programming?
Andrea Acquaviva IoT programming

Course purpose
Programming IoT devices includes:
Sensors/actuator interfacing
Web oriented programming (ok, this is like PCs) but protocols
and APIs are different
Lightweight, QoS oriented, low-power

Using specific communication paradigm and protocols (e.g.


publish/subscribe)
Using middleware services
Programming for a constrained HW

So, which instruments you need to learn?

Andrea Acquaviva IoT programming

Course contents

Classes
Middleware programming

Introduction to OOP
OO/Web programming with Python
Other Web programming approaches
(Java, Javascript, AJAX, PHP)
XML, JSON formats

IoT devices and smart objects


Architectures, sensors, actuators
Communication protocols: 802.15.4,
Zigbee, 6LowPAN, Internet 0, IPSO
Constraints: power, real-time, reliability

Programming distributed objects using


web services

Middlewares for IoT


Service and resource oriented
architectures

IoT network programming


Publish/subscribe paradigm
M2M protocols: MQTT, CoAP

Resource constrained programming


OS for smart objects
Event driven programming
Real time and security aspects

Web services and microservices


RestFULL, SOAP, WSDL

Andrea Acquaviva IoT programming

Course contents

Raspberry pi2
+ case

Labs
1.

Python programming
Basics, OOP

2.

Web programming I
Web services, cherry py, static pages

3.

Web programming II
Web services, cherry py, dynamic
pages, REST+JSON

4.

Raspberry PI I

T, H sensor

Intro + sensors

5.

RaspberryPI II
Web services + sensors

6.

Relay

RaspberryPI III
Web services + MQTT

Raspberry Pi Model 2 - Quad core CPU 1GB RAM


6x More Powerful Than Previous Models
Black case, 8GB NOOBS Micro SD and adapter
MulPnaPonal Power adapter - 5V 2A UK, EU
Wi nano, 2.0Mtr HDMI, Ethernet cable
Core
Speed
No cores
RAM
OS

ARM710
900 MHz
4
1 GB
Linux

Seminars
IREN (Italian DSO) will demonstrate District Heating
management system (sensors + data in the CLOUD) for
smart city applications
Reply (consulting company) will demonstrate their IoT
solutions

Andrea Acquaviva IoT programming

Introduction

THE INTERNET OF THINGS


SCENARIO

IoT concept
US National Intelligence Council (NIC) considers Internet of Things
as one of the 6 Disruptive Civil Technologies
(April 2008)
IEEE ranks IoT #1 in the list of Top Trends for 2013 (Winter 2012):
The IoT promises to be the most disruptive technological

revolution since the advent of the World Wide Web. Projections


indicate that up to 100 billion uniquely identifiable objects will be
connected to the Internet by 2020

Andrea Acquaviva IoT programming

10

Tentative definition
IoT is
Things having identities and virtual personalities operating
in smart spaces using intelligent interfaces to connect and
communicate within social, environmental, and user
contexts

Andrea Acquaviva IoT programming

11

A more practical one


According to Wikipedia, IoT refers to the interconnection of uniquely
identifiable embedded computing-like devices within the
existingInternetinfrastructure.
Typically, IoT is expected to offer advanced connectivity of devices,
systems, and services that goes beyond
machine-to-machine communications (M2M)and covers a variety of
protocols, domains, and applications.
The interconnection of these embedded devices (including
smart objects), is expected to usher in automation in nearly all fields,
while also enabling advanced applications like aSmart Grid.
Andrea Acquaviva IoT programming

12

What is IoT then?

What is

first proposed by Kevin Ashton

The Internet of Things connects every day consumer objects and


The eInternet
Things
connects
every
day consumer
industrial
quipment of
onto
the network,
enabling
informa=on
gathering objects
equipment
onto
network,
and industrial
management
of these devices
via sthe
o>ware
in order enabling
to increase information g
eciency,
enable new services,
r achieve
other health,
safety, or in order to in
and management
of othese
devices
via software
environmental
benets.
efficiency,
enable new services, or achieve other health, safe
@Kevin_Ashton

environmental benefits.

Kevin Ashton, a BriPsh technologist in


1999 was ExecuPve Director at MITs
Auto-ID C@Kevin_Ashton
enter, an RFID research
consorPum

Kevin Ashton, a British technologist
Wired talk on youtube

in 1999 was Executive Director at


MITs Auto-ID Center,
an RFID research consortium
Wired 2013 talk on YouTube

[Courtesy: Roberto Zafalon, ST microelectronics]

2020

The Digital Explosion


The Digital Explosion
>44
Zettabytes

50 Billion

2013

x10

x5

<4 Zettabytes

13 Billion

Yearly Data creation

Devices

1 ZeDabytes = 1012 Gigabytes

1 Zettabytes = 1012 G

[Courtesy: Roberto Zafalon, ST microelectronics]

By 2020 the Internet traffic will


shift dramatically!
Most of the IP traffic will originate from other than personal
computers (PCs). Wi-Fi traffic will exceed wired traffic and Full HD
video will generate more traffic than standard video.
According to a report issued by Cisco, the number of connected
devices (i.e. through IPv6 and evolution) will grow to some 50 billion
devices by 2020. The internet traffic will get close to 44 Zettabytes
(i.e. 10^21 bytes)!

Things?
Things, in the IoT, can refer to a wide variety of devices
such as heart monitoring implants,bio-chip transponders
on farm animals, automobiles with built-in sensors, or field
operation devices that assist fire-fighters in search and
rescue.
Current market examples includesmart thermostatsystems
and washer/dryers that utilize WiFi for remote monitoring.

Andrea Acquaviva IoT programming

16

New Things
to Augment
LifeLife
New Things
to Augment
Smart City
Reduce traffic congestion
Better use of resources
Improve security

Smart Car
Reduce emissions
Increase safety
Save fuel

Smart Home
Make entertainment more
interactive and immersive
Increase comfort
Save energy

Smart Me Healthcare
Empower patients
Help physicians monitor and
diagnose remotely

Smart Me Wellness
Help to lead healthier lives
Optimize sports performance
Early warning of illness

Smart Industrial
& Smart Services
Productivity gains
Efficiency, agility, water and
food.

[Courtesy: Roberto Zafalon, ST microelectronics]

Making Things Smarter

Making Things Smarter

It used to tell you


the time

It used to remind
you of someone
close to your heart

Now it tells
you what to do

Now it reminds
you to take care
of your heart

And how you


are doing

And exactly
what you
doing

They used to keep


your feet warm

They used to help you


see clearly

Now they help you keep you


and your feet fit

Now they help you


to see more

[Courtesy: Roberto Zafalon, ST microelectronics]

TheInternet
Internet of
of Things
Things Opportunity
The
Opportunity

Existing Things
augmented

New Things to
augment life

[Courtesy: Roberto Zafalon, ST microelectronics]

Internet
EveryThings
Things Scenario
Internet
ofofEvery
scenario
Remote
Monitoring

13

Home and Building


Automation

Power Plant

Smart Metering

Fab automation

Smart Home

Renewable Energy

Plug-in Hybrid Electric Vehicle


Smart
Street Lighting

Smart Systems are pervasive, converging


through Internet of Every Things!

[Courtesy: Roberto Zafalon, ST microelectronics]

IoT Services

21

Enabling Technologies and


Issues
Key technologies:

Sensors/Actuators
Low power, autonomic, pervasive, ubiquitous computing
Communication protocols (REST, CoAP, MQTT)
Microservices and Middlewares
Data Analytics Engines -> in the CLOUD
Apps (iOS, Android, Web)

Key issues:
Interoperability
Security/trust and privacy
Low resources (=> revisit protocols and algorithms
implemented in Internet and Web)
Scalability
Andrea Acquaviva IoT programming

22

Communication Technologies for IoT


1. Bluetooth
2. Zigbee
3. Z-Wave
4. NFC (Near-Field Communication)
5. RFID
6. WiFi
7. 2G/3G/LTE
8. Wibro/Mobile WiMax
9. PLC (Power Line Communication)
10.Ethernet
11. What else?
Andrea Acquaviva IoT programming

Web services & IoT


A smart object system implemented with web services.
Temperature sensors post temperature data to a building
automation server
The building automation server configures a radiator based on
the temperature data
XML

JSON

Andrea Acquaviva IoT programming

24

Publish/Subscribe/Service:/Pattern
Publish/Subscribe
Pattern

ICT$Smartcities$2013$$$2$$$FP72SMARTCITIES22013$$
ICT22013.6.4$Optimizing$Energy$Systems$in$Smart$Cities

Publish/Subscribe$pattern

Andrea Acquaviva IoT programming


DIMMER$2
DIMMER$$28229.10.2014$$Sankt$Augustin$$Alexandr$Krylovskiy

25

Publish/Subscribe: QoS

T$Smartcities$2013$$$2$$$FP72SMARTCITIES22013$$
T22013.6.4$Optimizing$Energy$Systems$in$Smart$Cities

Publish/Subscribe/Service:/QoS

Andrea Acquaviva IoT programming

26

The Concept of Micro-services


Micro-service architecture:
the system is decomposed into a collection of independent and specialized services
each of which exhibits its own interface to access to other services of the system
Each service can be managed independently for deploy / start / stop operations.

Andrea Acquaviva IoT programming

27

Terminologies similar to IoT


1.
2.
3.
4.
5.

USN (Ubiquitous Sensor Networks)


M2M (Machine-to-Machine)
IoE (Internet of Everything) Ciscos favorite term
Cloud of Things
Web of Things

Andrea Acquaviva IoT programming

Introductory Videos
Intel IoT -- What Does The Internet of Things Mean?
http://www.youtube.com/watch?v=Q3ur8wzzhBU

Cisco - How the Internet of Things Will Change Everything-Including Ourselves


http://www.youtube.com/watch?v=B_hjAfPJeRA

IBM Internet of Things


http://www.youtube.com/watch?v=df9xAZZ-8zg

Dr. John Barrett at TEDxCIT The Internet of Things


http://www.youtube.com/watch?v=QaTIt1C5R-M
Andrea Acquaviva IoT programming

Internet of Things: 3 Points of


View?

NFC: Near Field CommunicaPon,


protocols based on RFID

WISP: Wireless idenPcaPon and


sensing plakorm, a RFID
(radio-frequency idenPcaPon)
device that supports sensing and
compuPng

Spimes: Objects trackable in space


and Pme
SemanPc middleware:
sonware layer providing
funcPonaliPes to enable
interoperability among
devices

SemanPc web: web


pages with
annotaPons allowing
data sharing

Internet 0: Lighter
IP using simple
communicaPon
protocol
IPSO: Integrate IP and IEEE
802.15.4 (6LoWPAN) IPSO
Alliance

6LowPAN: IP over
802.15.4

L. Atzori et al. / Computer Networks 54 (2010) 27872805


Andrea Acquaviva IoT programming

The Network Issue


Key issue: object2object communication
First approach: develop specific communication protocols
adapted to each type of things and type of applications
need for standardization
which compatibility with Internet?

Second approach: (re-)use IP


integrate IP and IEEE 802.15.4 (6LoWPAN) (IP for Smart Objects
(IPSO) Alliance)
make IP lighter (Internet )

Third approach: (re-use) 802.15.4


enrich 802.15.4 (Zigbee)

Andrea Acquaviva IoT programming

The Network Issue


From host2host to object2object
TCP is not adapted
Designed for long-lasting connections while objects (like tags or
sensors) exchange small pieces of data => handshake + congestion
control/retransmit/recovery + flow control + buffering procedures too
complex

Very heterogeneous networks and traffic


Scalability?
Quality of service?
Andrea Acquaviva IoT programming

The Identification issue


Ultimate goal: unique/universal ID for naming and addressing
individual objects i.e., to attach an ego to each object, condition
to develop ego-centric applications
Naming is difficult!
IP is limited, not good for mobility
IPv6 comes to the rescue (10^38 addresses) but still lacks mobility,
moreover, imposes overhead limiting payload (e.g. 21-46 bytes for
6LowPAN)
More efficient naming schemes are needed e.g. through ONS: Object Name
Service

Andrea Acquaviva IoT programming

Security and Privacy (1/2)


A definitive threat for privacy!
A security nightmare!
Security
IoT = a kind of unsupervised
mobile/pervasive grids whose endcomponents are resource limited
tiny objects = a security nightmare
Physical attacks
Man in the Middle attacks
Cryptographic techniques too
CPU-intensive for low energy
objects
Etc
Andrea Acquaviva IoT programming

Security and Privacy (2/2)


Privacy
Your life can will be traced => possible monitoring, mining,
analysis
Connection possible with Linked Open Data => worsen the
threats
Open air connections => possibility of eavesdropping
Not only your digital life but also your analogical life
You cannot even know what is sensed about you, when it is
sensed, etc. Sensors do not ask for permission (cf. video
surveillance)
No forget option -> once data are on the Internet they cannot
be (easily) deleted

Andrea Acquaviva IoT programming

Example Application:
Smart Buildings
The thing here is the power plug that becomes a smart plug
Data are processed in the CLOUD and visualized in A/R or V/R
through context aware technologies on a mobile device
5

530

(c) The Circle

(d) The Stealth

Wireless Sensor Nodes.

Module

2420

2520

Prosumer 1

Temperature Sensor

Humidity Sensor

Sensirion
Electric SHT11
Meter
TI TMP125Avago

Photodiode Sensor
Hamamatsu S1087
Hamamatsu S1087-01
ADPS-9300

MV/LV Substation 1

MV/LV Substation j

MV/LV Substation m

Electric Meter

Electric Meter

Electric Meter

Gas Meter
ts CC2530 and Crossbow Telos rev. B Hardware
Water Meter

nb),
ils

ce
ed
se
of
he
on
%.
es
ks
ch
er
en

re
mIn
ed
nd
he
ed

30
ed
da
ng
ys
dto

Heating Meter

WSNs to the web through the LinkSmart middleware Web


Services.
Particular emphasis was given to the possibility to handle
and to reconfigure each node remotely, changing also some
parameters about power management, when it is enabled in the
Prosumer
i
mote. Thus the end-user
stores
the configuration parameters
into the PC-Gateway database via web-service interface. When
Meter
the EN wakesElectric
up from
the sleeping period, the GW creates
Building
automatically the configuration packet that is sent to the
Gas Meter
receiver mote trough the CO, when the EN will wake upconcentrator
from
the sleeping period. The configurable parameters are:
sampling period: the time interval between two consecHeating Meter
utive sampling and transmission of environmental information;
radio wake up interval: the time interval between two
consecutive wakes of the radio module to check for
possible presence of packets to be received;
active sensors: those sensors that must be activated
Prosumer
n
depending on
the environmental
information to be collected. Concerning CC2530, the user can choose between
User
Electric
eter Humidity and Battery level are
Temperature
andMLight;
services
added for TelosB motes.
On CC2530, sampling period and radio wake up interval are
Meter
coincident. TheseWater
setting
will be exported as a virtual EndNode from the GW
to the
upper layers transparently trough
Heating
Meter
Web Services. Therefore the user can choose the right settings
without knowing the real physical hardware related to the
virtual device.
B. Environment and Building Description

Central cloud system

DSO
services

FLEXMETER consorPum

The campus buildings, which were investigated in this

Other
services

Andrea Acquaviva IoT programming

SEEMPubS consorPum
36

IoT as enabling technology for..


Ambient intelligence and context aware applications
User interacting with an interactive environment providing
personalized services
Applications adapts their selves to the environment
https://www.youtube.com/watch?v=ITjsb22-EwQ

Andrea Acquaviva IoT programming

Summary
IoT is an incoming revolution, enabling a world of new applications
New communication paradigms are needed (i.e. publish/subscribe)
Programming IoT requires specific skills (web-network-object oriented,
resource constrained programming)
In this course we will study the main paradigm of IoT programming
using Python, similar concepts can be implemented in Java and other
scripting languages

Andrea Acquaviva IoT programming

You might also like