Skip to content

Commit

Permalink
missing log data fix, error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
LowPowerLab committed Feb 17, 2016
1 parent 104cd1e commit 5190620
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
14 changes: 7 additions & 7 deletions gateway.js
Expand Up @@ -47,13 +47,13 @@ serial = new serialport.SerialPort(settings.serial.port.value, { baudrate : sett
serial.on('error', function serialErrorHandler(error) {
//Send serial error messages to console.
//Better error handling needs to be here in the future.
console.log(error.message);
console.error(error.message);
});

serial.on('close', function serialCloseHandler(error) {
//Give user a sane error message and exit. Future possibilities could include
//sending message to front end via socket.io & setup timer to retry opening serial.
console.log(error.message);
console.error(error.message);
process.exit(1);
});

Expand Down Expand Up @@ -85,7 +85,7 @@ global.sendEmail = function(SUBJECT, BODY) {
//html: '<b>Hello world ?</b>' // html body
};
transporter.sendMail(mailOptions, function(error, info) {
if(error) console.log('SENDEMAIL ERROR: ' + error);
if(error) console.error('SENDEMAIL ERROR: ' + error);
else console.log('SENDEMAIL SUCCESS: ' + info.response);
});
}
Expand All @@ -98,7 +98,7 @@ global.sendSMS = function(SUBJECT, BODY) {
text: BODY
};
transporter.sendMail(mailOptions, function(error, info) {
if(error) console.log('SENDSMS error: ' + error);
if(error) console.error('SENDSMS error: ' + error);
else console.log('SENDSMS SUCCESS: ' + info.response);
});
}
Expand Down Expand Up @@ -133,7 +133,7 @@ global.handleNodeEvents = function(node) {
try {
evt.serverExecute(node);
}
catch(ex) {console.log('Event ' + key + ' execution failed: ' + ex.message);}
catch(ex) {console.warn('Event ' + key + ' execution failed: ' + ex.message);}
}
}
}
Expand All @@ -160,7 +160,7 @@ io.use(function(socket, next) {
io.sockets.on('connection', function (socket) {
var address = socket.handshake.headers['x-forwarded-for'] || socket.request.connection.remoteAddress;
//var port = socket.request.connection.remotePort;
console.log("NEW CONNECTION FROM " + address /*+ ":" + port*/);
console.info("NEW CONNECTION FROM " + address /*+ ":" + port*/);
socket.emit('MOTESDEF', metricsDef.motes);
socket.emit('METRICSDEF', metricsDef.metrics);
socket.emit('EVENTSDEF', metricsDef.events);
Expand Down Expand Up @@ -466,7 +466,7 @@ global.processSerialData = function (data) {
try {
console.log('post: ' + logfile + '[' + ts + ','+graphValue + ']');
dbLog.postData(logfile, ts, graphValue);
} catch (err) { console.log(' POST ERROR: ' + err.message); /*console.log(' POST ERROR STACK TRACE: ' + err.stack); */ } //because this is a callback concurrent calls to the same log, milliseconds apart, can cause a file handle concurrency exception
} catch (err) { console.error(' POST ERROR: ' + err.message); /*console.log(' POST ERROR STACK TRACE: ' + err.stack); */ } //because this is a callback concurrent calls to the same log, milliseconds apart, can cause a file handle concurrency exception
}
else console.log(' METRIC NOT NUMERIC, logging skipped... (extracted value:' + graphValue + ')');
}
Expand Down
6 changes: 4 additions & 2 deletions logUtil.js
Expand Up @@ -27,8 +27,11 @@ exports.getData = function(filename, start, end, dpcount) {
if (dpcount<1 || start > end) return {};

var ts = new Date();
fd = fs.openSync(filename, 'r');
data = [];

filesize = exports.fileSize(filename);
if (filesize == -1) return {data:data, queryTime:0, msg:'no log data'};
fd = fs.openSync(filename, 'r');
interval = (end - start) / dpcount;

// Ensure that interval request is less than 1, adjust number of datapoints to request if interval = 1
Expand All @@ -37,7 +40,6 @@ exports.getData = function(filename, start, end, dpcount) {
dpcount = (end - start) / interval;
}

data = [];
timetmp = 0;
buff = new Buffer(9);

Expand Down
2 changes: 1 addition & 1 deletion www/index.html
Expand Up @@ -598,7 +598,7 @@ <h1>Settings</h1>
graphOptions.yaxis.max = max;

graphOptions = $.extend(true, graphOptions, rawData.options); //http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically
$('#graphStat').html(rawData.graphData.data.length + 'pts, ' + rawData.graphData.queryTime + 'ms');
$('#graphStat').html(rawData.graphData.msg != undefined ? rawData.graphData.msg : (rawData.graphData.data.length + 'pts, ' + rawData.graphData.queryTime + 'ms'));
//need to defer plotting until after pageshow is finished rendering, otherwise the wrapper will return an incorrect width of "100"
if (metricGraphWrapper.width()==100)
$(document).on("pageshow", "#metricdetails", renderPlot);
Expand Down

0 comments on commit 5190620

Please sign in to comment.