modified to use events, hopefully will fix the crashing particle

This commit is contained in:
Martin Donnelly 2016-02-12 16:39:05 +00:00
parent b8e4a3229d
commit 4cbd586bc4

View File

@ -62,9 +62,7 @@ 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');
}
@ -89,7 +87,7 @@ function insertTempReading(time, reading) {
}
});*/
});*/
/*router.get('/:id', function (req, res, next) {
var id = req.params.id;
@ -98,7 +96,7 @@ function insertTempReading(time, reading) {
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);
}