Fix client-side sensor code separation.
This commit is contained in:
parent
13baef9662
commit
e921280966
3 changed files with 22 additions and 8 deletions
|
@ -1,10 +1,19 @@
|
|||
// Temperature sensor / TM
|
||||
|
||||
exports.register = function (socket) {
|
||||
/* This is the code that updates the webpage when
|
||||
* new data appears on the socket.
|
||||
* It gets loaded with the webpage, hopefully after
|
||||
* the socket has been initalised.
|
||||
*
|
||||
* A document.ready() function that will bind functions to (say)
|
||||
* some button clicks can also go here (sensor specific!).
|
||||
*/
|
||||
|
||||
if( socket ){
|
||||
socket.on('received-TM-temp', function (data) {
|
||||
$('#TMtemp').html(data.content);
|
||||
});
|
||||
socket.on('received-TM-batt', function (data) {
|
||||
$('#TMbatt').html(data.content);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* socket_client.js
|
||||
* The code that initalises the socket on the client side
|
||||
* and performs initial communication with the server.
|
||||
*/
|
||||
|
||||
var socket = io.connect('/');
|
||||
var socket_connected = false;
|
||||
var autoMode;
|
||||
|
||||
var TMsensor = require('./sensors/TM.js')
|
||||
|
||||
// Sensors: register on the socket
|
||||
TMsensor.register(socket);
|
||||
|
||||
// Initialising the connection
|
||||
socket.on('connected-to-server', function (data) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
extends layout
|
||||
|
||||
//- include new devices in the 'main-column' and 'scripts' blocks
|
||||
|
||||
block top
|
||||
.navbar
|
||||
.navbar-inner
|
||||
|
@ -17,6 +19,7 @@ block left-column
|
|||
|
||||
block main-column
|
||||
#devices
|
||||
//- INCLUDE sensors (the displayed blocks)
|
||||
include sensors/TM.jade
|
||||
|
||||
|
||||
|
@ -38,3 +41,5 @@ block scripts
|
|||
script(src='/js/index.js')
|
||||
script(src="/socket.io/socket.io.js")
|
||||
script(src='/js/socket_client.js')
|
||||
//- INCLUDE sensors (the code that updates the page with new data)
|
||||
script(src='/js/sensors/TM.js')
|
||||
|
|
Loading…
Reference in a new issue