From ee8aba9b871d30948400911a71d792ac740855d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Thu, 31 Jan 2013 00:09:00 +0100 Subject: [PATCH] cleanup added cosmfetcher function into this module, so we can merge --- .idea/jsLibraryMappings.xml | 7 +++ app.js | 36 +++++++++++---- cosm.js | 85 ++++++++++++++++++++++++++++++++++++ cosmdisplay.iml | 1 + gedanken.txt | 5 +++ osc.js | 20 +++++++++ package.json | 5 ++- public/stylesheets/style.css | 10 ++--- routes/index.js | 13 ------ routes/user.js | 12 ----- views/index.jade | 15 +++++-- views/layout.jade | 2 + 12 files changed, 168 insertions(+), 43 deletions(-) create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 cosm.js create mode 100644 osc.js delete mode 100644 routes/index.js delete mode 100644 routes/user.js diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..9ab233f --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/app.js b/app.js index aa8f01c..93fcbd1 100644 --- a/app.js +++ b/app.js @@ -1,15 +1,19 @@ var express = require('express') - , routes = require('./routes') - , http = require('http') - , path = require('path'); + , app = express() + , server = require('http').createServer(app) + , path = require('path') + , io = require('socket.io').listen(server) + , cosm = require('./cosm.js') + , osc = require('./osc.js'); + +var cosmClient = new cosm([91755, 70632], 'orKBBdLAKuKJU-RxqmZpZB6q0baSAKxBTVhKdjhUNkdyVT0g'); +var oscClient = new osc('localhost', 8000); -var app = express(); app.configure(function () { app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); - app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); @@ -22,9 +26,25 @@ app.configure('development', function () { app.locals.pretty = true; }); -app.get('/', routes.index); -app.get("/blafasel", routes.blafasel); +app.get("/", function(req, res) { + res.render('index', { title: 'COSM display' }); +}); -http.createServer(app).listen(app.get('port'), function () { +io.sockets.on('connection', function (socket) { + socket.emit('news', { hello: 'world' }); + socket.on('my other event', function (data) { + console.log(data); + }); +}); + +server.listen(app.get('port'), function () { console.log("Express server listening on port " + app.get('port')); }); + + +// this event is send by cosm client when new data arrives (just when values changed) +cosmClient.on('changedvalue', function(object) { + console.log("changedvalue: " + JSON.stringify(object)); + + oscClient.send('/cosm/' + object.stream + "/" + object.displayname, object.value); +}); \ No newline at end of file diff --git a/cosm.js b/cosm.js new file mode 100644 index 0000000..6ac919d --- /dev/null +++ b/cosm.js @@ -0,0 +1,85 @@ +var restify = require('restify') + , util = require('util') + , EventEmitter = require('events').EventEmitter; + +var COSM = function(streams, key) { + var self = this; + + var streams = streams; + var interval = 1000; + + var jsonClient = restify.createJsonClient({ + url: 'http://api.cosm.com', + headers: { 'X-ApiKey': key }, + version:'*' + }); + + var recentvalues = {}; + + setInterval(function() { + + for(var i=0; i + diff --git a/gedanken.txt b/gedanken.txt index c4d0acd..52024cd 100644 --- a/gedanken.txt +++ b/gedanken.txt @@ -11,3 +11,8 @@ in jeder Spalte die Infos von einem Stream Dann bis zu drei? streams als Graph oder Zahl zeigen ->konfigurierbar? - Karte ganz unten + + +Anstelle der Graphen lieber die Anzeige als Zahlenwerte +Zahlen mit aktuellem Wert blinken dann auf, +Überschrift dann mit ID und Tags \ No newline at end of file diff --git a/osc.js b/osc.js new file mode 100644 index 0000000..44a964f --- /dev/null +++ b/osc.js @@ -0,0 +1,20 @@ +var nodeosc = require('node-osc'); + +var osc = function(host, port) { + var self = this; + + var hubAddress = host || '192.168.23.43'; + var hubPort = port || 7110; + + console.log("using " + hubAddress + ":" + hubPort + " as hub"); + self._client = new nodeosc.Client(hubAddress, hubPort); + +} + +osc.prototype.send = function(path, value) { + var self = this; + self._client.send(path, value) +} + + +module.exports = osc; \ No newline at end of file diff --git a/package.json b/package.json index 3a04650..8b71a9a 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,9 @@ "dependencies": { "express": "3.1.0", "jade": "*", - "cosm": "*" + "cosm": "*", + "socket.io": "*", + "restify": "*", + "node-osc": "*" } } \ No newline at end of file diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 369ca11..b9cdcd2 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -3,7 +3,7 @@ html, body { margin: 0; font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; background-color: black; - color: white; + color: #ffcbb0; height: 100%; } @@ -34,17 +34,17 @@ a { .kasten { padding: 10px; - margin: 5px; + margin: 24px; height: 90%; - background-color: #333; - border: 1px solid #e5e5e5; + background-color: #444; + border: 1px solid #7b7b7b; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; } div.mapbox { - width: 200px; + width: 270px; height: 150px; margin-top: 20px; } diff --git a/routes/index.js b/routes/index.js deleted file mode 100644 index d3b2f0f..0000000 --- a/routes/index.js +++ /dev/null @@ -1,13 +0,0 @@ - -/* - * GET home page. - */ - -exports.index = function(req, res){ - res.render('index', { title: 'Express' }); -}; - - -exports.blafasel = function(req, res){ - res.render('index', { title: 'Blafasel' }); -}; \ No newline at end of file diff --git a/routes/user.js b/routes/user.js deleted file mode 100644 index 163c311..0000000 --- a/routes/user.js +++ /dev/null @@ -1,12 +0,0 @@ - -/* - * GET users listing. - */ - -exports.list = function(req, res){ - res.send("respond with a resource"); -}; - -//exports.index2 = function(req, res){ -// res.render('index', { title: 'Express' }); -//}; \ No newline at end of file diff --git a/views/index.jade b/views/index.jade index 01663ec..8c7704d 100644 --- a/views/index.jade +++ b/views/index.jade @@ -1,10 +1,13 @@ extends layout +block head + script(src="/socket.io/socket.io.js") + block content div.container div.row - for nr in [ 1,2,3,4,5 ] + for nr in [ 1,2,3] div.cell div.kasten h3 Freakduino + Netrad SBM-20 @@ -27,7 +30,7 @@ block content div.mapbox(id="map#{nr}") - img(src="https://api.cosm.com/v2/feeds/64590/datastreams/microsievertsperhour.png?width=200&height=100&colour=%23f15a24&duration=5minutes&show_axis_labels=true&detailed_grid=true&scale=auto&timezone=Berlin") + //img(src="https://api.cosm.com/v2/feeds/64590/datastreams/microsievertsperhour.png?width=200&height=100&colour=%23f15a24&duration=5minutes&show_axis_labels=true&detailed_grid=true&scale=auto&timezone=Berlin") @@ -48,7 +51,11 @@ block content loadMap(document.getElementById("map1"), -34.397, 150.644); loadMap(document.getElementById("map2"), -34.397, 150.644); loadMap(document.getElementById("map3"), -34.397, 150.644); - loadMap(document.getElementById("map4"), -34.397, 150.644); - loadMap(document.getElementById("map5"), -34.397, 150.644); + }); + + var socket = io.connect('http://localhost'); + socket.on('news', function (data) { + console.log(data); + socket.emit('my other event', { my: 'data' }); }); diff --git a/views/layout.jade b/views/layout.jade index 49625d3..4c24d71 100644 --- a/views/layout.jade +++ b/views/layout.jade @@ -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") + block head + body block content