Add full support for BL0940

Add support for BL0940 energy monitor as used in Blitzwolf BW-SHP10 (#8175)
This commit is contained in:
Theo Arends 2020-06-07 17:59:54 +02:00
parent c6fede2bf4
commit e54c85f83e
3 changed files with 5 additions and 25 deletions

View File

@ -75,3 +75,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
- Add ``FlashFrequency`` to ``status 4``
- Add support for up to two BH1750 sensors controlled by commands ``BH1750Resolution`` and ``BH1750MTime`` (#8139)
- Add support for up to eight MCP9808 temperature sensors by device111 (#8594)
- Add support for BL0940 energy monitor as used in Blitzwolf BW-SHP10 (#8175)

View File

@ -17,6 +17,7 @@
- Add ``FlashFrequency`` to ``status 4``
- Add support for up to two BH1750 sensors controlled by commands ``BH1750Resolution`` and ``BH1750MTime`` (#8139)
- Add Zigbee auto-responder for common attributes
- Add support for BL0940 energy monitor as used in Blitzwolf BW-SHP10 (#8175)
### 8.3.1.1 20200518

View File

@ -152,33 +152,11 @@ void Bl0940EverySecond(void) {
Bl0940.current = 0;
Bl0940.power = 0;
} else {
long cf_frequency = 0;
if (BL0940_PULSES_NOT_INITIALIZED == Bl0940.cf_pulses_last_time) {
Bl0940.cf_pulses_last_time = Bl0940.cf_pulses; // Init after restart
} else {
if (Bl0940.cf_pulses < Bl0940.cf_pulses_last_time) { // Rolled over after 16777215 pulses
cf_frequency = (0x1000000 - Bl0940.cf_pulses_last_time) + Bl0940.cf_pulses;
} else {
cf_frequency = Bl0940.cf_pulses - Bl0940.cf_pulses_last_time;
}
if (cf_frequency && Energy.active_power[0]) {
unsigned long delta = (cf_frequency * Settings.energy_power_calibration) / 36;
// prevent invalid load delta steps even checksum is valid (issue #5789):
// if (delta <= (3680*100/36) * 10 ) { // max load for S31/Pow R2: 3.68kW
// prevent invalid load delta steps even checksum is valid but allow up to 4kW (issue #7155):
if (delta <= (4000*100/36) * 10 ) { // max load for S31/Pow R2: 4.00kW
Bl0940.cf_pulses_last_time = Bl0940.cf_pulses;
Energy.kWhtoday_delta += delta;
}
else {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("BL9: Load overflow"));
Bl0940.cf_pulses_last_time = BL0940_PULSES_NOT_INITIALIZED;
}
if (Energy.active_power[0]) {
Energy.kWhtoday_delta += (Energy.active_power[0] * 1000) / 36;
EnergyUpdateToday();
}
}
}
Bl0940Serial->flush();
Bl0940Serial->write(BL0940_READ_COMMAND);