added testsender, extended cosmfetcher, bugfix to send float if value is number, instead of sending number strings
This commit is contained in:
parent
cfe4fa0bb9
commit
02410bc483
|
@ -1 +1,3 @@
|
|||
node_modules/
|
||||
.idea/
|
||||
*.iml
|
|
@ -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<streams.length;i++) {
|
||||
getstream(streams[i]);
|
||||
}
|
||||
}
|
||||
var recentvalues = {};
|
||||
|
||||
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);
|
||||
var dataStream = obj.datastreams[i];
|
||||
if(dataStream.id != null) {
|
||||
var streamName = dataStream.id;
|
||||
if(streamName.length < 2 && dataStream.tags.length > 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<streams.length;i++) {
|
||||
getstream(streams[i]);
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
|
||||
function isNumber(value) {
|
||||
if ((undefined === value) || (null === value)) {
|
||||
return false;
|
||||
}
|
||||
if (typeof value == 'number') {
|
||||
return true;
|
||||
}
|
||||
return !isNaN(value - 0);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
Anzeige vom Hub mit Darstellung woher die Daten kommen "windrad japan"
|
|
@ -1,15 +1,18 @@
|
|||
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');
|
||||
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);
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue