Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lecture on the Web of Things

2,443 views

Published on

This is the course material of the Web of Things lecture that was taught at MIT, IoT week and in several universities.

Published in: Internet
  • Hey guys! Who wants to chat with me? More photos with me here 👉 http://www.bit.ly/katekoxx
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Lecture on the Web of Things

  1. 1. © EVRYTHNG INC. | 2016 COMMERCIAL & CONFIDENTIAL Smarter products come with EVRYTHNG For Customers title slide Workshop: Building the Web of Things One layer at a time! @domguinard @vladounet Dominique Guinard, CTO – co-founder @domguinard @EVRYTHNG We are hiring devs: evrythng.com/jobs
  2. 2. https://bit.ly/wot-lecture Presented at:
  3. 3. Where the Web of Things was born... http://webofthings.org
  4. 4. Define IoT! ▪ DEFINITION: The Internet of Things is a system of physical objects that can be discovered, monitored, controlled, or interacted with by electronic devices that communicate over various networking interfaces and eventually can be connected to the wider Internet.
  5. 5. The IoT is a science primarily focusing on creating the most complex ways of turning lights on. “ “ [@domguinard]
  6. 6. @ConnectEvrythng© EVRYTHNG Limited | Confidential | 2013 @EVRYTHNG© EVRYTHNG | Confidential | 2014 + Pre IoT
  7. 7. @ConnectEvrythng© EVRYTHNG Limited | Confidential | 2013 @EVRYTHNG© EVRYTHNG | Confidential | 2014 Post IoT
  8. 8. The Web of Things is a refinement of the Internet of Things by integrating smart things not only into the Internet (network), but into the Web Architecture (application) “ “ [@domguinard]
  9. 9. Enters the Web of Things!
  10. 10. Great, but this was 2007!
  11. 11. Yeah, sure. Not!“ “ [The embedded/IoT community]
  12. 12. The Web is for blogs!“ “ [The embedded/IoT community]
  13. 13. Researching the Web of Things... Get the theses from: http://webofthings.org/publications
  14. 14. The Web of Things Architecture ▪ Converge all the Things towards Web protocols! − Web Gateway ▪ WoT principles: ▪ Reuse the Web! ▪ Unless: − Battery powered − Very low-power − Need for a mesh ▪ => Choose Web protocols − HTTPS, WSS, etc.
  15. 15. WoT in use @EVRYTHNG on billions of products!
  16. 16. http://book.webofthings.io 39% off “Building the Web of Things” with code “39guinard” on:
  17. 17. Discover the WoT Chapters 1 - 2
  18. 18. Chapter 1: IoT vs WoT
  19. 19. Chapter 2: Browsing Things http://devices.webofthings.io
  20. 20. Dom Guinard CTO & Co-founder
  21. 21. Interact with Things in a few lines of JS code! $(document).ready( //#A function doPoll() { $.getJSON('http://devices.webofthings.io/pi/sensors/temperature', //#B function (data) { //#C console.log(data); $('#temp').html(data.value + ' ' + data.unit); //#D setTimeout(doPoll, 5000); //#E }); }); //#A Wait until the page is loaded and then call doPoll() //#B Use the AJAX helper to get the JSON payload from the temperature sensor //#C When the response arrives, this function is called //#D Select the "temp" HTML element and update its content using the data.value (the value) and data.unit (the unit) returned in the JSON payload //#E The doPoll() function sets a timer to call itself again in 5 seconds (5000 milliseconds)
  22. 22. Lab 1: Hello WoT: The Web as an Application Layer See also: Chapter 2 from page 36 1. Fork & Clone the book code: - git clone https://github.com/webofthings/wot-book --recursive - Try pushing from your machine, pulling from the Pi 2. Browse the device as a Human on: http://devices.webofthings.io/ 3. Install Postman and browse the device as an App - URL: http://devices.webofthings.io/ - Accept: application/json 4. Modify 2.2 code to get the humidity value every 5 seconds 5. Bonus: change the type of graph in 2.2
  23. 23. Embedded Systems & Node Chapter 3 - 4
  24. 24. Chapter 4: Getting started with IoT Devices VS Multicores 32-64 Bits X GB of RAM X GB of Flash Microcontroller 8 Bits X KB of RAM X KB of ROM
  25. 25. Chapter 3: Node.js for Embedded Devices? Really? ▪ Before: − C rules − Windows based IDEs, 1 per platform − Small community, highly specialized − Very resource constrained devices − Integration via specialized SDKs ▪ After − Node.js is taking over! − Larger community, more reach, more innovation − Huge ecosystem of libraries − Integration via the Internet and the Web
  26. 26. Node on embedded devices: Hardware support Espruino Edison Tessle Artik Kinoma Beaglebone Raspberry Pi (Pi Zero incl.)
  27. 27. Why Node?
  28. 28. Lab 2: Hello Node.js See also: Chapter 4, page 98 1. Install NVM & Node.js on your Pi and computer - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash - nvm install v4.8.3 2. Build your (first?) Node HTTP server 3. Bonus: build a more advanced server, see Listing 3.2 page 66
  29. 29. GPIOs: sensing & actuating Chapter 4
  30. 30. Chapter 4: Sensors, Actuator & GPIOs
  31. 31. GPIO support via Node on Embedded Systems http://johnny-five.io https://github.com/fivdi/onoff https://github.com/intel-iot-devkit/mraa https://cylon.js http://ni-c.github.io/heimcontrol.js/ https://github.com/webofthings/webofthings.js
  32. 32. An example with On/Off: connecting a PIR sensor var Gpio = require('onoff').Gpio, sensor = new Gpio(17, 'in', 'both'); //#A sensor.watch(function (err, value) { //#B if (err) exit(err); console.log(value ? 'there is someone!' : 'not anymore!'); }); function exit(err) { if (err) console.log('An error occurred: ' + err); sensor.unexport(); console.log('Bye, bye!') process.exit(); } process.on('SIGINT', exit); // #A Initialize pin 17 in input mode, 'both' means we want to handle both rising and falling interrupt edges // #B Listen for state changes on pin 17, if a change is detected the anonymous callback function will be called with the new value
  33. 33. Lab 3: GPIO & Node See also: Chapter 4, from page 102 1. Setup the PIR sensor (see page 104) 2. Connect it to onoff.js code (see chapter4-gpios/pir.js) 3. Bonus: setup the DHT sensor (see Chapter 4 from page 105)
  34. 34. Wiring the PIR sensor
  35. 35. IoT Networks Chapter 5
  36. 36. Different Protocol Stacks
  37. 37. The 2 valid reasons for not choosing IP+Web end-to-end Battery Powered Devices Deployment requires a mesh
  38. 38. Web vs Not Web: Why should I care?
  39. 39. Source: http://xkcd.com
  40. 40. The Web of Things Architecture ▪ Converge all the Things towards Web protocols! − Web Gateway ▪ WoT principles: ▪ Reuse the Web! ▪ Unless: − Battery powered − Very low-power − Need for a mesh ▪ => Choose Web protocols − HTTPS, WSS, etc.
  41. 41. WoT Architecture: Access Chapters 6 - 7
  42. 42. Web API for Things: 5 Steps Design Process 1. Integration strategy—Choose a pattern to integrate Things to the internet and the web. 2. Resource design—Identify the functionality or services of a Thing, and organize the hierarchy of these services. 3. Representation design—Decide which representations will be served for each resource. 4. Interface design—Decide which commands are possible for each service, along with which error codes. 5. Resource linking design—Decide how the different resources are linked to each other. [Gui2010] Guinard, D., Trifa, V., Wilde, E. A Resource Oriented Architecture for the Web of Things. IoT 2010
  43. 43. 1. Integration Strategy
  44. 44. The Web on Devices!
  45. 45. But: Not all devices can speak Web!
  46. 46. Integration via Gateway
  47. 47. The Cloud as a Gateway (e.g., EVRYTHNG)
  48. 48. Example: EVRYTHNG Smart Products Platform
  49. 49. 2. Resources, Representations & Links
  50. 50. Design Process Applied Request: GET /pi Host: devices.webofthings.io Accept: application/json Response: 200 OK Content-Type: application/json { "name" : "Pi" ... } 2. Resource design 3. Representation design 4. Interface design GET PUT 5. Linking Design
  51. 51. Beyond HTTP: Websockets for Event Driven Communication HTTP 1.1 WebSockets
  52. 52. WebSocket Client function subscribeToWs(url, msg) { var socket = new WebSocket(url); socket.onmessage = function (event) { console.log(event.data); }; socket.onerror = function (error) { console.log('An error occurred while trying to connect to a Websocket!'); console.log(error); }; socket.onopen = function (event) { if (msg) { socket.send(msg); } }; } //subscribeToWs('ws://localhost:8484/pi/sensors/temperature');
  53. 53. Lab 4: Designing the Pi API See also: Chapter 7 1. Code deep-dive chapter7-implementation/part1-2-direct-gateway - Resources (add a noise sensor) - Representation (see messagepack) 2. Adding a representation - Add CBOR support - npm install --save cbor - In converter.js 3. Communication via WebSocket - chapter2-hello-wot/client/ex-2.3-websockets-temp-graph.html 4. Bonus: bind the PIR sensor of your Pi (see page 183)
  54. 54. WoT Architecture: Find Chapter 8
  55. 55. 3 Challenges in IoT Findability 1. Bootstrap URL? 2. What’s the format? (syntax) 3. What does that mean? (semantics) The Web can help with all 3!
  56. 56. How to find the URL of a Thing? mDNS! ▪ mDNS clients listen for mDNS messages (on UDP) ▪ DNS tables are populated from what they catch ▪ Your Pi broadcasts mDNS messages as we speak! service up: { interfaceIndex: 4, type: { name: 'http', protocol: 'tcp', subtypes: [], fullyQualified: true }, replyDomain: 'local.', flags: 3, name: 'Brother MFC-8520DN', networkInterface: 'en0', fullname: 'Brother032MFC-8520DN._http._tcp.local.', host: 'EVT-BW-BROTHER.local', The service port: 80, local IP address addresses: [ '192.168.0.6' ] }
  57. 57. Web Thing Model & Semantic Web http://model.webofthings.io http://gateway.webofthings.io
  58. 58. Web Thing Model Resources
  59. 59. Say Hi to the Semantic Web (of Things!) ▪ Semantic extensions [via JSON-LD] − Enhance semantics: What is that Thing really? − Schema.org ▪ Fosters: − Findability − Interoperability − Compliance ▪ More details: − http://model.webofthings.io
  60. 60. Lab 5: Hello Semantic Web of Things See also: Chapter 8 1. Experiment with the Web Thing Model in Action: Automatic UI generation - http://localhost:8484/model - chapter10-mashups/UI/ 2. Change the mDNS address of your Pi - SSH to your Pi - sudo nano /etc/hosts - domguinards-pi - sudo nano /etc/hostname - sudo reboot 3. Bonus: - download and run webofthings.js (see page 176) - implement your own mDNS server (see page 219 and mdns folder)
  61. 61. WoT Architecture: Share & Secure Chapter 9
  62. 62. A. Securing Things (over simplified) ▪ The most dangerous thing about Web Things is to bring them to the Web! (but also sort of the point :)) ▪ Problem 1: − Web Encryption ▪ Problem 2: − TLS (SSL) certificates ▪ Problem 3: − API keys (oAuth) − Authorization header − Token query param
  63. 63. B. Sharing Things: Social Web of Things http://webofthings.org/2010/02/02/sharing-in-a-web-of-things/
  64. 64. Lab 6: Sharing Things See also: Chapter 9 1. Demo of the Social WoT proxy - https://localhost:5050/login 2. Securing our server - Encryption: openssl req -sha256 -newkey rsa:4096 -keyout privateKey.pem -out caCert.pem -days 1095 -x509 - Try: https://localhost:8484/pi/ 3. Bonus: see how the API key support was added (page 260)
  65. 65. WoT Architecture: Compose Chapter 10
  66. 66. Physical Mashups Born @MIT ▪ Idea: prove to Walmart we could implement a security workflow in minutes, thanks to the Web ▪ Physical Mashups Dominique Guinard, Christian Floerkemeier, Sanjay Sarma Cloud Computing, REST and Mashups to Simplify RFID Application Development and Deployment.
  67. 67. Node-RED ▪ Mashup tool for makers ▪ Box and wires ▪ Wire your prototypes ▪ Large community support − Nodes − E.g., https://flows.nodered.or g/node/node-red-contrib -evrythng http://node-red.org
  68. 68. IFTTT: Solid Mashups for the Masses ▪ If This Then That ▪ Wizard based mashups ▪ Mashups made accesible to anyone ▪ “Secret” Maker Hook chanel − Supports REST (HTTP Webhook) http://ifttt.com
  69. 69. Lab 7: Composing Things: Node-RED & IFTTT See also: Chapter 10 1. Connect our PIR sensor to Node-RED (see page 293) - Launch the unsecure version (chapter 8) - node-red - Connect to: ws://localhost:8484/properties/pir 2. Create an IFTTT mashup that - Posts Tweets from your to the screen of the EVRYTHNG WoT Pi: ▪ http://devices.webofthings.io/pi/actuators/display/content ▪ {"value":"message"} 3. Bonus: - Implement the full Node-RED mashup (see page 292) - Try the full JS mashup of chapter 2: ex-5-mashup.html
  70. 70. http://book.webofthings.io @domguinard 39% off “Building the Web of Things” with code “39guinard” on: Get the hardware kit from:
  71. 71. Backups

×