Browse Source

Add a basic temp sensor display.

master
flabbergast 9 years ago
parent
commit
cd0b316168
  1. 10
      TODO.md
  2. 5
      modules/llap_helper.js
  3. 32
      modules/socket_server.js
  4. 2
      public/css/style.styl
  5. 10
      public/js/socket_client.js
  6. 5
      views/index.jade
  7. 2
      views/layout.jade

10
TODO.md

@ -0,0 +1,10 @@
## Immediate ##
### LLAP sensor message handling ###
- remember timestamp (when was the last message received)
- allow for "disabling" the display/processing the messages?
- refactor variables: make one object for one sensor
- do something about STARTED/AWAKE/SLEEPING messages?
## Eventually ##
- Implement Log section (last couple of things pulled when connected, then each time a message comes, add it to the log locally)
- Phone-friendly version of the site

5
modules/llap_helper.js

@ -17,6 +17,11 @@ exports.deviceName = function(msg) {
return msg.substring(1,3);
}
exports.message = function(msg,filler) {
if(!filler) { var filler = '-'; }
return msg.substring(3,12).replace(/-*$/,"");
}
exports.isValid = function(msg) {
return msg.length == 12 &&
msg.charAt(0) == 'a' &&

32
modules/socket_server.js

@ -3,10 +3,8 @@ var serport = require('./serial_node');
var lhelper = require('./llap_helper');
var logger = require('./log_backend');
var activeUser;
/*
TODO - need to store the current animation & autoMode setting on the server
*/
var TMtemp = "??";
var TMbatt = "??";
exports.init = function(io){
@ -41,8 +39,27 @@ exports.onDataOverSerial = function(data){
if (lhelper.isValid(msg)) {
// log the message
logger.log_message(msg);
// let all the clients know about the message
sockets.emit('received-llap-msg', { content: msg });
// process the message if "known"
var message = lhelper.message(msg);
switch (lhelper.deviceName(msg)) {
case "TM":
if(message.substring(0,4) == "TMPA") {
TMtemp = message.substring(4,9);
sockets.emit('received-TM-temp',
{ content: ("Temp: "+TMtemp+" ºC")});
}
if(message.substring(0,4) == "BATT") {
TMbatt = message.substring(4,9);
sockets.emit('received-TM-batt',
{ content: ("Batt: "+TMbatt+" V")});
}
break;
default:
// let all the clients know about the message|
sockets.emit('received-llap-msg', { content: msg });
break;
}
} else {
// message not valid
}
@ -51,5 +68,8 @@ exports.onDataOverSerial = function(data){
var onUserConnected = function(socket)
{
serport.writeNumber(socket.user.id);
socket.emit('received-TM-temp', { content: ("Temp: "+TMtemp+" ºC") });
socket.emit('received-TM-batt', { content: ("Batt: "+TMbatt+" V") });
// here comes socket.on('something-happens', ...)
}

2
public/css/style.styl

@ -32,4 +32,4 @@ footer
.footer p
margin-bottom 0
color #999
color #999

10
public/js/socket_client.js

@ -18,4 +18,14 @@ socket.on('server-info-response', function (data) {
socket.on('received-llap-msg', function (data) {
$('#serialtalk #serialtalk-resp').html(data.content);
});
// 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,7 +17,10 @@ block left-column
block main-column
#devices
.well wazzaup?
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
block right-column

2
views/layout.jade

@ -1,7 +1,7 @@
!!! 5
html
head
title Node LED
title Sensors base station
link(rel='stylesheet', href='/vendor/bootstrap.min.css')
//link(rel='stylesheet', href='/vendor/bootstrap-responsive.min.css')
link(rel='stylesheet', href='/css/style.css')

Loading…
Cancel
Save