Browse Source

Option to select power read & report interval from web UI

fastled
Xose Pérez 7 years ago
parent
commit
245285556d
9 changed files with 2703 additions and 2634 deletions
  1. +1
    -0
      code/espurna/config/general.h
  2. +1
    -2
      code/espurna/config/hardware.h
  3. BIN
      code/espurna/data/index.html.gz
  4. +28
    -6
      code/espurna/power.ino
  5. +1
    -3
      code/espurna/power_emon.ino
  6. +1
    -1
      code/espurna/power_hlw8012.ino
  7. +2632
    -2621
      code/espurna/static/index.html.gz.h
  8. +2
    -0
      code/espurna/web.ino
  9. +37
    -1
      code/html/index.html

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

@ -554,6 +554,7 @@ PROGMEM const char* const custom_reset_string[] = {
#endif
#define POWER_VOLTAGE 230 // Default voltage
#define POWER_MIN_READ_INTERVAL 2000 // Minimum read interval
#define POWER_READ_INTERVAL 6000 // Default reading interval (6 seconds)
#define POWER_REPORT_INTERVAL 60000 // Default report interval (1 minute)
#define POWER_CURRENT_DECIMALS 2 // Decimals for current values


+ 1
- 2
code/espurna/config/hardware.h View File

@ -1,4 +1,4 @@
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Configuration HELP
// -----------------------------------------------------------------------------
//
@ -63,7 +63,6 @@
#define LED1_PIN 2
#define LED1_PIN_INVERSE 1
// -----------------------------------------------------------------------------
// ESPurna
// -----------------------------------------------------------------------------


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


+ 28
- 6
code/espurna/power.ino View File

@ -20,6 +20,9 @@ bool _power_enabled = false;
bool _power_ready = false;
bool _power_newdata = false;
unsigned long _power_read_interval = POWER_READ_INTERVAL;
unsigned long _power_report_interval = POWER_REPORT_INTERVAL;
double _power_current = 0;
double _power_voltage = 0;
double _power_apparent = 0;
@ -171,11 +174,11 @@ void _powerRead() {
void _powerReport() {
// Get the fitered values
_power_current = _filter_current.average(true);
_power_current = _filter_current.median(true);
#if POWER_HAS_ACTIVE
_power_apparent = _filter_apparent.average(true);
_power_voltage = _filter_voltage.average(true);
_power_active = _filter_active.average(true);
_power_apparent = _filter_apparent.median(true);
_power_voltage = _filter_voltage.median(true);
_power_active = _filter_active.median(true);
if (_power_active > _power_apparent) _power_apparent = _power_active;
_power_reactive = (_power_apparent > _power_active) ? sqrt(_power_apparent * _power_apparent - _power_active * _power_active) : 0;
_power_factor = (_power_apparent > 0) ? _power_active / _power_apparent : 1;
@ -189,7 +192,7 @@ void _powerReport() {
double energy_delta = _power_energy - _power_last_energy;
_power_last_energy = _power_energy;
#else
double energy_delta = power * (POWER_REPORT_INTERVAL / 1000.);
double energy_delta = power * (_power_report_interval / 1000.);
_power_energy += energy_delta;
#endif
_power_ready = true;
@ -293,6 +296,14 @@ double getPowerFactor() {
// PUBLIC API
// -----------------------------------------------------------------------------
unsigned long powerReadInterval() {
return _power_read_interval;
}
unsigned long powerReportInterval() {
return _power_report_interval;
}
bool powerEnabled() {
return _power_enabled;
}
@ -312,6 +323,16 @@ void powerResetCalibration() {
}
void powerConfigure() {
_power_read_interval = atol(getSetting("pwrReadEvery", POWER_READ_INTERVAL).c_str());
_power_report_interval = atol(getSetting("pwrReportEvery", POWER_REPORT_INTERVAL).c_str());
if (_power_read_interval < POWER_MIN_READ_INTERVAL) {
_power_read_interval = POWER_MIN_READ_INTERVAL;
setSetting("pwrReadEvery", _power_read_interval);
}
if (_power_report_interval < _power_read_interval) {
_power_report_interval = _power_read_interval;
setSetting("pwrReportEvery", _power_report_interval);
}
_powerConfigureProvider();
}
@ -332,6 +353,7 @@ void powerSetup() {
moveSetting("powerRatioP", "pwrRatioP");
_powerSetupProvider();
powerConfigure();
// API
#if WEB_SUPPORT
@ -352,7 +374,7 @@ void powerLoop() {
}
static unsigned long last = 0;
if (millis() - last > POWER_REPORT_INTERVAL) {
if (millis() - last > _power_report_interval) {
last = millis();
_powerReport();
}


+ 1
- 3
code/espurna/power_emon.ino View File

@ -141,8 +141,6 @@ void _powerSetupProvider() {
brzo_i2c_end_transaction();
#endif
_powerConfigureProvider();
_emon.warmup();
}
@ -152,7 +150,7 @@ void _powerLoopProvider(bool before) {
if (before) {
static unsigned long last = 0;
if (millis() - last > POWER_READ_INTERVAL) {
if (millis() - last > powerReadInterval()) {
last = millis();
_power_newdata = true;
}


+ 1
- 1
code/espurna/power_hlw8012.ino View File

@ -151,7 +151,7 @@ void _powerLoopProvider(bool before) {
if (before) {
static unsigned long last = 0;
if (millis() - last > POWER_READ_INTERVAL) {
if (millis() - last > powerReadInterval()) {
last = millis();
_power_newdata = true;


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


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

@ -656,6 +656,8 @@ void _wsStart(uint32_t client_id) {
root["pwrVoltage"] = getVoltage();
root["pwrApparent"] = getApparentPower();
root["pwrEnergy"] = getPowerEnergy();
root["pwrReadEvery"] = powerReadInterval();
root["pwrReportEvery"] = powerReportInterval();
#if POWER_HAS_ACTIVE
root["pwrActive"] = getActivePower();
root["pwrReactive"] = getReactivePower();


+ 37
- 1
code/html/index.html View File

@ -796,7 +796,7 @@
<div class="header">
<h1>POWER CALIBRATION</h1>
<h2>
Calibrate your power monitor device. Use a pure resistive load and introduce the expected values for active power, current and voltage. Use the nominal values or a multimeter to get the proper numbers. Set any field to 0 to leave the calibration value untouched.
Configure and calibrate your power monitor device. Use a pure resistive load and introduce the expected values for active power, current and voltage. Use the nominal values or a multimeter to get the proper numbers. Set any field to 0 to leave the calibration value untouched.
</h2>
</div>
@ -804,6 +804,42 @@
<fieldset>
<div class="pure-g">
<label class="pure-u-1 pure-u-sm-1-4" for="pwrReadEvery">Read interval</label>
<select class="pure-u-1 pure-u-sm-1-4" name="pwrReadEvery">
<option value=2000>2 seconds</option>
<option value=6000>6 seconds</option>
<option value=10000>10 seconds</option>
<option value=15000>15 seconds</option>
<option value=30000>30 seconds</option>
<option value=60000>60 seconds</option>
</select>
<div class="pure-u-0 pure-u-md-1-2">&nbsp;</div>
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">
Select the interval between readings. These will be filtered and averaged for the report.<br />
The default and recommended value is 6 seconds.
</div>
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-sm-1-4" for="pwrReportEvery">Report interval</label>
<select class="pure-u-1 pure-u-sm-1-4" name="pwrReportEvery">
<option value=6000>6 seconds</option>
<option value=10000>10 seconds</option>
<option value=30000>30 seconds</option>
<option value=60000>1 minute</option>
<option value=300000>5 minutes</option>
</select>
<div class="pure-u-0 pure-u-md-1-2">&nbsp;</div>
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">
Select the interval between reports via MQTT.<br />
This can't be less than the reading interval above.<br />
The default and recommended value is 1 minute.
</div>
</div>
<div class="pure-g module module-hlw module-emon module-v9261f">
<label class="pure-u-1 pure-u-md-1-4" for="pwrExpectedP">AC RMS Active Power</label>
<input class="pure-u-1 pure-u-md-3-4 pwrExpected" name="pwrExpectedP" type="text" size="8" tabindex="51" placeholder="0" />


Loading…
Cancel
Save