thing-node
A Kii enabled IoT library for node.js capable Things
Installation
$ npm install --save thing-node
Usage
For detailed info see demos
and test/index.js
var thingNode = require('thing-node');
const vendorThingId = 'MyThing';
const thingPassword = 'ThingPassword';
const thingType = 'ThingType';
const thingRegistrationFields = {
_vendorThingID: vendorThingId,
_password: thingPassword,
_thingType: thingType,
_vendor: 'ThingManufacturer'
};
// Initialize with Kii app info (get it at developer.kii.com)
thingNode.initialize(<APP_ID>, <APP_KEY>, <APP_SITE>);
// Register Thing in cloud
thingNode.registerOrLoadThing(thingRegistrationFields, function (error, thing) {
if (!error) {
thingId = thing.getThingID();
thingAccessToken = thing.getAccessToken();
thingNode.onboardThing(vendorThingId, thingPassword, thingType, thingAccessToken, function (error, onboardInfo) {
if(!error) {
var state = {
'power': true,
'temperature': 33
};
thingNode.registerThingState(thingId, state, thingAccessToken, function (error, stateRegInfo) {
if (!error)
console.log('Thing-IF state registration successful: ' + stateRegInfo);
else
console.log('Error registering Thing state: ' + error);
});
} else {
console.log('Error onboarding Thing: ' + error);
}
});
} else {
console.log('Error loading or registering Thing: ' + error);
}
});
TODO
- Provide Promises besides a callback based API
- Provide API documentation (JSDoc)
Development
- Test:
npm test
orgulp
- Node dev version:
4.2.1
- Npm dev version:
3.5.2
- Node deploy version:
0.12.17
- Npm deploy version:
2.15.1
Logging
How to see what's happening on the cloud side (Kii log):
node ../kii-cli/bin/kii-logs.js -t --site us --app-id <KII_APP_ID> --app-key <KII_APP_KEY> --client-id <KII_CLIENT_ID> --client-secret <KII_CLIENT_SECRET>
License
MIT © German Viscuso