← back to the blog

How it works

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
  • APIs for dealing with complex, asynchronous Javascript, similar in concept to async.js


The most important difference of DeviceJS over other Javascript runtimes is how it executes. DeviceJS is a distributed system. Scripts/applications written for DeviceJS can execute and consequently control devices in many locations. Applications control a system, and a systemmay involve devices which reside in different locations. An application runs not a single DeviceJS runtime, but on a team of runtimes, and those may be located together on the same LAN (for instance floors in a building) or, instead, geographically apart across a WAN (buildings in different cities across the world).

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.

Script distribution
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:



    .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:

  1. In this very simple script, which turns all devices categorized as ‘light’ on, the execution kicks off from the leader, Relay A.
  2. 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.

Please Sign In to leave a comment.