From ac179daa17f19d542aaa1e3695c93075067887ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sun, 9 Apr 2017 18:34:30 +0200 Subject: [PATCH] Filter off-limits in HLW8012 readings --- code/espurna/config/hardware.h | 2 +- code/espurna/config/sensors.h | 4 +++- code/espurna/pow.ino | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index b2e095ff..12d3980e 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -58,7 +58,7 @@ #define LED1_PIN_INVERSE 0 #define BUTTON1_PIN 4 #define BUTTON1_RELAY 1 - #define BUTTON1_MODE BUTTON_SWITCH + #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH #define ENABLE_POW 1 // ----------------------------------------------------------------------------- diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index 6d1d570f..b0567dc0 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -118,8 +118,10 @@ #define POW_ENERGY_TOPIC "energy" #define POW_UPDATE_INTERVAL 5000 #define POW_REPORT_EVERY 12 -#define POW_MIN_POWER 10 +#define POW_MIN_POWER 5 +#define POW_MAX_POWER 2500 #define POW_MIN_CURRENT 0.05 +#define POW_MAX_CURRENT 10 //-------------------------------------------------------------------------------- // Internal power montior diff --git a/code/espurna/pow.ino b/code/espurna/pow.ino index 1807126c..bf11624b 100644 --- a/code/espurna/pow.ino +++ b/code/espurna/pow.ino @@ -96,25 +96,25 @@ void powReset() { unsigned int getActivePower() { unsigned int power = hlw8012.getActivePower(); - if (power < POW_MIN_POWER) power = 0; + if (POW_MIN_POWER > power || power > POW_MAX_POWER) power = 0; return power; } unsigned int getApparentPower() { unsigned int power = hlw8012.getApparentPower(); - if (power < POW_MIN_POWER) power = 0; + if (POW_MIN_POWER > power || power > POW_MAX_POWER) power = 0; return power; } unsigned int getReactivePower() { unsigned int power = hlw8012.getReactivePower(); - if (power < POW_MIN_POWER) power = 0; + if (POW_MIN_POWER > power || power > POW_MAX_POWER) power = 0; return power; } double getCurrent() { double current = hlw8012.getCurrent(); - if (current < POW_MIN_CURRENT) current = 0; + if (POW_MIN_CURRENT > current || current > POW_MAX_CURRENT) power = 0; return current; }