SlideShare a Scribd company logo
1 of 51
Building it
From mock-up to prototype to
production
• Rapid prototyping is important
• Mock-up vs prototype
– Start with a mock-up, or
– Start working on the target hardware

• Using the same components when
prototyping as in production is good
– Makes production easier
Mock-up: Raspberry Pi
Mock-up: Arduino Yun
Prototyping: CC2538
IoT hardware – closer look
IoT hardware
• Sensors and actuators
– Connectors to the physical world

• Microprocessor
– To be able to do something with the
sensors/actuators

• Communication device
– To communicate with the world

• Power source
Typical IoT hardware properties
• Microcontroller
– Memory
• Flash ROM on the order of 64-512 kilobytes
• RAM on the order of 8-32 kilobytes

– I/O to connect sensors and actuators
• Serial ports, ADCs, SPI, etc

• Radio
– External transceivers
– Systems-on-a-Chip
• Radio integrated with microcontroller
Typical IoT hardware properties
• Power source
– Battery
– Energy harvesting
•
•
•
•

Solar cells
Ambient RF (like RFID)
Piezo electric
Temperature differences
Radio hardware
• Microcontroller + transceiver
–
–
–
–

CC1120 – sub-GHz
CC2520 – IEEE 802.15.4
nRF8001 – Bluetooth Smart
CC3300 – WiFi

• Connected via SPI
• System-on-a-Chip
– CC2538 – IEEE 802.15.4 + ARM Cortex M3
– Broadcom Wiced – WiFi + ARM Cortex M3
Power
• Power consumers
– Sensors, actuators
– Microprocessor
– Communication

• Radio must be completely off
– Consumes power even when idle

• Radio duty cycling mechanisms
OS vs rolling your own
• Rolling your own non-OS firmware
– Write everything, flash the chip

• An OS helps you with
– Network stacks
– Memory managament
– Drivers
– Power management
– ... and much, much more
IoT software challenges
• Severe limitations in every dimension
– Memory
– Processing power
– Communication bandwidth
– Energy, power consumption

• The number of different platforms is large
– Different microcontrollers, different radios,
different compilers
IoT system challenges
• Communication-bound, distributed
systems
– Exceptionally low visibility
• Hard to understand what is going on

– Application development difficult
– Debugging difficult

• Large-scale
• Wireless communication
Wireless connectivity
• Counter-intuitive
• Not a simple replacement to cables
The magic behind it all: Contiki
Contiki: an IoT OS
• Runs on tiny microcontrollers and SoCs
• Handles communication over a number of
different radios
• Provides processes, timers, libraries,
memory allocation, network stacks, etc
Contiki
• Dealing with limited memory
– Memory block allocation strategies
– Protothreads

• Portability
– Fully written in C

• Application development and debugging
– The Cooja network simulator
The Cooja network simulator
A Brief History of Contiki
Contiki: 10+ years old
• Based on the uIP TCP/IP stack
• First release March 10, 2003
– Ports to a range of odd lovely platforms
• Most 6502-based (Apple II, Atari 2600)
• Commodore C64

• The Contiki idea: put things on the Internet
– First system to do IP-based wireless sensor
networks
2008: IPv6 for Contiki
• uIPv6 was contributed by Cisco in 2008
• World’s smallest fully certified IPv6 stack
TIME magazine award
Recent history
• July 2012: Thingsquare founded, Contiki 2.6 released

• October 2012: Moved to github
• November 2012: automated regression tests with Travis
• November 2012: IPv6/RPL updates
• December 2012: New testing framework
• July 2013: Significant RPL updates
• November 2013: Contiki 2.7
Next steps: Contiki 3.x
• Push the Thingsquare firmware features
towards Contiki
• UDP, TCP socket APIs
• HTTP socket API
• Websocket API
Contiki features
• Three network stacks
– IPv4/IPv6 stacks
• RPL, 6lowpan, CoAP, HTTP, ...

– Rime stack

•
•
•
•
•
•
•
•
•
•

