fx for changed values, using correct port for chaosc, feed whitelist per stream

This commit is contained in:
Stefan Kögl 2013-02-19 02:48:52 +01:00
parent a7119749fc
commit 47f44234ec
5 changed files with 43 additions and 18 deletions

14
app.js
View File

@ -6,10 +6,14 @@ var express = require('express')
, cosm = require('./cosm.js')
, osc = require('./osc.js');
var cosmStreams = [97325, 84896, 84388, 70632 ];
var cosmStreams = [84896, 84388, 70632];
var cosmFeeds = {84896 : ["003", "004", "006"],
84388 : ["Furdo", "Halo", "Gyerekszoba"],
70632 : ["househumid4", "humidity", "motion4"]};
var cosmClient = new cosm(cosmStreams, 'orKBBdLAKuKJU-RxqmZpZB6q0baSAKxBTVhKdjhUNkdyVT0g');
var oscClient = new osc('localhost', 8000);
var oscClient = new osc('localhost', 7110);
function logErrors(err, req, res, next) {
console.error(err.stack);
@ -69,7 +73,8 @@ server.listen(app.get('port'), function () {
cosmClient.on('updatevalue', function(object) {
console.log("updatevalue: " + JSON.stringify(object));
oscClient.send('/cosm/' + object.stream + "/" + object.displayname, object.value);
io.sockets.emit('updatevalue', object);
if (cosmFeeds.hasOwnProperty(object.stream) && cosmFeeds[object.stream].indexOf(object.displayname) != -1)
io.sockets.emit('updatevalue', object);
});
@ -77,5 +82,6 @@ cosmClient.on('updatevalue', function(object) {
cosmClient.on('changedvalue', function(object) {
console.log("changedvalue: " + JSON.stringify(object));
oscClient.send('/cosm/' + object.stream + "/" + object.displayname, object.value);
io.sockets.emit('changedvalue', object);
if (cosmFeeds.hasOwnProperty(object.stream) && cosmFeeds[object.stream].indexOf(object.displayname) != -1)
io.sockets.emit('changedvalue', object);
});

View File

@ -51,8 +51,9 @@ function Cosm(streams, key) {
var address = obj.id + ":" + dataStream.id;
console.log(recentvalues);
if(recentvalues[address] != currentValue) {
console.log(recentvalues[address] + " " + currentValue);
console.log(typeof(recentvalues[address]) + " " + typeof(currentValue));
if(recentvalues[address] !== currentValue) {
self.emit('changedvalue', object);
}
else

View File

@ -34,8 +34,13 @@ a {
.kasten {
padding: 10px;
margin: 10px;
height: 90%;
margin: 5px;
/*margin-right: 10px;
margin-right: 10px;
margin-right: 10px;*/
/* margin-bottom: 10px; */
width:256px;
height: 98%;
background-color: #444;
border: 1px solid #7b7b7b;
-webkit-border-radius: 5px;
@ -45,11 +50,12 @@ a {
div.mapbox {
height: 150px;
width:270px;
width:236px;
margin-left: auto;
margin-right: auto;
/* margin-top:20px; */
position:absolute;
bottom:10%;
bottom:20px;
}
.kasten img {

View File

@ -31,10 +31,6 @@ block content
div.mapbox(id="map#{nr}") --
script(type="text/javascript",src="http://maps.googleapis.com/maps/api/js?sensor=false&key=AIzaSyDZ5gUZumNEZOHyRLs4HWJEJ-mDeEkWInU")
script(type="text/javascript")
//var streams;
//var stream;
@ -82,23 +78,37 @@ block content
});
function add_data(data) {
console.log("changedvalue");
console.log("add_data");
console.dir(data);
var row = $('tr#' + data.feed).html();
if (row === undefined) {
var tmp = '<tr id="' + data.feed + '"><td>' + data.displayname + "</td><td>" + data.value + "</td></tr>";
var tmp = '<tr id="' + data.feed + '"><td>' + data.displayname + '</td><td class="value">' + data.value + "</td></tr>";
console.log("new tmp: " + tmp);
$("div#" + data.stream + " table > tbody").append(tmp);
}
};
function update_data(data) {
console.log("update_data");
console.dir(data);
var row = $('tr#' + data.feed).html();
if (row === undefined) {
var tmp = '<tr id="' + data.feed + '"><td>' + data.displayname + '</td><td class="value">' + data.value + "</td></tr>";
console.log("new tmp: " + tmp);
$("div#" + data.stream + " table > tbody").append(tmp);
}
else {
var t = 'div#' + data.stream + ' table > tbody tr#' + data.feed;
var tmp = "<td>" + data.displayname + "</td><td>" + data.value + "</td>";
var tmp = "<td>" + data.displayname + '</td><td class="value">' + data.value + "</td>";
console.log("existing tmp: " + tmp);
$(t).html(tmp);
var f = $("tr#" + data.feed + " .value");
console.dir(f);
f.effect("pulsate", { times:3 }, 2000);
}
};
socket.on('changedvalue', add_data);
socket.on('changedvalue', update_data);
socket.on('updatevalue', add_data);

View File

@ -5,6 +5,8 @@ html
meta(name='viewport', content='width=device-width, initial-scale=1.0')
link(rel='stylesheet', href='/stylesheets/style.css')
script(type="text/javascript",src="/javascripts/jquery-1.9.0.min.js")
script(type="text/javascript",src="/javascripts/jquery-ui-1.10.1.custom.min.js")
script(type="text/javascript",src="http://maps.googleapis.com/maps/api/js?sensor=false&key=AIzaSyDZ5gUZumNEZOHyRLs4HWJEJ-mDeEkWInU")
block head
body