chaosc-fetcher/cosmfetcher.js

38 lines
912 B
JavaScript

var assert = require('assert');
var restify = require('restify');
var osc = require('node-osc');
var streams = [ 91755, 70632 ];
var oscclient = new osc.Client('shell.ctdo.de',7110);
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 + ".json", function(err, req, res, obj) {
if(err == null && 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);
}
}
} else {
console.error("receive failure %s", err);
}
});
}
setInterval(fubs, 1000);