Browse Source

Report sensor errors to web UI

fastled
Xose Pérez 6 years ago
parent
commit
89f892ac79
4 changed files with 1821 additions and 1800 deletions
  1. BIN
      code/espurna/data/index.html.gz
  2. +1
    -0
      code/espurna/sensor.ino
  3. +1804
    -1799
      code/espurna/static/index.html.gz.h
  4. +16
    -1
      code/html/custom.js

BIN
code/espurna/data/index.html.gz View File


+ 1
- 0
code/espurna/sensor.ino View File

@ -132,6 +132,7 @@ void _sensorWebSocketOnSend(JsonObject& root) {
sensor["value"] = String(buffer); sensor["value"] = String(buffer);
sensor["units"] = _sensorUnits(magnitude.type); sensor["units"] = _sensorUnits(magnitude.type);
sensor["description"] = magnitude.sensor->slot(magnitude.local); sensor["description"] = magnitude.sensor->slot(magnitude.local);
sensor["error"] = magnitude.sensor->error();
if (magnitude.type == MAGNITUDE_TEMPERATURE) hasTemperature = true; if (magnitude.type == MAGNITUDE_TEMPERATURE) hasTemperature = true;


+ 1804
- 1799
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 16
- 1
code/html/custom.js View File

@ -39,6 +39,14 @@ function sensorType(type) {
return null; return null;
} }
function sensorError(error) {
var errors = [
"OK", "Out of range", "Warming up", "Timeout", "Wrong ID", "CRC Error"
];
if (0 <= error && error < errors.length) return errors[error];
return "Error " + error;
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Utils // Utils
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -730,7 +738,14 @@ function processData(data) {
initSensors(data[key]); initSensors(data[key]);
for (var i=0; i<data[key].length; i++) { for (var i=0; i<data[key].length; i++) {
var element = $("input[name=sensor][data=" + i + "]"); var element = $("input[name=sensor][data=" + i + "]");
if (element.length) element.val(data[key][i].value + data[key][i].units);
if (element.length) {
var error = data[key][i].error || 0;
if (error == 0) {
element.val(data[key][i].value + data[key][i].units);
} else {
element.val(sensorError(error));
}
}
} }
return; return;
} }


Loading…
Cancel
Save