1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-13 19:12:49 +00:00

added date updated to sensors

This commit is contained in:
2015-12-17 13:48:18 -06:00
parent 279303d2b9
commit 345432ef15
3 changed files with 26 additions and 32 deletions

View File

@@ -22,34 +22,6 @@ router.get('/vpn', function(req, res, next){
});
router.get('/sensors', function(req, res, next) {
temperature.aggregate( [ {$sort : {location : -1, updated : -1}}, { $group : { _id : "$location", temperature : {$first : "$temperature"}, humidity : {$first : "$humidity"}, updated : {$first : "$updated"}} } ] ).exec(function(err, info){
var date1 = new Date();
for (var i = 0; i < info.length; i++){
console.log(info[i].updated.getTime());
console.log(Date.now());
//compared current time to last db entry - 1200000 milliseconds is 2 minutes
if(info[i].updated.getTime() > (Date.now() - 120000)){
info[i].connected = true;
}
else {
info[i].connected = false;
}
console.log(info[i].connected);
}
res.render('sensors', {query : info});
});
});
/* GET home page. */
router.get('/', function(req, res, next) {