Beyond this DeviceJS adds a number of capabilities:
- A realtime, distributed JSON database, which updates live directly into the DeviceJS runtime.
- Object based API, roughly based of base2 and Prototype
- Service hooks to native device drivers for protocols like: 6loWPAN, Z-Wave and ZigBee
- A Catalog which allows devices of all kinds to be categorized and cross-referenced in a variety of ways
From the application programmer’s view point, the physical location of the runtimes does not have to be a factor – although it can be considered if desired. This also means that if devices jump, or move between locations, an application does not need to be modified. An example might be a mobile sensor which moves from one location to another.
When an application is started the same script is sent to every DeviceJS runtime in theteam. It’s how each runtime executes this script that makes the difference. Which ever DeviceJS runtime that kicked off the script is considered the leader. The leader leads execution down the script. Let’s take an example:
dev$ .byTag("light")// select devices tagged as a 'light' // here the lead relay signals the downline relays.setOn();// Relay B & C turns lights on...
There are two steps:
- In this very simple script, which turns all devices categorized as ‘light’ on, the execution kicks off from the leader, Relay A.
- Relay A has no lights, so it does nothing locally. It informs Relays B & C that the script is kicked off. They have the same script and execute it, turning their own local lights on.