Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 43 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
var HumixSense = require('humix-sense');

var config = {
"moduleName" : "sample",
"commands" : ["command1", "command2"],
"events" : ["event1", "event2"],
"moduleName" : "temporature",
"commands" : [ "start"],
"events" : ["temporature"],
"moduleEvents":["higher"],
"log" : [

{
file : './humix-sample-module.log',
level : 'info'
}
],
"debug" : true
"debug" : true,
"natsIp": ""//If empty, means your humix-sense is in the localhost, if not you can fill this p
};

var humix = new HumixSense(config);
var hsm;

var basedTemporature=20;
var tempBroadCast;
humix.on('connection', function(humixSensorModule){
hsm = humixSensorModule;
var log = hsm.getLogger();
Expand All @@ -24,26 +28,43 @@ humix.on('connection', function(humixSensorModule){
// When finished, the result is passed back to humix-think via
// the 'done' callback.

hsm.on("command1", function (data, done) {

console.log('do something with command1. data:'+data);
done('i am done');

})



hsm.on("command2", function (data) {
log.info('do something with command2. data:'+data);
})
hsm.onModuleEvent("higher", function (data) {

});

if(data){


basedTemporature+=parseInt(data);

}
else
basedTemporature+=1;
});


hsm.on("start",function(data){

tempBroadCast=setInterval(function () {



// publish a dummy data in every 5 seconds.
setInterval(function () {
if (hsm) {
var temp = Math.floor(Math.random() * 5 + basedTemporature);
var data = { "d": { "name": "temporature", "temperature": temp } };

if (hsm) {
var data = {'a':'b'}
hsm.event('event1', data);
}
console.log('send data : ' + JSON.stringify(data));
hsm.event('temporature', data);
}

}, 1000);
});

hsm.moduleCommand('another module name','command','data');
hsm.moduleEvent('moduleEvent name','data');


});

}, 5000);