From 02410bc4835daab3da304fbb705249b93a988f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Tue, 15 Jan 2013 22:12:00 +0100 Subject: [PATCH] added testsender, extended cosmfetcher, bugfix to send float if value is number, instead of sending number strings --- .gitignore | 2 ++ cosmfetcher.js | 57 +++++++++++++++++++++++++++++++++++--------------- ideen.txt | 2 ++ oscreceiver.js | 26 +++++++++++++++++------ testsender.js | 20 ++++++++++++++++++ 5 files changed, 84 insertions(+), 23 deletions(-) create mode 100644 ideen.txt create mode 100644 testsender.js diff --git a/.gitignore b/.gitignore index c2658d7..e47ca26 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules/ +.idea/ +*.iml \ No newline at end of file diff --git a/cosmfetcher.js b/cosmfetcher.js index 5d81c38..e5730b3 100644 --- a/cosmfetcher.js +++ b/cosmfetcher.js @@ -1,31 +1,39 @@ -var assert = require('assert'); -var restify = require('restify'); -var osc = require('node-osc'); +var assert = require('assert'), + restify = require('restify'), + osc = require('node-osc'); -var streams = [ 91755, 70632 ]; +var hubAddress = '192.168.23.43', hubPort = 7110; +var oscClient = new osc.Client(hubAddress, hubPort); -var oscclient = new osc.Client('shell.ctdo.de',7110); +var streams = [ 91755, 70632, 53146, 45582 ]; var client = restify.createJsonClient({ - url: 'http://api.cosm.com', - headers: { 'X-ApiKey': 'orKBBdLAKuKJU-RxqmZpZB6q0baSAKxBTVhKdjhUNkdyVT0g' }, - version: '*' + url: 'http://api.cosm.com', headers: {'X-ApiKey':'orKBBdLAKuKJU-RxqmZpZB6q0baSAKxBTVhKdjhUNkdyVT0g'},version:'*' }); -var fubs = function() { - for(var i=0;i 0) streamName = dataStream.tags[0] + streamName; + + var address = '/cosm/' + obj.id + "/" + streamName; + var currentValue = dataStream.current_value; + + + if(isNumber(currentValue)) currentValue = parseFloat(currentValue); + + if(recentvalues[address] != currentValue) { + oscClient.send(address, currentValue); + } + + recentvalues[address] = currentValue; } } } else { @@ -34,4 +42,19 @@ var getstream = function(streamId) { }); } -setInterval(fubs, 1000); +setInterval(function() { + for(var i=0;i 2 ? process.argv[2] : '5001'; -var oscClient = new osc.Client('shell.ctdo.de',7110); -var oscServer = new osc.Server(port, '0.0.0.0'); +var listenPort = 8000; +var hubAddress = '192.168.23.43'; +var hubPort = 7110; + +var oscClient = new osc.Client(hubAddress, hubPort); +var oscServer = new osc.Server(listenPort, '0.0.0.0'); oscServer.on("message", function (msg, rinfo) { - console.log("message: " + msg); + console.log("message: " + msg); }); -oscClient.send('/subscribe',"distinto.lp-server.net:"+port); +oscClient.send('/subscribe','192.168.23.102', listenPort, "sekret"); var rl = readline.createInterface(process.stdin,process.stdout,null); @@ -18,6 +21,7 @@ rl.on('line', function(cmd) { if(sepIndex > 0) { var path = cmd.substr(0, sepIndex); var val = cmd.substr(sepIndex+1); + if(isNumber(val)) parseFloat(val); console.log("writing: %s with %s", path, val); oscClient.send(path, val); } @@ -25,7 +29,17 @@ rl.on('line', function(cmd) { rl.on('close', function(cmd) { console.log("bye bye"); - oscClient.send('/unsubscribe',"distinto.lp-server.net:"+port); + oscClient.send('/unsubscribe', hubAddress, listenPort); process.exit(0); }); + +function isNumber(value) { + if ((undefined === value) || (null === value)) { + return false; + } + if (typeof value == 'number') { + return true; + } + return !isNaN(value - 0); +} \ No newline at end of file diff --git a/testsender.js b/testsender.js new file mode 100644 index 0000000..199b162 --- /dev/null +++ b/testsender.js @@ -0,0 +1,20 @@ +var osc = require('node-osc'); + +var hubAddress = '192.168.23.43'; +var hubPort = 7110; + +var oscClient = new osc.Client(hubAddress, hubPort); + +var rate = 0.0; + +function fubs() { + oscClient.send('/snd/rate',rate); + console.log("rate = " + rate); + rate+=0.01; + if(rate >=1) rate = 0.0; + +} + +setInterval(fubs, 200); + +