Browse Source

HLW8012 working with new modules

fastled
Xose Pérez 7 years ago
parent
commit
1f1ba1deb7
3 changed files with 8 additions and 11 deletions
  1. +3
    -3
      code/espurna/power.h
  2. +2
    -0
      code/espurna/power.ino
  3. +3
    -8
      code/espurna/power_hlw8012.ino

+ 3
- 3
code/espurna/power.h View File

@ -15,9 +15,9 @@ class MedianFilter {
}
virtual void reset() {
_data[0] = _data[_size];
_data[0] = _data[_pointer-1];
_pointer = 1;
for (unsigned char i=_pointer; i<=_size; i++) _data[i] = 0;
for (unsigned char i=1; i<=_size; i++) _data[i] = 0;
}
virtual void add(double value) {
@ -47,7 +47,7 @@ class MedianFilter {
}
sum /= (_pointer - 1);
sum /= (_pointer - 2);
}


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

@ -153,12 +153,14 @@ void _powerReport() {
_power_apparent = _filter_apparent.average(true);
_power_voltage = _filter_voltage.average(true);
_power_active = _filter_active.average(true);
if (_power_active > _power_apparent) _power_apparent = _power_active;
#else
_power_apparent = _power_current * _power_voltage;
_power_active = _power_apparent;
#endif
_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;
if (_power_factor > 1) _power_factor = 1;
_power_ready = true;
char buf_current[10];


+ 3
- 8
code/espurna/power_hlw8012.ino View File

@ -94,16 +94,11 @@ double _powerApparentPower() {
}
double _powerReactivePower() {
double active = _powerActivePower();
double apparent = _powerApparentPower();
if (apparent > active) return sqrt(apparent * apparent - active * active);
return 0;
return _hlw8012.getReactivePower();
}
double _powerPowerFactor() {
double apparent = _powerApparentPower();
if (apparent > 0) return _powerActivePower() / apparent;
return 1;
return _hlw8012.getPowerFactor();
}
void _powerEnabledProvider() {
@ -142,7 +137,7 @@ void _powerSetupProvider() {
// * The VOLTAGE_RESISTOR_DOWNSTREAM is the 1kOhm resistor in the voltage divider that feeds the V2P pin in the HLW8012
_hlw8012.setResistors(HLW8012_CURRENT_R, HLW8012_VOLTAGE_R_UP, HLW8012_VOLTAGE_R_DOWN);
powerConfigureProvider();
_powerConfigureProvider();
_power_wifi_onconnect = WiFi.onStationModeGotIP([](WiFiEventStationModeGotIP ipInfo) {
powerEnabled(true);


Loading…
Cancel
Save