Coder Social home page Coder Social logo

devicejs-examples's Introduction

deviceJS DeviceJS Examples

Auto Increment Example

We will start a DeviceJS instance with an "ExampleDiscoverer" which will discover three "ExampleDeviceThatEmits" devices.

  1. Install DeviceJS if you have not already done so.
    This example
  2. start DeviceJS using the ExampleDeviceThatEmits.conf.json config file. In the newly cloned directory of devicejs-example, run:
    sudo [devicejs-location]/bin/devjs -vvvv --start --id test -c conf/ExampleDeviceThatEmits.conf.json
where [devicejs-location] is where DeviceJS is installed.

This will start DeviceJS with a large amount of debugging output, running under the instance name "test". You can verify the instance is running from another terminal by typing:
$ sudo ~/work/devicejs/bin/devjs --show
DeviceJS running instances:
  ID						State
  test	S
3. Now we can connect to this running instance over a shell. The shell is useful for trying out commands and debugging applications. It uses the same node.js REPL facilities just like [this](http://blog.modulus.io/absolute-beginners-guide-to-nodejs), when you type node at the prompt. To shell in you need to specify the DeviceJS instance:
$ sudo ~/work/devicejs/bin/devjs --shell --id test
2014-12-28T02:14:50.241Z  exec/runtimeIpc.js:239 (sendControlResponseCB) res is { r: 'ready',
  p: '/home/ed/work/devicejs/var/1141127-11329-p576wq_repl' }
Shell into DevJS instance /home/ed/work/devicejs/var/1141127-11329-p576wq_repl
2014-12-28T02:14:50.245Z  exec/devjsREPL.js:61 (clientConnect) path: /home/ed/work/devicejs/var/1141127-11329-p576wq_repl
2014-12-28T02:14:50.248Z  exec/devjsREPL.js:79 (Socket.) connected.
devjs[test]> 
The DeviceJS devjs[test]> prompt tells you that you are shelled into the DeviceJS instance "test". Notice if you type dev$ and *enter* the DeviceJS global selector will be dumped to the console. 4. Now we can test out the example code.
devjs[test]> dev$.selectByFacade("ExampleHappened")
The function returns an object which can act on devices with the Facade "ExampleHappened". Notice the deviceMap area - which will have three unique IDs:
     ...
     deviceMap: 
      { 'b5b1f308-cacc-4d70-8f0b-b5c437f00a20': [Object],     
        '82bad9ef-094e-416b-9493-ab7c0a73c1de': [Object],
        '55d3bb83-5ecf-4ea2-8b0c-6e6bbb12b342': [Object] },
     ...
These are the three UUID of the devices created by the ExampleDiscoverer class.
The example device class ExampleDeviceThatEmits implements a Facade ExampleHappened.
devjs[test]> dev$.selectByID("b5b1f308-cacc-4d70-8f0b-b5c437f00a20").device().special();
100  (or some other number if you have ran the example before)
This is the value 'special' for the device. 5. Now let's run a method of the ExampleDeviceThatEmits class. This method will start making the device changing the special value periodically:
devjs[test]> dev$.selectByID("b5b1f308-cacc-4d70-8f0b-b5c437f00a20").device().autoIncrementSpecial();
undefined
Now look at the *special* value change over time. Note: this value is being stored automatically to the database... so if you kill DeviceJS and restart, the value will be where it was.
devjs[test]> dev$.selectByID("b5b1f308-cacc-4d70-8f0b-b5c437f00a20").device().special()
1415
devjs[test]> dev$.selectByID("b5b1f308-cacc-4d70-8f0b-b5c437f00a20").device().special()
1415
devjs[test]> dev$.selectByID("b5b1f308-cacc-4d70-8f0b-b5c437f00a20").device().special()
1415
devjs[test]> dev$.selectByID("b5b1f308-cacc-4d70-8f0b-b5c437f00a20").device().special()
1416
devjs[test]> dev$.selectByID("b5b1f308-cacc-4d70-8f0b-b5c437f00a20").device().special()
1416
devjs[test]> dev$.selectByID("b5b1f308-cacc-4d70-8f0b-b5c437f00a20").device().special()
1416
devjs[test]> dev$.selectByID("b5b1f308-cacc-4d70-8f0b-b5c437f00a20").device().special()
1418

devicejs-examples's People

Contributors

edhemphill avatar

Stargazers

Andrew Weaver avatar Randy Mujica avatar

Watchers

Cruz Monrreal avatar James Cloos avatar Walt Giroir avatar  avatar br avatar  avatar Russ Butler avatar Travis McCollum avatar  avatar Yixin Zhang avatar Jon Martin  avatar Yash Goyal avatar  avatar Randy Mujica avatar Divya Katipamula avatar Kunal Pasricha avatar Nicolas Costa avatar  avatar

Forkers

ezhangle

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.