1. Drop the Phone and Talk to the Physical World:
Programming the Internet of Things with Erlang
Alessandro Sivieri Luca Mottola Gianpaolo Cugola
DEEPSE Group
Dipartimento di Elettronica e Informazione
Politecnico di Milano
Third International Workshop on
Software Engineering for Sensor Network Applications
June 2nd , 2012
2. Scenario
Internet of Things
Sensing and actuation systems
Massively decentralized
Heterogeneous devices
Wireless Sensor Networks
Forerunner and key component of IoT
WSN community was the rst to tackle the IoT issues
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 2
3. Motivation
Current approaches
Low-level frameworks (i.e., TinyOS, Contiki): full control of
resources vs. diculties in testing and maintaining applications
High-level frameworks (i.e., Regiment, Flask): ease of
programming vs. generality and performance
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 3
4. ErLang meets IoT
Why Erlang
Actor-like concurrency
model
Declarative programming
...
ELIoT
Dedicated libraries and customized syntax for many-to-many
IPC
Reduced hardware requirements for the run-time system
Dedicated simulator (full and mixed congurations)
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 4
5. Outline
Erlang
ELIoT
Preliminary results
Conclusions
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 5
6. Erlang
Main characteristics
Concurrent execution without shared memory, side-eects free
computation
Transparency of the network distribution
Single-assignment semantics, improving testing and debugging
Libraries for fault detection
Code hot-swap
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 6
7. Erlang - A Brief Example
Creating processes
1 start (X ) -
2 Pid = spawn(fun operations/0),
3 Pid ! { self () , X} ,
4 receive
5 { Sender , Result } -
6 Result
7 end .
8
9 operations () -
10 receive
11 { Sender , Number } -
12 Sender ! { self () , Number * Number };
13 { Sender , Number1 , Number2 } -
14 Sender ! { self () , Number1 * Number2 }
15 end .
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 7
8. Erlang - A Brief Example
Sending messages
1 start (X ) -
2 Pid = spawn ( fun operations /0) ,
3 Pid ! {self(), X},
4 receive
5 { Sender , Result } -
6 Result
7 end .
8
9 operations () -
10 receive
11 { Sender , Number } -
12 Sender ! { self () , Number * Number };
13 { Sender , Number1 , Number2 } -
14 Sender ! { self () , Number1 * Number2 }
15 end .
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 7
9. Erlang - A Brief Example
Receiving messages using pattern matching
1 start (X ) -
2 Pid = spawn ( fun operations /0) ,
3 Pid ! { self () , X} ,
4 receive
5 { Sender , Result } -
6 Result
7 end .
8
9 operations () -
10 receive
11 {Sender, Number} -
12 Sender ! {self(), Number * Number};
13 { Sender , Number1 , Number2 } -
14 Sender ! { self () , Number1 * Number2 }
15 end .
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 7
10. Outline
Erlang
ELIoT
Preliminary results
Conclusions
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 8
11. ELIoT
The library
Processes must be explicitly allowed to receive messages from
other devices
The send operator (!) also supports broadcast operations
1 myprocess () -
2 erlang : register ( somename , self ()) ,
3 erlang : export ( somename ),
4 Data = eliot_gpio : get (? TEMPERATURE ) ,
5 { somename , all } ! { temperature , Data }.
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 9
12. ELIoT
The library
Processes can be spawned on other nodes of the network,
nodes can specify properties that can be used to choose on
which of them these processes will be executed
mysensor_init() -
eliot:put(room, 301).
mysink_update () -
Cnd = fun () -
eliot : get ( room ) == 301
end ,
eliot : spawn ( fun newfunction /0 , Cnd ).
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 10
13. ELIoT
The library
Processes can be spawned on other nodes of the network,
nodes can specify properties that can be used to choose on
which of them these processes will be executed
mysensor_init () -
eliot : put ( room , 301).
mysink_update() -
Cnd = fun() -
eliot:get(room) == 301
end,
eliot:spawn(fun newfunction/0, Cnd).
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 10
14. ELIoT
The interpreter
Removed all functionalities integrated in the platform but not
required for IoT applications
Support for sensing and actuation devices
Support for broadcast operations directly integrated in the
interpreter
Microprocessor Ralink RT3050
RAM 32 MB
ROM 8 MB
Freq. 320 MHz
Networking Ethernet, WiFi
Interfaces GPIO/SPI/I2C/Serial
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 11
15. ELIoT
The simulator
Leverage Erlang native transparency of the network distribution
Full simulation using virtual nodes and unmodied code,
model the virtual communication using dierent techniques
Mixed simulation using virtual and real nodes at the same time
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 12
16. ELIoT
The simulator
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 13
17. Outline
Erlang
ELIoT
Preliminary results
Conclusions
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 14
18. Preliminary results
Example applications
Trickle, a propagation algorithm
Opportunistic ooder, another propagation algorithm
Collection Tree Protocol, a data collection algorithm
Some numbers
Algorithm TinyOS Contiki ELIoT % gained
Opportunistic ooder 495 187 178 5-64%
Trickle 219 194 148 24-32%
CTP 2169 1470 450 70-80%
Lines of code
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 15
19. A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 16
20. Outline
Erlang
ELIoT
Preliminary results
Conclusions
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 17
21. Conclusions
Leverage Erlang native characteristics, introduce new
mechanisms required by IoT
Single node programming, reprogramming of the entire
network
Testing and simulation in full or mixed congurations
Future Works
Integration of IoT idioms into the language
Further customization of the interpreter
Formal verication (correctness) of applications
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 18
22. Thank You
Questions?
A. Sivieri, L. Mottola, G. Cugola ErLang for the Internet of Things 19