Skip to content

Commit

Permalink
CSE7766 Sensor (Sonoff S31/Pow R2) prevent invalid energy load steps
Browse files Browse the repository at this point in the history
prevent invalid load delta steps even checksum of datastream from CSE is valid (issue arendst#5789)
  • Loading branch information
curzon01 committed May 14, 2019
1 parent 0b6c62f commit 9ed9ac6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sonoff/xnrg_02_cse7766.ino
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,15 @@ void CseEverySecond(void)
cf_frequency = cf_pulses - cf_pulses_last_time;
}
if (cf_frequency && energy_active_power) {
cf_pulses_last_time = cf_pulses;
energy_kWhtoday_delta += (cf_frequency * Settings.energy_power_calibration) / 36;
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
cf_pulses_last_time = cf_pulses;
energy_kWhtoday_delta += delta;
}
else {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("CSE: Load overflow"));
}
EnergyUpdateToday();
}
}
Expand Down

0 comments on commit 9ed9ac6

Please sign in to comment.