Instant Contiki development environment
The Cooja network simulator
Sleepy meshing (ContikiMAC)
Interactive shell
Flash-based file system
Powertracing
Protothreads
Multithreading
Event timers, real-time timers
Libraries: linked list, ringbuf, crc16, etc
Additional Thingsquare features:
Contiki 3.x
• IPv4/IPv6 routing
– NAT64 and DNS64

•
•
•
•
•
•
•

AES encryption
Network sniffer
Frequency hopping protocol
Portable duty cycling (Drowsie, CSL)
WebSocket protocol
UDP, TCP, HTTP socket APIs
More hardware platforms
Back to the Big Red Button
What the Big Red Button did
• When the button switch went from 1 to 0
– Do HTTP POST request to http://requestb.in

• Several steps:
– Ask the DNS server for requestb.in
– Get the answer, but converted to an IPv6 address
– converted by the router
– Set up a TCP connection to the IPv6 address
– The router translates to IPv4
– Send the HTTP POST request
HTTP POST request
POST /abcdefghij HTTP/1.1
Host: requestb.in
Content-Type: application/x-www-form-urlencoded
Content-Length: 15
button=big%20red
The Contiki code
#define URL "http://requestb.in/abcdefghij"
#define DATA "button=big%20red"
static struct http_socket s;
http_socket_post(&s, URL, DATA, strlen(DATA),
"application/x-www-form-urlencoded", callback,
NULL);
RESTful APIs
•
•
•
•
•
•

Leverage the way that HTTP works
Representational state transfer
Coined by Roy Fielding in 2000
Resources, representation
State
Actions, requests
Example RESTful API
• Collection resource
– http://api.example.com/devices

• Element resource
– http://api.example.com/device/23

• Typical actions:
– GET collection
• Return a list of devices

– POST collection
• Create a new device

– GET element
• Return the device

– PUT/POST element
• Update the device information
Representation: JSON
• JavaScript Object Notation
• Very simple
– Compared to stuff like XML

• A representation of a Javascript object
– Can easily be converted back and forth
– var str = JSON.stringify(obj);
– var obj = JSON.parse(str);
JSON Example
{
"id": "12345acb",
"name": "Adam",
"age": 392131145,
"sensors": [ "light", "button" ]
}
Lab 2: Build our own cloud
service
• Device connect to the cloud server with a
websocket
• Server receives message from device,
broadcasts to all connected devices
Material
• Cloud software
– Node.js
– Running on our laptop

• The Thingsquare kit
• Device software
– websocket-example.c
Cloud software: node.js
• Javascript framework for scalable highconcurrency servers
• Non-blocking, event-driven programming
style
• Lots of libraries
• npm – the node package manager
Node.js crash course
• Javascript programs are run from the
command prompt
– node program.js

• Unlike server software like Apache, node.js is
extremely raw
– You program everything from the ground up
– Libraries help you do almost everything

• Use HTTP library to build web server
• Use Websocket library to build web socket
server
Install node
• http://nodejs.org/
• Unzip websocket-server.zip
• Open a command prompt, go to the
websocket-server directory
• In the websocket-server directory, install
the websocket module
– npm install websocket

• node example-server.js
The cloud server code
var serverPort = 8080;
var http = require('http');
var server = http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('This is a websocket-only servern');
response.end();
});
server.listen(serverPort, function() {
console.log('Server is listening on port ' + serverPort);
});
The cloud server code
var websocket = require('websocket').server;
var wsServer = new websocket({
httpServer: server
});
var connections = [];
function broadcastMessage(message) {
for (var i = 0; i < connections.length; i++) {
connections[i].sendUTF(message);
}
}
The cloud server code
wsServer.on('request', function(request) {
var connection = request.accept(null, request.origin);
var connectionIndex = connections.push(connection) - 1;
console.log('Connection from ' + connection.remoteAddress + '.');
connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log('Message: ' + message.utf8Data);
broadcastMessage(message.utf8Data);
}
});

