Chapter 2. Hello, World Wide Web of Things
Listing 2.1. Polling for the temperature sensor
Listing 2.2. Polling and displaying a sensor reading
Listing 2.3. Connecting to a WebSocket and listening for messages
Listing 2.4. Register to a WebSocket and get real-time temperature updates
Listing 2.5. Simple HTML form to send a command to an actuator
Listing 2.6. Send an HTTP POST with JSON payload from a form
Listing 2.7. A basic device browser
Listing 2.8. Retrieve and parse device metadata using AJAX JSON calls
Chapter 3. Node.js for the Web of Things
Listing 3.1. A Hello World HTTP server in Node.js
Listing 3.2. A simple HTTP server returning JSON data
Listing 3.3. A simple package.json file
Listing 3.4. operations.js: a mathematics module in Node.js
Listing 3.5. A simple Node application using the operations module
Listing 3.6. An asynchronous call to the database
Listing 3.7. Using the request library
Listing 3.8. A mashup with asynchronous calls leading to a “callback hell”
Listing 3.9. A mashup with asynchronous calls and named callbacks
Chapter 4. Getting started with embedded systems
Listing 4.1. Modifying the Wi-Fi configuration file
Listing 4.3. Connecting to the Pi using ssh
Listing 4.4. Installing Node.js on your Pi
Listing 4.5. Configuring GitHub on the Pi and forking the project
Listing 4.6. blink.js: the Hello World of the IoT
Listing 4.7. pir.js: reading a PIR sensor using the onoff library
Chapter 5. Building networks of Things
Chapter 6. Access: Web APIs for Things
Listing 6.1. A simple HTTP request and response
Listing 6.2. Requesting an XML return payload using the Accept header
Listing 6.3. Requesting a JSON return payload using the Accept header
Listing 6.4. GET to read a resource (the temperature sensor of our Pi)
Listing 6.5. POST to create a new resource
Listing 6.6. PUT to update an existing resource (change the colors of the LEDs)
Listing 6.7. DELETE to remove an existing resource
Listing 6.8. GET request to a resource using CORS
Listing 6.9. HTML representation of the Raspberry Pi root resource
Listing 6.10. JSON representation of the “links” resource of a Raspberry Pi
Listing 6.11. Using OPTIONS to retrieve the verbs supported by a resource
Listing 6.12. Subscription via a webhook
Chapter 7. Implementing web Things
Listing 7.1. WoT server for Pi project directory structure
Listing 7.2. /resources/resources.json: JSON model of the Pi resources
Listing 7.3. /routes/sensors.js: routes for sensors
Listing 7.4. /servers/http.js: Express application
Listing 7.5. /wot-server.js: application entry point
Listing 7.6. /plugins/internal/pirPlugin.js: PIR sensor plugin
Listing 7.7. /plugins/internal/DHT22SensorPlugin.js: temperature and humidity sensor plugin
Listing 7.8. Integrating the plugins to wot-server.js
Listing 7.9. /middleware/converter.js: implementing representation middleware
Listing 7.10. Calling the next middleware in sensors.js
Listing 7.11. Adding PUT support for LEDs in /routes/actuators.js
Listing 7.12. /plugins/internal/ledsPlugin.js: LED plugin
Listing 7.13. /server/websockets.js: WebSockets server
Listing 7.14. Enabling the WebSockets server in wot-server.js
Listing 7.15. coap.js: a simple CoAP server
Listing 7.16. /plugins/external/coapPlugin.js: a simple CoAP plugin
Listing 7.17. simple-plug.js: simulated power plug that connects to EVRYTHNG via MQTT
Listing 7.18. plug-with-control.js: subscribe and handle actions pushed from the server
Listing 7.19. client/plug.html: attach a handler to the toggle button
Listing 7.20. client/plugs.html: the sendAction() function
Listing 7.21. Connecting to WebSockets and handling property updates
Chapter 8. Find: Describe and discover web Things
Listing 8.1. An mDNS message from a printer
Listing 8.2. Pseudocode for crawling the HTML representation of Things
Listing 8.3. GET {WT}: retrieve the metadata of a web Thing
Listing 8.4. GET {WT}/properties: retrieve the properties of a web Thing
Listing 8.5. Retrieve the temperature property
Listing 8.6. GET {WT}/actions: retrieve the actions supported by a web Thing
Listing 8.7. GET {WT}/model: the actions object of a web Thing model
Listing 8.8. POST {WT}/actions/ledState: turn on LED 3
Listing 8.9. GET {WT}/things: the things object of the Web Thing Model
Listing 8.10. Temperature property for Pi
Listing 8.11. /routes/routesCreator.js: root resource route
Listing 8.12. /routes/routesCreator.js: actions resources routes
Listing 8.13. /plugins/corePlugin.js: generic plugin for common features
Listing 8.14. /plugins/ledsPlugin.js: LED plugin working with the Web Thing Model
Listing 8.15. The HTML representation of the root resource with RDFa annotations
Listing 8.16. Templating HTML view in Express with RDFa tags
Listing 8.17. /middleware/converter.js: extending the converter
Listing 8.18. resources/piJsonLd.json: adding JSON-LD to our JSON model
Listing 8.19. middleware/converter.js: adding support for JSON-LD representations
Chapter 9. Share: Securing and sharing web Things
Listing 9.1. Information requested when generating a self-signed certificate
Listing 9.2. Modifying the WoT Pi server to serve HTTPS and WSS content
Listing 9.3. utils/utils.js: generate a crypto-secure API token
Listing 9.4. auth.js: authentication middleware
Listing 9.5. providers/facebook.js: a Facebook authentication strategy
Listing 9.6. config/acl.json: the access control list JSON file
Listing 9.7. Authorizing user requests: /middleware/auth.js
Listing 9.8. Proxying requests to Things: /middleware/proxy.js
Chapter 10. Compose: Physical mashups
Listing 10.1. Retrieve the JSON model of a web Thing with jQuery
Listing 10.2. The actions object of the Web Thing Model for our Pi
Listing 10.3. The HTML code of the form to create an ledState action
Listing 10.4. The generateActions() function
Listing 10.5. The PIR and LED properties of the Pi Web Thing Model
3.149.251.154