smartbase
smartbase is a base board for you to create a smartobject with plugins.
1. Overview
This module helps developers integrate plugins into a smartobject. smartbase is like a carrier and plugins are various peripherals such as a LED, a temperature sensor, a switch to be put into the smartobject. In addition, **smartbase ** makes the smartobject listenable as well.
2. Installation
$ npm install smartbase --save
3. Basic Usage
var SmartObject = require('smartobject'),
smartbase = require('smartbase');
var ledPlugin = require('linkit-smart-7688-led');
var so = new SmartObject();
so = smartbase(so, {
led0: ledPlugin({ iid: 0, pin: 10, active: 'high' }),
led1: ledPlugin({ iid: 1, pin: 11, active: 'low' })
});
so.onChange('lightCtrl/0/onOff', function (cVal, pVal) {
console.log('A listener to this resource');
console.log(cVal);
console.log(pVal);
});
so.onChange('temperature/0/sensorValue', function (cVal, pVal) {
console.log('Another listener to this resource');
});
so.write('temperature', 0, 'sensorValue', 80, function (err, data) {
if (err)
console.log(err);
});