Skip to content

Commit

Permalink
Show energy couont from date on web UI (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Apr 12, 2018
1 parent bb82d49 commit 072dd04
Show file tree
Hide file tree
Showing 4 changed files with 725 additions and 703 deletions.
Binary file modified code/espurna/data/index.html.gz
Binary file not shown.
21 changes: 20 additions & 1 deletion code/espurna/sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ unsigned char _sensor_temperature_units = SENSOR_TEMPERATURE_UNITS;
double _sensor_temperature_correction = SENSOR_TEMPERATURE_CORRECTION;
double _sensor_humidity_correction = SENSOR_HUMIDITY_CORRECTION;

String _sensor_energy_reset_ts = String();

// -----------------------------------------------------------------------------
// Private
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -120,9 +122,15 @@ void _sensorWebSocketSendData(JsonObject& root) {
element["type"] = int(magnitude.type);
element["value"] = String(buffer);
element["units"] = magnitudeUnits(magnitude.type);
element["description"] = magnitude.sensor->slot(magnitude.local);
element["error"] = magnitude.sensor->error();

if (magnitude.type == MAGNITUDE_ENERGY) {
if (_sensor_energy_reset_ts.length() == 0) _sensorReset();
element["description"] = magnitude.sensor->slot(magnitude.local) + _sensor_energy_reset_ts;
} else {
element["description"] = magnitude.sensor->slot(magnitude.local);
}

if (magnitude.type == MAGNITUDE_TEMPERATURE) hasTemperature = true;
if (magnitude.type == MAGNITUDE_HUMIDITY) hasHumidity = true;

Expand Down Expand Up @@ -277,6 +285,12 @@ void _sensorPost() {
}
}

void _sensorReset() {
if (ntpSynced()) {
_sensor_energy_reset_ts = String(" (since ") + ntpDateTime() + String(")");
}
}

// -----------------------------------------------------------------------------
// Sensor initialization
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -677,6 +691,7 @@ void _sensorConfigure() {

if (getSetting("pwrResetE", 0).toInt() == 1) {
sensor->resetEnergy();
_sensorReset();
}

sensor->setVoltage(getSetting("pwrVoltage", EMON_MAINS_VOLTAGE).toInt());
Expand All @@ -690,6 +705,7 @@ void _sensorConfigure() {
EmonADC121Sensor * sensor = (EmonADC121Sensor *) _sensors[i];
if (getSetting("pwrResetE", 0).toInt() == 1) {
sensor->resetEnergy();
_sensorReset();
}
}
#endif
Expand All @@ -699,6 +715,7 @@ void _sensorConfigure() {
EmonADS1X15Sensor * sensor = (EmonADS1X15Sensor *) _sensors[i];
if (getSetting("pwrResetE", 0).toInt() == 1) {
sensor->resetEnergy();
_sensorReset();
}
}
#endif
Expand Down Expand Up @@ -728,6 +745,7 @@ void _sensorConfigure() {

if (getSetting("pwrResetE", 0).toInt() == 1) {
sensor->resetEnergy();
_sensorReset();
}

if (getSetting("pwrResetCalibration", 0).toInt() == 1) {
Expand Down Expand Up @@ -765,6 +783,7 @@ void _sensorConfigure() {

if (getSetting("pwrResetE", 0).toInt() == 1) {
sensor->resetEnergy();
_sensorReset();
}

if (getSetting("pwrResetCalibration", 0).toInt() == 1) {
Expand Down
Loading

0 comments on commit 072dd04

Please sign in to comment.