Browse Source

Separate the sensors code on the client side.

master
flabbergast 8 years ago
parent
commit
f51d9172a7
  1. 10
      public/js/sensors/TM.js
  2. 16
      public/js/socket_client.js
  3. 5
      views/index.jade
  4. 4
      views/sensors/TM.jade

10
public/js/sensors/TM.js

@ -0,0 +1,10 @@
// Temperature sensor / TM
exports.register = function (socket) {
socket.on('received-TM-temp', function (data) {
$('#TMtemp').html(data.content);
});
socket.on('received-TM-batt', function (data) {
$('#TMbatt').html(data.content);
});
}

16
public/js/socket_client.js

@ -2,6 +2,12 @@ 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) {
// update the view based with the current server settings //
// generate a random id for this newly connected user //
@ -28,13 +34,3 @@ socket.on('sent-latest-logs', function (data) {
$('#logs-content').append(elt.timestamp + ": "+elt.message+"<br />");
});
});
// Sensors:
// TM
socket.on('received-TM-temp', function (data) {
$('#TMtemp').html(data.content);
});
socket.on('received-TM-batt', function (data) {
$('#TMbatt').html(data.content);
});

5
views/index.jade

@ -17,10 +17,7 @@ block left-column
block main-column
#devices
h3.well.text-center TM / temperature sensor
br
button.btn.btn-primary.btn-large.disabled#TMtemp Temp: No value yet
button.btn.btn-info.btn-large.disabled#TMbatt Batt: No value yet
include sensors/TM.jade
block right-column

4
views/sensors/TM.jade

@ -0,0 +1,4 @@
h3.well.text-center TM / temperature sensor
br
button.btn.btn-primary.btn-large.disabled#TMtemp Temp: No value yet
button.btn.btn-info.btn-large.disabled#TMbatt Batt: No value yet
Loading…
Cancel
Save