connection.on('close', function(connection) {
connections.splice(connectionIndex, 1);
});
});
The device code
PROCESS_THREAD(websocket_example_process, ev, data)
{
static struct etimer et;
PROCESS_EXITHANDLER(websocket_close(&s));
PROCESS_BEGIN();
websocket_open(&s, "ws://192.168.1.65:8080/",
"thingsquare", callback);
while(1) {
etimer_set(&et, CLOCK_SECOND * 10);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
websocket_send_str(&s, "hello");
}
PROCESS_END();
}
The device code
static void
callback(struct websocket *s, websocket_result r,
uint8_t *data, uint16_t datalen)
{
if(r == WEBSOCKET_CONNECTED) {
websocket_send_str(s, "Connected");
} else if(r == WEBSOCKET_DATA) {
char buf[100];
snprintf(buf, sizeof(buf), "%.*s", datalen, data);
thsq_client_set_str("data", buf);
}
thsq_client_push();
}
Update the code
• Obtain the IPv4 address of your laptop
– On Windows, run “ipconfig” command
– On Linux, run “ifconfig” command
– On Mac, run “ifconfig” command

• Insert your own IPv4 address in the
websocket_open() call
Running the code
• Run the websocket server on your laptop
– node websocket-server.js

• Compile and upload the code to your device
• Enter “data” in the variable inspection field
• You should see
– The server should say something like
• Connection from 192.168.1.98

– The device should say “Connected” then “hello” in
the variable inspection field
What we have done
• We have built our own IoT cloud service
– On our laptop

• We have connected an IoT device to our
cloud service
• We have seen two-way communication,
from the device to the cloud and back
More like this

http://thingsquare.com

More Related Content

What's hot

Zigbee intro v5
Zigbee intro v5Zigbee intro v5
Zigbee intro v5
rajrayala
 
Tech Talk by John Casey (CTO) CPLANE_NETWORKS : High Performance OpenStack Ne...
Tech Talk by John Casey (CTO) CPLANE_NETWORKS : High Performance OpenStack Ne...Tech Talk by John Casey (CTO) CPLANE_NETWORKS : High Performance OpenStack Ne...
Tech Talk by John Casey (CTO) CPLANE_NETWORKS : High Performance OpenStack Ne...
nvirters
 
Node-RED and getting started on the Internet of Things
Node-RED and getting started on the Internet of ThingsNode-RED and getting started on the Internet of Things
Node-RED and getting started on the Internet of Things
Boris Adryan
 

What's hot (20)

Simplifying the OpenStack and Kubernetes network stack with Romana
Simplifying the OpenStack and Kubernetes network stack with RomanaSimplifying the OpenStack and Kubernetes network stack with Romana
Simplifying the OpenStack and Kubernetes network stack with Romana
 
Zigbee intro v5
Zigbee intro v5Zigbee intro v5
Zigbee intro v5
 
ONUG Tutorial: Bridges and Tunnels Drive Through OpenStack Networking
ONUG Tutorial: Bridges and Tunnels Drive Through OpenStack NetworkingONUG Tutorial: Bridges and Tunnels Drive Through OpenStack Networking
ONUG Tutorial: Bridges and Tunnels Drive Through OpenStack Networking
 
Ipx protocol slide share
Ipx protocol slide shareIpx protocol slide share
Ipx protocol slide share
 
Openstack Neutron Insights
Openstack Neutron InsightsOpenstack Neutron Insights
Openstack Neutron Insights
 
High Availability in Neutron
High Availability in NeutronHigh Availability in Neutron
High Availability in Neutron
 
OpenStack Neutron's Distributed Virtual Router
OpenStack Neutron's Distributed Virtual RouterOpenStack Neutron's Distributed Virtual Router
OpenStack Neutron's Distributed Virtual Router
 
Tech Talk by John Casey (CTO) CPLANE_NETWORKS : High Performance OpenStack Ne...
Tech Talk by John Casey (CTO) CPLANE_NETWORKS : High Performance OpenStack Ne...Tech Talk by John Casey (CTO) CPLANE_NETWORKS : High Performance OpenStack Ne...
Tech Talk by John Casey (CTO) CPLANE_NETWORKS : High Performance OpenStack Ne...
 
