added fetcher app

This commit is contained in:
Lucas Pleß 2012-12-17 14:58:03 +01:00
commit 3c0444fc5d
5 changed files with 66 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

36
cosmfetcher.js Normal file
View File

@ -0,0 +1,36 @@
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);

7
oscreceiver.js Normal file
View File

@ -0,0 +1,7 @@
var osc = require('node-osc');
var port = process.argv.length > 2 ? process.argv[2] : '5001';
var oscServer = new osc.Server(port, '0.0.0.0');
oscServer.on("message", function (msg, rinfo) {
console.log("message: " + msg);
});

6
readme Normal file
View File

@ -0,0 +1,6 @@
install nodejs and npm
install node packages with npm
npm install node-osc restify

16
testhub.js Normal file
View File

@ -0,0 +1,16 @@
var osc = require('node-osc');
var port = process.argv.length > 2 ? process.argv[2] : '5001';
var sender1 = new osc.Client('127.0.0.1', 6001);
var sender2 = new osc.Client('127.0.0.1', 6002);
var sender3 = new osc.Client('127.0.0.1', 6003);
var sender4 = new osc.Client('127.0.0.1', 6004);
var receiver = new osc.Server(port, '0.0.0.0');
receiver.on("message", function (msg, rinfo) {
sender1.send(msg[0],msg[1]);
sender2.send(msg[0],msg[1]);
sender3.send(msg[0],msg[1]);
sender4.send(msg[0],msg[1]);
});