chaosc-fetcher/cosmfetcher.js

37 lines
850 B
JavaScript

var assert = require('assert');
var restify = require('restify');
var osc = require('node-osc');
var streams = [ 91755, 70632 ];
var oscclient = new osc.Client('127.0.0.1',5001);
var client = restify.createJsonClient({
url: 'http://api.cosm.com',
headers: { 'X-ApiKey': 'orKBBdLAKuKJU-RxqmZpZB6q0baSAKxBTVhKdjhUNkdyVT0g' },
version: '*'
});
var fubs = function() {
for(var i=0;i<streams.length;i++) {
getstream(streams[i]);
}
}
var getstream = function(streamId) {
client.get('/v2/feeds/' + streamId, function(err, req, res, obj) {
assert.ifError(err);
if(obj.datastreams != null) {
for(var i=0;i<obj.datastreams.length;i++) {
var foo =obj.datastreams[i];
if(foo.tags != null && foo.unit != null) {
oscclient.send('/cosm/' + obj.id + "/" + foo.id ,foo.current_value);
}
}
}
});
}
setInterval(fubs, 5000);