LowPowerLab Forum

Software support => Pi Gateway => Topic started by: rlramirez77 on September 23, 2016, 10:27:39 AM

Title: Use of initial-state library to forward messages
Post by: rlramirez77 on September 23, 2016, 10:27:39 AM
Hi, I would like to use the Initial State NodeJS library with the Pi Gateway. It appears that one obvious place would be within gateway.js, but I actually want to code it so that specific mote nodes have their data forwarded. I'd be using the bucket.push method as shown here: https://github.com/InitialState/node-initial-state

Any suggestions?

Russ
Title: Re: Use of initial-state library
Post by: Felix on September 23, 2016, 11:58:57 AM
If you need data forwarded from certain nodes, you can setup some data-events in metrics.js (https://github.com/LowPowerLab/RaspberryPi-Gateway/blob/master/metrics.js), then activate those events for the nodes you want. The alert events already included are good examples. You'd have to include your new library in metrics.js (and maybe in gateway.js - try it without first).
Title: Re: Use of initial-state library
Post by: rlramirez77 on September 26, 2016, 01:49:56 PM
Got that working Felix, thanks. It turned out to be much easier than I was originally thinking it would be. I essentially added an event for temperature like so:


  temperatureAlert : { label:'Temperature : Alert', icon:'comment', descr:'Send Initial-State data', serverExecute:function(node) { if (node.metrics['F'] && (Date.now() - new Date(node.metrics['F'].updated).getTime() < 2000))
  {
    var IS = require('initial-state');
    var bucket = IS.bucket('myBucketKey', 'myAccessKey');
    // Push event to initial state
    bucket.push('Temperature', node.metrics['F'].value, Date.now());
  }; } },


and this allowed me to catch the events up at Initial-State every 2 mins.

Russ