Skip to content

zliu9/io-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IOT IO Library

A unified IO Javascript library for IOT device(Galileo/Edison), companion device(phone/tablet) and XDK.

Features

  • Arduino like API
  • Unified API for nodejs and browser
  • Standard JSON-RPC 2.0 support
  • Offload execution
  • Autogen tools for customized IO functions

PreInstall

  • This library can run correctly both on Intel dev kit https://software.intel.com/en-us/iotdevkit which contains host a machine running DevKit Live USB image and target Intel Galileo platform. This IO library can run on both of them. Below is a quick guide of how to enable nodejs on host and target.

Install yocoto on galileo

dd if=/path/to/image  of=/sd/dev/path bs=1M
  • insert SD card to galileo, then power on galileo

  • ssh login

ssh root@ip_address_for_galileo
  • check node/node-gyp/npm
    • If not in $PATH, please find it under root directory, then create symbol link for it. for example,
ln -s /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js /usr/bin/node-gyp
  • Make sure Galileo system is set correctly.

  • copy io-js to galileo, then you can jump to Installation section. But the installation is very slow on Galileo. You may want to compile the library on host machine with cross compiler

Install devkit live image on host machine

vboxmanage convertfromraw --format VMDK devkit-live-img-final.binblob ~/devkit.vmdk
  • Boot up devkit.vmdk in virtual box

  • login virtual machine

  • check node/node-gyp/npm

    • If not under $PATH, please find it under root directory, then create symbol link for it. for example,
  ln -s /opt/iot-devkit/1.5.1/yocto/sysroots/i586-poky-linux/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js /usr/bin/node-gyp
  • copy io-js to devkit, then run it followed Installation part.

Installation

npm install (if run io-js as root, please use "npm install -unsafe-perm" instead)

Examples

  • Native IO operation on IOT device
var IOLIB = (typeof require === 'function') ? require('../'): this.IOLIB;

var io = new IOLIB.IO({
  log: true
});

var led = new IOLIB.Led({
  io: io,
  pin: 13
});

led.blink();
  • RPC client which submits the IO request to IOT device.

Only needs to add RPC options to IO constructor. The code works in nodejs or browser.

var io = new IOLIB.IO({
  log: true,
  rpc: true,
  port: 2000,
  hostname: 'localhost',
});
  • Offload execution

The client can offload functions to remote server.

var IOLIB = (typeof require === 'function') ? require('..'): this.IOLIB;

var io = new IOLIB.IO({
  log: true,
  rpc: true,
  port: 2000,
  hostname: 'localhost',
});

io.offload(function(IOLIB, context) {
  var io = new IOLIB.IO({
    emu: true,
    log: true
  });
  var led = new IOLIB.Led({
    io: io,
    pin: 13
  });

  led.off();

  context.save = 1;
  return true;
});

io.offloadQuery(function(error, response) {
  console.log(JSON.stringify(response));
});

Test

We choose Buster.js to run tests in Nodejs and browser

Install buster.js

npm install -g buster

Run test

make test

Arduino Library

Go to target/device/libio