chaosc-fetcher/cosmfetcher.js

38 lines
912 B
JavaScript
Raw Normal View History

2012-12-17 13:58:03 +00:00
var assert = require('assert');
var restify = require('restify');
var osc = require('node-osc');
var streams = [ 91755, 70632 ];
2012-12-18 15:21:46 +00:00
var oscclient = new osc.Client('shell.ctdo.de',7110);
2012-12-17 13:58:03 +00:00
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) {
2012-12-18 15:21:46 +00:00
client.get('/v2/feeds/' + streamId + ".json", function(err, req, res, obj) {
2012-12-17 13:58:03 +00:00
2012-12-18 15:21:46 +00:00
if(err == null && obj.datastreams != null) {
2012-12-17 13:58:03 +00:00
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);
}
}
2012-12-18 15:21:46 +00:00
} else {
console.error("receive failure %s", err);
2012-12-17 13:58:03 +00:00
}
});
}
2012-12-18 15:21:46 +00:00
setInterval(fubs, 1000);