Node-RED and getting started on the Internet of Things
Node-RED and getting started on the Internet of ThingsNode-RED and getting started on the Internet of Things
Node-RED and getting started on the Internet of Things
 
OCP Summit 2016 - Transforming Networks to All-IT Network with OCP and Open N...
OCP Summit 2016 - Transforming Networks to All-IT Network with OCP and Open N...OCP Summit 2016 - Transforming Networks to All-IT Network with OCP and Open N...
OCP Summit 2016 - Transforming Networks to All-IT Network with OCP and Open N...
 
Neutron scaling
Neutron scalingNeutron scaling
Neutron scaling
 
Neutron scale
Neutron scaleNeutron scale
Neutron scale
 
Network address translation
Network address translationNetwork address translation
Network address translation
 
OpenStack in Action 4! Emilien Macchi & Sylvain Afchain - What's new in neutr...
OpenStack in Action 4! Emilien Macchi & Sylvain Afchain - What's new in neutr...OpenStack in Action 4! Emilien Macchi & Sylvain Afchain - What's new in neutr...
OpenStack in Action 4! Emilien Macchi & Sylvain Afchain - What's new in neutr...
 
IPv6 at Mythic Beasts - Networkshop44
IPv6 at Mythic Beasts - Networkshop44IPv6 at Mythic Beasts - Networkshop44
IPv6 at Mythic Beasts - Networkshop44
 
Open stackdaykorea2016 wedge
Open stackdaykorea2016 wedgeOpen stackdaykorea2016 wedge
Open stackdaykorea2016 wedge
 
Tungsten Fabric Overview
Tungsten Fabric OverviewTungsten Fabric Overview
Tungsten Fabric Overview
 
01 Node-RED Basic
01 Node-RED Basic01 Node-RED Basic
01 Node-RED Basic
 
VPNaaS in Neutron
VPNaaS in NeutronVPNaaS in Neutron
VPNaaS in Neutron
 
Navigating OpenStack Networking
Navigating OpenStack NetworkingNavigating OpenStack Networking
Navigating OpenStack Networking
 

Similar to Building the Internet of Things with Thingsquare and Contiki - day 1, part 3

Securing IoT Applications
Securing IoT Applications Securing IoT Applications
Securing IoT Applications
WSO2
 
chapter-4-networking hjgjjgj did hfhhfhj
chapter-4-networking hjgjjgj did hfhhfhjchapter-4-networking hjgjjgj did hfhhfhj
chapter-4-networking hjgjjgj did hfhhfhj
AmitDeshai
 
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDN
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDNTech Tutorial by Vikram Dham: Let's build MPLS router using SDN
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDN
nvirters
 

Similar to Building the Internet of Things with Thingsquare and Contiki - day 1, part 3 (20)

Using Java Script and COMPOSE to build cool IoT applications, SenZations 2015
Using Java Script and COMPOSE to build cool IoT applications, SenZations 2015Using Java Script and COMPOSE to build cool IoT applications, SenZations 2015
Using Java Script and COMPOSE to build cool IoT applications, SenZations 2015
 
Master-Master Replication and Scaling of an Application Between Each of the I...
Master-Master Replication and Scaling of an Application Between Each of the I...Master-Master Replication and Scaling of an Application Between Each of the I...
Master-Master Replication and Scaling of an Application Between Each of the I...
 
Null mumbai-iot-workshop
Null mumbai-iot-workshopNull mumbai-iot-workshop
Null mumbai-iot-workshop
 
Building the Internet of Things with Eclipse IoT - IoTBE meetup
Building the Internet of Things with Eclipse IoT - IoTBE meetupBuilding the Internet of Things with Eclipse IoT - IoTBE meetup
Building the Internet of Things with Eclipse IoT - IoTBE meetup
 
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
 
Securing IoT Applications
Securing IoT Applications Securing IoT Applications
Securing IoT Applications
 
