From 6dd701ca7f27e112aba448cdd77adbe0b32755b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 24 Sep 2018 17:51:51 +0200 Subject: [PATCH] Support for apparent power and power factor in CSE77XX sensor (#1215) --- README.md | 4 ++-- code/espurna/sensors/CSE7766Sensor.h | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c465dd12..2112fb62 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smar It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. [![version](https://img.shields.io/badge/version-1.13.3a-brightgreen.svg)](CHANGELOG.md) -[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.com/ColinShorts/espurna.git/tree/dev/) -[![travis](https://travis-ci.org/ColinShorts/espurna.git.svg?branch=dev)](https://travis-ci.org/ColinShorts/espurna.git) +[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.com/xoseperez/espurna/tree/dev/) +[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna) [![codacy](https://api.codacy.com/project/badge/Grade/c9496e25cf07434cba786b462cb15f49)](https://www.codacy.com/app/xoseperez/espurna/dashboard) [![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)
diff --git a/code/espurna/sensors/CSE7766Sensor.h b/code/espurna/sensors/CSE7766Sensor.h index 1248ce09..6d70d4a3 100644 --- a/code/espurna/sensors/CSE7766Sensor.h +++ b/code/espurna/sensors/CSE7766Sensor.h @@ -22,7 +22,7 @@ class CSE7766Sensor : public BaseSensor { // --------------------------------------------------------------------- CSE7766Sensor(): BaseSensor(), _data() { - _count = 4; + _count = 6; _sensor_id = SENSOR_CSE7766_ID; } @@ -161,7 +161,9 @@ class CSE7766Sensor : public BaseSensor { if (index == 0) return MAGNITUDE_CURRENT; if (index == 1) return MAGNITUDE_VOLTAGE; if (index == 2) return MAGNITUDE_POWER_ACTIVE; - if (index == 3) return MAGNITUDE_ENERGY; + if (index == 3) return MAGNITUDE_POWER_APPARENT; + if (index == 4) return MAGNITUDE_POWER_FACTOR; + if (index == 5) return MAGNITUDE_ENERGY; return MAGNITUDE_NONE; } @@ -170,7 +172,9 @@ class CSE7766Sensor : public BaseSensor { if (index == 0) return _current; if (index == 1) return _voltage; if (index == 2) return _active; - if (index == 3) return _energy; + if (index == 3) return _voltage * _current; + if (index == 4) return ((_voltage > 0) && (_current > 0)) ? 100 * _active / _voltage / _current : 100; + if (index == 5) return _energy; return 0; }