implemented hub registration

This commit is contained in:
Lucas 2012-12-18 16:21:46 +01:00
parent 3c0444fc5d
commit cfe4fa0bb9
2 changed files with 30 additions and 5 deletions

View File

@ -4,7 +4,7 @@ var osc = require('node-osc');
var streams = [ 91755, 70632 ];
var oscclient = new osc.Client('127.0.0.1',5001);
var oscclient = new osc.Client('shell.ctdo.de',7110);
var client = restify.createJsonClient({
url: 'http://api.cosm.com',
@ -19,18 +19,19 @@ var fubs = function() {
}
var getstream = function(streamId) {
client.get('/v2/feeds/' + streamId, function(err, req, res, obj) {
assert.ifError(err);
client.get('/v2/feeds/' + streamId + ".json", function(err, req, res, obj) {
if(obj.datastreams != null) {
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, 5000);
setInterval(fubs, 1000);

View File

@ -1,7 +1,31 @@
var readline = require('readline');
var osc = require('node-osc');
var port = process.argv.length > 2 ? process.argv[2] : '5001';
var oscClient = new osc.Client('shell.ctdo.de',7110);
var oscServer = new osc.Server(port, '0.0.0.0');
oscServer.on("message", function (msg, rinfo) {
console.log("message: " + msg);
});
oscClient.send('/subscribe',"distinto.lp-server.net:"+port);
var rl = readline.createInterface(process.stdin,process.stdout,null);
rl.on('line', function(cmd) {
var sepIndex = cmd.indexOf(":");
if(sepIndex > 0) {
var path = cmd.substr(0, sepIndex);
var val = cmd.substr(sepIndex+1);
console.log("writing: %s with %s", path, val);
oscClient.send(path, val);
}
});
rl.on('close', function(cmd) {
console.log("bye bye");
oscClient.send('/unsubscribe',"distinto.lp-server.net:"+port);
process.exit(0);
});