sample_pir-lights_rgb

Dependencies:   ChainableLED

Committer:
iv123
Date:
Sun Jun 18 10:14:56 2017 +0000
Revision:
0:7a352727249b
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iv123 0:7a352727249b 1 # Connected Lights Web Application
iv123 0:7a352727249b 2
iv123 0:7a352727249b 3 This is the web application that goes with the article [Building an internet connected lighting system](https://docs.mbed.com/docs/building-an-internet-connected-lighting-system/en/latest/), in which we build a lighting system on top of the ARM mbed IoT Device Platform.
iv123 0:7a352727249b 4
iv123 0:7a352727249b 5 To get started, install a recent version of [node.js](https://nodejs.org/en/). Then:
iv123 0:7a352727249b 6
iv123 0:7a352727249b 7 ```bash
iv123 0:7a352727249b 8 $ npm install
iv123 0:7a352727249b 9 $ TOKEN=xxx node main.js # xxx = mbed Cloud Access Token
iv123 0:7a352727249b 10 ```
iv123 0:7a352727249b 11
iv123 0:7a352727249b 12 Now go to http://localhost:5265 to see your connected lights.
iv123 0:7a352727249b 13
iv123 0:7a352727249b 14 ## Architecture
iv123 0:7a352727249b 15
iv123 0:7a352727249b 16 This application is built on top of [Konekuta](https://github.com/armmbed/konekuta), a node.js library to quickly build dynamic web applications on top of mbed Cloud.
iv123 0:7a352727249b 17
iv123 0:7a352727249b 18 The server side source code is relatively compact. In [main.js](main.js) we declare which devices we want to find (`deviceType`) and which resources on these devices to retrieve, which resources to subscribe to, and which resources can be updated. We also tell Konekuta how to map the data from mbed Cloud into a view (used to render the web application). Konekuta will now set up a socket connection to every connected client, sync changes from one client to another, store data in mbed Cloud, and will notify clients when a device changes it status (either update the `/pir/0/count`, disappears or comes back online).
iv123 0:7a352727249b 19
iv123 0:7a352727249b 20 On the client we'll connect to the server, and subscribe to events from the server. We then update the UI based on these updates. This ensures that every connected client will always see the same UI. Changing the color of a light on your desktop will also update the color on your phone.
iv123 0:7a352727249b 21
iv123 0:7a352727249b 22 To update data we can send events to the server over the same socket. The server will send the data back to Connector and tell the sender whether the action succeeded. If the action succeeded the server will also inform all other clients.
iv123 0:7a352727249b 23
iv123 0:7a352727249b 24 Konekuta also has logic for handling disconnects, going from offline to online, and other features to synchronize data.