Browse Source

Option to report energy data in kWh (#523)

rfm69
Xose Pérez 6 years ago
parent
commit
da3f7b7055
7 changed files with 3231 additions and 3205 deletions
  1. +0
    -7
      code/espurna/config/general.h
  2. +20
    -5
      code/espurna/config/sensors.h
  3. BIN
      code/espurna/data/index.html.gz
  4. +10
    -0
      code/espurna/sensor.ino
  5. +3193
    -3191
      code/espurna/static/index.html.gz.h
  6. +0
    -2
      code/espurna/ws.ino
  7. +8
    -0
      code/html/index.html

+ 0
- 7
code/espurna/config/general.h View File

@ -309,13 +309,6 @@ PROGMEM const char* const custom_reset_string[] = {
// Do not save relay state after these many milliseconds
#define RELAY_SAVE_DELAY 1000
//------------------------------------------------------------------------------
// I18N
//------------------------------------------------------------------------------
#define TMP_CELSIUS 0
#define TMP_FAHRENHEIT 1
//------------------------------------------------------------------------------
// LED
//------------------------------------------------------------------------------


+ 20
- 5
code/espurna/config/sensors.h View File

@ -15,10 +15,6 @@
#define SENSOR_USE_INDEX 0 // Use the index in topic (i.e. temperature/0)
// even if just one sensor (0 for backwards compatibility)
#ifndef SENSOR_TEMPERATURE_UNITS
#define SENSOR_TEMPERATURE_UNITS TMP_CELSIUS // Temperature units (TMP_CELSIUS | TMP_FAHRENHEIT)
#endif
#ifndef SENSOR_TEMPERATURE_CORRECTION
#define SENSOR_TEMPERATURE_CORRECTION 0.0 // Offset correction
#endif
@ -39,6 +35,24 @@
#define SENSOR_PUBLISH_ADDRESSES 0 // Publish sensor addresses
#define SENSOR_ADDRESS_TOPIC "address" // Topic to publish sensor addresses
//------------------------------------------------------------------------------
// UNITS
//------------------------------------------------------------------------------
#define ENERGY_JOULES 0
#define ENERGY_KWH 1
#define TMP_CELSIUS 0
#define TMP_FAHRENHEIT 1
#ifndef SENSOR_TEMPERATURE_UNITS
#define SENSOR_TEMPERATURE_UNITS TMP_CELSIUS // Temperature units (TMP_CELSIUS | TMP_FAHRENHEIT)
#endif
#ifndef SENSOR_ENERGY_UNITS
#define SENSOR_ENERGY_UNITS ENERGY_JOULES // Energy units (ENERGY_JOULES | ENERGY_KWH)
#endif
//--------------------------------------------------------------------------------
// Sensor ID
// These should remain over time, do not modify them, only add new ones at the end
@ -504,7 +518,7 @@
PROGMEM const unsigned char magnitude_decimals[] = {
0,
1, 0, 2,
3, 0, 0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0, 3, 3,
0, 0, 0,
0, 0, 0,
0, 0
@ -550,6 +564,7 @@ PROGMEM const char magnitude_amperes[] = "A";
PROGMEM const char magnitude_volts[] = "V";
PROGMEM const char magnitude_watts[] = "W";
PROGMEM const char magnitude_joules[] = "J";
PROGMEM const char magnitude_kwh[] = "kWh";
PROGMEM const char magnitude_ugm3[] = "µg/m3";
PROGMEM const char magnitude_ppm[] = "ppm";
PROGMEM const char magnitude_lux[] = "lux";


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


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

@ -34,6 +34,7 @@ bool _sensor_realtime = API_REAL_TIME_VALUES;
unsigned long _sensor_read_interval = 1000 * SENSOR_READ_INTERVAL;
unsigned char _sensor_report_every = SENSOR_REPORT_EVERY;
unsigned char _sensor_temperature_units = SENSOR_TEMPERATURE_UNITS;
unsigned char _sensor_energy_units = SENSOR_ENERGY_UNITS;
double _sensor_temperature_correction = SENSOR_TEMPERATURE_CORRECTION;
// -----------------------------------------------------------------------------
@ -50,6 +51,9 @@ double _magnitudeProcess(unsigned char type, double value) {
if (_sensor_temperature_units == TMP_FAHRENHEIT) value = value * 1.8 + 32;
value = value + _sensor_temperature_correction;
}
if (type == MAGNITUDE_ENERGY || type == MAGNITUDE_ENERGY_DELTA) {
if (_sensor_energy_units == ENERGY_KWH) value = value / 3600000;
}
return roundTo(value, _magnitudeDecimals(type));
}
@ -110,6 +114,7 @@ void _sensorWebSocketStart(JsonObject& root) {
root["sensorsVisible"] = 1;
//root["apiRealTime"] = _sensor_realtime;
root["tmpUnits"] = _sensor_temperature_units;
root["energyUnits"] = _sensor_energy_units;
root["tmpCorrection"] = _sensor_temperature_correction;
root["snsRead"] = _sensor_read_interval / 1000;
root["snsReport"] = _sensor_report_every;
@ -491,6 +496,7 @@ void _sensorConfigure() {
_sensor_report_every = constrain(getSetting("snsReport", SENSOR_REPORT_EVERY).toInt(), SENSOR_REPORT_MIN_EVERY, SENSOR_REPORT_MAX_EVERY);
_sensor_realtime = getSetting("apiRealTime", API_REAL_TIME_VALUES).toInt() == 1;
_sensor_temperature_units = getSetting("tmpUnits", SENSOR_TEMPERATURE_UNITS).toInt();
_sensor_energy_units = getSetting("energyUnits", SENSOR_ENERGY_UNITS).toInt();
_sensor_temperature_correction = getSetting("tmpCorrection", SENSOR_TEMPERATURE_CORRECTION).toFloat();
// Update filter sizes
@ -608,6 +614,10 @@ String magnitudeUnits(unsigned char type) {
if (type < MAGNITUDE_MAX) {
if ((type == MAGNITUDE_TEMPERATURE) && (_sensor_temperature_units == TMP_FAHRENHEIT)) {
strncpy_P(buffer, magnitude_fahrenheit, sizeof(buffer));
} else if ((type == MAGNITUDE_ENERGY) && (_sensor_energy_units == ENERGY_KWH)) {
strncpy_P(buffer, magnitude_kwh, sizeof(buffer));
} else if ((type == MAGNITUDE_ENERGY_DELTA) && (_sensor_energy_units == ENERGY_KWH)) {
strncpy_P(buffer, magnitude_kwh, sizeof(buffer));
} else {
strncpy_P(buffer, magnitude_units[type], sizeof(buffer));
}


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


+ 0
- 2
code/espurna/ws.ino View File

@ -255,8 +255,6 @@ void _wsOnStart(JsonObject& root) {
root["btnDelay"] = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt();
root["webPort"] = getSetting("webPort", WEB_PORT).toInt();
root["tmpUnits"] = getSetting("tmpUnits", SENSOR_TEMPERATURE_UNITS).toInt();
root["tmpCorrection"] = getSetting("tmpCorrection", SENSOR_TEMPERATURE_CORRECTION).toFloat();
}


+ 8
- 0
code/html/index.html View File

@ -932,6 +932,14 @@
</div>
</div>
<div class="pure-g module module-hlw module-emon">
<label class="pure-u-1 pure-u-lg-1-4">Energy units</label>
<select name="energyUnits" tabindex="16" class="pure-u-1 pure-u-lg-1-4">
<option value="0">Joules (J)</option>
<option value="1">Kilowatts·hour (kWh)</option>
</select>
</div>
<div class="pure-g module module-temperature">
<label class="pure-u-1 pure-u-lg-1-4">Temperature units</label>
<select name="tmpUnits" tabindex="16" class="pure-u-1 pure-u-lg-1-4">


Loading…
Cancel
Save