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