Eclipse Kura Shoot a-pi
Eclipse Kura Shoot a-piEclipse Kura Shoot a-pi
Eclipse Kura Shoot a-pi
 
End-to-end IoT solutions with Java and Eclipse IoT
End-to-end IoT solutions with Java and Eclipse IoTEnd-to-end IoT solutions with Java and Eclipse IoT
End-to-end IoT solutions with Java and Eclipse IoT
 
Tracking the International Space Station with Commodore Computers
Tracking the International Space Station with Commodore ComputersTracking the International Space Station with Commodore Computers
Tracking the International Space Station with Commodore Computers
 
IoT interoperability
IoT interoperabilityIoT interoperability
IoT interoperability
 
Metarhia: Node.js Macht Frei
Metarhia: Node.js Macht FreiMetarhia: Node.js Macht Frei
Metarhia: Node.js Macht Frei
 
Nodemcu and IOT.pptx
Nodemcu and IOT.pptxNodemcu and IOT.pptx
Nodemcu and IOT.pptx
 
Securing the Internet of Things
Securing the Internet of ThingsSecuring the Internet of Things
Securing the Internet of Things
 
Witekio IoT presentation
Witekio IoT presentation Witekio IoT presentation
Witekio IoT presentation
 
DCUS17 : Docker networking deep dive
DCUS17 : Docker networking deep diveDCUS17 : Docker networking deep dive
DCUS17 : Docker networking deep dive
 
Building Open Source IoT Cloud
Building Open Source IoT CloudBuilding Open Source IoT Cloud
Building Open Source IoT Cloud
 
Chapter - 1 Introduction to networking (3).ppt
Chapter - 1 Introduction to networking (3).pptChapter - 1 Introduction to networking (3).ppt
Chapter - 1 Introduction to networking (3).ppt
 
Scalable Open-Source IoT Solutions on Microsoft Azure
Scalable Open-Source IoT Solutions on Microsoft AzureScalable Open-Source IoT Solutions on Microsoft Azure
Scalable Open-Source IoT Solutions on Microsoft Azure
 
