Browse Source

Report max power over period to MQTT and InfluxDB

fastled
Xose Pérez 7 years ago
parent
commit
194f2a384c
3 changed files with 17 additions and 3 deletions
  1. +2
    -1
      code/espurna/config/general.h
  2. +8
    -0
      code/espurna/libs/MedianFilter.h
  3. +7
    -2
      code/espurna/power.ino

+ 2
- 1
code/espurna/config/general.h View File

@ -447,11 +447,12 @@ PROGMEM const char* const custom_reset_string[] = {
#define MQTT_TOPIC_RFLEARN "rflearn" #define MQTT_TOPIC_RFLEARN "rflearn"
// Power module // Power module
#define MQTT_TOPIC_POWER_ACTIVE "power"
#define MQTT_TOPIC_CURRENT "current" #define MQTT_TOPIC_CURRENT "current"
#define MQTT_TOPIC_VOLTAGE "voltage" #define MQTT_TOPIC_VOLTAGE "voltage"
#define MQTT_TOPIC_POWER_ACTIVE "power"
#define MQTT_TOPIC_POWER_APPARENT "apparent" #define MQTT_TOPIC_POWER_APPARENT "apparent"
#define MQTT_TOPIC_POWER_REACTIVE "reactive" #define MQTT_TOPIC_POWER_REACTIVE "reactive"
#define MQTT_TOPIC_MAX_POWER "max_power"
#define MQTT_TOPIC_POWER_FACTOR "factor" #define MQTT_TOPIC_POWER_FACTOR "factor"
#define MQTT_TOPIC_ENERGY_DELTA "energy_delta" #define MQTT_TOPIC_ENERGY_DELTA "energy_delta"
#define MQTT_TOPIC_ENERGY_TOTAL "energy_total" #define MQTT_TOPIC_ENERGY_TOTAL "energy_total"


+ 8
- 0
code/espurna/libs/MedianFilter.h View File

@ -30,6 +30,14 @@ class MedianFilter {
add(last); add(last);
} }
virtual double max() {
double max = 0;
for (unsigned char i = 1; i < _data->size(); i++) {
if (max < _data->at(i)) max = _data->at(i);
}
return max;
}
virtual double result(bool do_reset = false) { virtual double result(bool do_reset = false) {
double sum = 0; double sum = 0;


+ 7
- 2
code/espurna/power.ino View File

@ -199,17 +199,20 @@ void _powerRead() {
void _powerReport() { void _powerReport() {
// Get the fitered values // Get the fitered values
_power_current = _filter_current.result(true);
#if POWER_HAS_ACTIVE #if POWER_HAS_ACTIVE
_power_apparent = _filter_apparent.result(true);
double max_power = _filter_active.max();
_power_current = _filter_current.result(true);
_power_voltage = _filter_voltage.result(true); _power_voltage = _filter_voltage.result(true);
_power_active = _filter_active.result(true); _power_active = _filter_active.result(true);
_power_apparent = _filter_apparent.result(true);
if (_power_active > _power_apparent) _power_apparent = _power_active; if (_power_active > _power_apparent) _power_apparent = _power_active;
_power_reactive = (_power_apparent > _power_active) ? sqrt(_power_apparent * _power_apparent - _power_active * _power_active) : 0; _power_reactive = (_power_apparent > _power_active) ? sqrt(_power_apparent * _power_apparent - _power_active * _power_active) : 0;
_power_factor = (_power_apparent > 0) ? _power_active / _power_apparent : 1; _power_factor = (_power_apparent > 0) ? _power_active / _power_apparent : 1;
if (_power_factor > 1) _power_factor = 1; if (_power_factor > 1) _power_factor = 1;
double power = _power_active; double power = _power_active;
#else #else
double max_power = _filter_current.max() * _power_voltage;
_power_current = _filter_current.result(true);
_power_apparent = _power_current * _power_voltage; _power_apparent = _power_current * _power_voltage;
double power = _power_apparent; double power = _power_apparent;
#endif #endif
@ -232,6 +235,7 @@ void _powerReport() {
{ {
mqttSend(MQTT_TOPIC_CURRENT, buf_current); mqttSend(MQTT_TOPIC_CURRENT, buf_current);
mqttSend(MQTT_TOPIC_POWER_APPARENT, String((int) _power_apparent).c_str()); mqttSend(MQTT_TOPIC_POWER_APPARENT, String((int) _power_apparent).c_str());
mqttSend(MQTT_TOPIC_MAX_POWER, String((int) max_power).c_str());
mqttSend(MQTT_TOPIC_ENERGY_DELTA, buf_energy_delta); mqttSend(MQTT_TOPIC_ENERGY_DELTA, buf_energy_delta);
mqttSend(MQTT_TOPIC_ENERGY_TOTAL, buf_energy_total); mqttSend(MQTT_TOPIC_ENERGY_TOTAL, buf_energy_total);
#if POWER_HAS_ACTIVE #if POWER_HAS_ACTIVE
@ -267,6 +271,7 @@ void _powerReport() {
if (idbEnabled()) { if (idbEnabled()) {
idbSend(MQTT_TOPIC_CURRENT, buf_current); idbSend(MQTT_TOPIC_CURRENT, buf_current);
idbSend(MQTT_TOPIC_POWER_APPARENT, String((int) _power_apparent).c_str()); idbSend(MQTT_TOPIC_POWER_APPARENT, String((int) _power_apparent).c_str());
idbSend(MQTT_TOPIC_MAX_POWER, String((int) max_power).c_str());
idbSend(MQTT_TOPIC_ENERGY_DELTA, buf_energy_delta); idbSend(MQTT_TOPIC_ENERGY_DELTA, buf_energy_delta);
idbSend(MQTT_TOPIC_ENERGY_TOTAL, buf_energy_total); idbSend(MQTT_TOPIC_ENERGY_TOTAL, buf_energy_total);
#if POWER_HAS_ACTIVE #if POWER_HAS_ACTIVE


Loading…
Cancel
Save