Browse Source

Fix client-side sensor code separation.

master
flabbergast 8 years ago
committed by js
parent
commit
e921280966
  1. 13
      public/js/sensors/TM.js
  2. 12
      public/js/socket_client.js
  3. 5
      views/index.jade

13
public/js/sensors/TM.js

@ -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);
});
}
}

12
public/js/socket_client.js

@ -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) {

5
views/index.jade

@ -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…
Cancel
Save