Use of initial-state library to forward messages

Started by rlramirez77, September 23, 2016, 10:27:39 AM

rlramirez77

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

Felix

If you need data forwarded from certain nodes, you can setup some data-events in 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).

rlramirez77

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