modified to use events, hopefully will fix the crashing particle
This commit is contained in:
parent
b8e4a3229d
commit
4cbd586bc4
@ -62,43 +62,41 @@ function insertTempReading(time, reading) {
|
||||
logger.debug('Inserting reading:' + reading);
|
||||
|
||||
temp_db.run('BEGIN TRANSACTION');
|
||||
|
||||
temp_db.run('INSERT into temp(date, reading) VALUES (?,?);', [time, reading]);
|
||||
|
||||
temp_db.run('commit');
|
||||
}
|
||||
|
||||
/*router.get('/', function (req, res, next) {
|
||||
var now = new Date();
|
||||
var now = new Date();
|
||||
|
||||
var t = req.query;
|
||||
var t = req.query;
|
||||
|
||||
logger.log('t:');
|
||||
logger.log(JSON.stringify(t));
|
||||
if (req.query != {} && req.query.temp != null) {
|
||||
// createDB();
|
||||
logger.log('t:');
|
||||
logger.log(JSON.stringify(t));
|
||||
if (req.query != {} && req.query.temp != null) {
|
||||
// createDB();
|
||||
|
||||
|
||||
res.writeHead(200, {"ContentType": "text/html"});
|
||||
//res.send(JSON.stringify(t));
|
||||
res.end('ok');
|
||||
} else {
|
||||
res.writeHead(200, {"ContentType": "text/html"});
|
||||
//res.send(JSON.stringify(t));
|
||||
res.end('error?');
|
||||
}
|
||||
res.writeHead(200, {"ContentType": "text/html"});
|
||||
//res.send(JSON.stringify(t));
|
||||
res.end('ok');
|
||||
} else {
|
||||
res.writeHead(200, {"ContentType": "text/html"});
|
||||
//res.send(JSON.stringify(t));
|
||||
res.end('error?');
|
||||
}
|
||||
|
||||
|
||||
});*/
|
||||
});*/
|
||||
|
||||
/*router.get('/:id', function (req, res, next) {
|
||||
var id = req.params.id;
|
||||
var id = req.params.id;
|
||||
|
||||
logger.log('id: ' + id);
|
||||
res.writeHead(200, {"ContentType": "text/html"});
|
||||
//res.send(JSON.stringify(t));
|
||||
res.end('ok');
|
||||
});*/
|
||||
logger.log('id: ' + id);
|
||||
res.writeHead(200, {"ContentType": "text/html"});
|
||||
//res.send(JSON.stringify(t));
|
||||
res.end('ok');
|
||||
});*/
|
||||
|
||||
router.get('/reading', function (req, res, next) {
|
||||
var now = new Date();
|
||||
@ -121,19 +119,17 @@ router.post('/', function (req, res, next) {
|
||||
var now = new Date();
|
||||
var dataJSON;
|
||||
|
||||
if(t.hasOwnProperty('data')){
|
||||
if (t.hasOwnProperty('data')) {
|
||||
var data = JSON.parse(t.data.toString());
|
||||
|
||||
if (data.hasOwnProperty('temp')) {
|
||||
busEmitter.emit("saveTempData", {time: now.toJSON(), value: parseFloat(data.temp)});
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
logger.error('No temp data!');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
logger.error('No data block!');
|
||||
}
|
||||
|
||||
@ -165,8 +161,6 @@ router.get('/all', function (req, res, next) {
|
||||
|
||||
//closeDB();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@ -174,7 +168,7 @@ module.exports = router;
|
||||
createDB();
|
||||
|
||||
|
||||
var sendSocketHandler = (obj) => {
|
||||
var sendSocketHandler = (obj) =>{
|
||||
// logger.info('sendSocket: ' + JSON.stringify(obj));
|
||||
insertTempReading(obj.time, obj.value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user