chapter-4-networking hjgjjgj did hfhhfhj
chapter-4-networking hjgjjgj did hfhhfhjchapter-4-networking hjgjjgj did hfhhfhj
chapter-4-networking hjgjjgj did hfhhfhj
 
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDN
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDNTech Tutorial by Vikram Dham: Let's build MPLS router using SDN
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDN
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Building the Internet of Things with Thingsquare and Contiki - day 1, part 3

  • 2. From mock-up to prototype to production • Rapid prototyping is important • Mock-up vs prototype – Start with a mock-up, or – Start working on the target hardware • Using the same components when prototyping as in production is good – Makes production easier
  • 6. IoT hardware – closer look
  • 7. IoT hardware • Sensors and actuators – Connectors to the physical world • Microprocessor – To be able to do something with the sensors/actuators • Communication device – To communicate with the world • Power source
  • 8. Typical IoT hardware properties • Microcontroller – Memory • Flash ROM on the order of 64-512 kilobytes • RAM on the order of 8-32 kilobytes – I/O to connect sensors and actuators • Serial ports, ADCs, SPI, etc • Radio – External transceivers – Systems-on-a-Chip • Radio integrated with microcontroller
  • 9. Typical IoT hardware properties • Power source – Battery – Energy harvesting • • • • Solar cells Ambient RF (like RFID) Piezo electric Temperature differences
  • 10. Radio hardware • Microcontroller + transceiver – – – – CC1120 – sub-GHz CC2520 – IEEE 802.15.4 nRF8001 – Bluetooth Smart CC3300 – WiFi • Connected via SPI • System-on-a-Chip – CC2538 – IEEE 802.15.4 + ARM Cortex M3 – Broadcom Wiced – WiFi + ARM Cortex M3
  • 11. Power • Power consumers – Sensors, actuators – Microprocessor – Communication • Radio must be completely off – Consumes power even when idle • Radio duty cycling mechanisms
  • 12. OS vs rolling your own • Rolling your own non-OS firmware – Write everything, flash the chip • An OS helps you with – Network stacks – Memory managament – Drivers – Power management – ... and much, much more
  • 13. IoT software challenges • Severe limitations in every dimension – Memory – Processing power – Communication bandwidth – Energy, power consumption • The number of different platforms is large – Different microcontrollers, different radios, different compilers
  • 14. IoT system challenges • Communication-bound, distributed systems – Exceptionally low visibility • Hard to understand what is going on – Application development difficult – Debugging difficult • Large-scale • Wireless communication
  • 15. Wireless connectivity • Counter-intuitive • Not a simple replacement to cables
  • 16. The magic behind it all: Contiki
  • 17. Contiki: an IoT OS • Runs on tiny microcontrollers and SoCs • Handles communication over a number of different radios • Provides processes, timers, libraries, memory allocation, network stacks, etc
  • 18. Contiki • Dealing with limited memory – Memory block allocation strategies – Protothreads • Portability – Fully written in C • Application development and debugging – The Cooja network simulator
  • 19. The Cooja network simulator
  • 20. A Brief History of Contiki
  • 21. Contiki: 10+ years old • Based on the uIP TCP/IP stack • First release March 10, 2003 – Ports to a range of odd lovely platforms • Most 6502-based (Apple II, Atari 2600) • Commodore C64 • The Contiki idea: put things on the Internet – First system to do IP-based wireless sensor networks
  • 22.
  • 23. 2008: IPv6 for Contiki • uIPv6 was contributed by Cisco in 2008 • World’s smallest fully certified IPv6 stack
  • 25. Recent history • July 2012: Thingsquare founded, Contiki 2.6 released • October 2012: Moved to github • November 2012: automated regression tests with Travis • November 2012: IPv6/RPL updates • December 2012: New testing framework • July 2013: Significant RPL updates • November 2013: Contiki 2.7
  • 26. Next steps: Contiki 3.x • Push the Thingsquare firmware features towards Contiki • UDP, TCP socket APIs • HTTP socket API • Websocket API
  • 27. Contiki features • Three network stacks – IPv4/IPv6 stacks • RPL, 6lowpan, CoAP, HTTP, ... – Rime stack • • • • • • • • • • Instant Contiki development environment The Cooja network simulator Sleepy meshing (ContikiMAC) Interactive shell Flash-based file system Powertracing Protothreads Multithreading Event timers, real-time timers Libraries: linked list, ringbuf, crc16, etc
  • 28. Additional Thingsquare features: Contiki 3.x • IPv4/IPv6 routing – NAT64 and DNS64 • • • • • • • AES encryption Network sniffer Frequency hopping protocol Portable duty cycling (Drowsie, CSL) WebSocket protocol UDP, TCP, HTTP socket APIs More hardware platforms
  • 29. Back to the Big Red Button
  • 30. What the Big Red Button did • When the button switch went from 1 to 0 – Do HTTP POST request to http://requestb.in • Several steps: – Ask the DNS server for requestb.in – Get the answer, but converted to an IPv6 address – converted by the router – Set up a TCP connection to the IPv6 address – The router translates to IPv4 – Send the HTTP POST request
  • 31. HTTP POST request POST /abcdefghij HTTP/1.1 Host: requestb.in Content-Type: application/x-www-form-urlencoded Content-Length: 15 button=big%20red
  • 32. The Contiki code #define URL "http://requestb.in/abcdefghij" #define DATA "button=big%20red" static struct http_socket s; http_socket_post(&s, URL, DATA, strlen(DATA), "application/x-www-form-urlencoded", callback, NULL);
  • 33. RESTful APIs • • • • • • Leverage the way that HTTP works Representational state transfer Coined by Roy Fielding in 2000 Resources, representation State Actions, requests
  • 34. Example RESTful API • Collection resource – http://api.example.com/devices • Element resource – http://api.example.com/device/23 • Typical actions: – GET collection • Return a list of devices – POST collection • Create a new device – GET element • Return the device – PUT/POST element • Update the device information
  • 35. Representation: JSON • JavaScript Object Notation • Very simple – Compared to stuff like XML • A representation of a Javascript object – Can easily be converted back and forth – var str = JSON.stringify(obj); – var obj = JSON.parse(str);
  • 36. JSON Example { "id": "12345acb", "name": "Adam", "age": 392131145, "sensors": [ "light", "button" ] }
  • 37. Lab 2: Build our own cloud service
  • 38. • Device connect to the cloud server with a websocket • Server receives message from device, broadcasts to all connected devices
  • 39. Material • Cloud software – Node.js – Running on our laptop • The Thingsquare kit • Device software – websocket-example.c
  • 40. Cloud software: node.js • Javascript framework for scalable highconcurrency servers • Non-blocking, event-driven programming style • Lots of libraries • npm – the node package manager
  • 41. Node.js crash course • Javascript programs are run from the command prompt – node program.js • Unlike server software like Apache, node.js is extremely raw – You program everything from the ground up – Libraries help you do almost everything • Use HTTP library to build web server • Use Websocket library to build web socket server
  • 42. Install node • http://nodejs.org/ • Unzip websocket-server.zip • Open a command prompt, go to the websocket-server directory • In the websocket-server directory, install the websocket module – npm install websocket • node example-server.js
  • 43. The cloud server code var serverPort = 8080; var http = require('http'); var server = http.createServer(function(request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.write('This is a websocket-only servern'); response.end(); }); server.listen(serverPort, function() { console.log('Server is listening on port ' + serverPort); });
  • 44. The cloud server code var websocket = require('websocket').server; var wsServer = new websocket({ httpServer: server }); var connections = []; function broadcastMessage(message) { for (var i = 0; i < connections.length; i++) { connections[i].sendUTF(message); } }
  • 45. The cloud server code wsServer.on('request', function(request) { var connection = request.accept(null, request.origin); var connectionIndex = connections.push(connection) - 1; console.log('Connection from ' + connection.remoteAddress + '.'); connection.on('message', function(message) { if (message.type === 'utf8') { console.log('Message: ' + message.utf8Data); broadcastMessage(message.utf8Data); } }); connection.on('close', function(connection) { connections.splice(connectionIndex, 1); }); });
  • 46. The device code PROCESS_THREAD(websocket_example_process, ev, data) { static struct etimer et; PROCESS_EXITHANDLER(websocket_close(&s)); PROCESS_BEGIN(); websocket_open(&s, "ws://192.168.1.65:8080/", "thingsquare", callback); while(1) { etimer_set(&et, CLOCK_SECOND * 10); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); websocket_send_str(&s, "hello"); } PROCESS_END(); }
  • 47. The device code static void callback(struct websocket *s, websocket_result r, uint8_t *data, uint16_t datalen) { if(r == WEBSOCKET_CONNECTED) { websocket_send_str(s, "Connected"); } else if(r == WEBSOCKET_DATA) { char buf[100]; snprintf(buf, sizeof(buf), "%.*s", datalen, data); thsq_client_set_str("data", buf); } thsq_client_push(); }
  • 48. Update the code • Obtain the IPv4 address of your laptop – On Windows, run “ipconfig” command – On Linux, run “ifconfig” command – On Mac, run “ifconfig” command • Insert your own IPv4 address in the websocket_open() call
  • 49. Running the code • Run the websocket server on your laptop – node websocket-server.js • Compile and upload the code to your device • Enter “data” in the variable inspection field • You should see – The server should say something like • Connection from 192.168.1.98 – The device should say “Connected” then “hello” in the variable inspection field
  • 50. What we have done • We have built our own IoT cloud service – On our laptop • We have connected an IoT device to our cloud service • We have seen two-way communication, from the device to the cloud and back

Editor's Notes

  1. 2.4 GHz Cortex-M3 SOCThe small boards contains the SOC with antenna etc, just connect to power and run. The big board is for JTAG programming and debugging.