From 9ed9ac662137477218bfda6ef9ed8b43832bc1c6 Mon Sep 17 00:00:00 2001 From: Norbert Richter Date: Tue, 14 May 2019 12:13:42 +0200 Subject: [PATCH] CSE7766 Sensor (Sonoff S31/Pow R2) prevent invalid energy load steps prevent invalid load delta steps even checksum of datastream from CSE is valid (issue #5789) --- sonoff/xnrg_02_cse7766.ino | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sonoff/xnrg_02_cse7766.ino b/sonoff/xnrg_02_cse7766.ino index fa0188e03188..078ff3d6e0bd 100644 --- a/sonoff/xnrg_02_cse7766.ino +++ b/sonoff/xnrg_02_cse7766.ino @@ -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(); } }