Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all supported DSP values and provide a sample config to push data to OpenEnergyMonitor (emoncms) via MQTT #16

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ABBAuroraEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ enum DSP_VALUE_TYPE

enum DSP_GLOBAL
{
GLOBAL_MESSUREMENT = 1,
MODULE_MESSUREMENT = 0,
GLOBAL_MEASUREMENT = 1,
MODULE_MEASUREMENT = 0,
};

enum CUMULATED_ENERGY_TYPE
Expand Down
216 changes: 128 additions & 88 deletions InverterMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ class InverterMonitor : public PollingComponent
{

protected:
InverterMonitor() : PollingComponent(15000) {}
InverterMonitor() : PollingComponent(5000) {}
static InverterMonitor *instance_;

private:
ABBAurora *inverter;
bool led_state;
uint8_t connection = 0;

public:
Expand All @@ -76,17 +75,84 @@ class InverterMonitor : public PollingComponent
Sensor *cumulated_energy_month = new Sensor();
Sensor *cumulated_energy_year = new Sensor();
Sensor *cumulated_energy_total = new Sensor();
Sensor *grid_voltage = new Sensor();
Sensor *grid_current = new Sensor();
Sensor *grid_power = new Sensor();
Sensor *frequency = new Sensor();
Sensor *v_bulk = new Sensor();
Sensor *i_leak_dc_dc = new Sensor();
Sensor *i_leak_inverter = new Sensor();
Sensor *dc_dc_grid_voltage = new Sensor();
Sensor *dc_dc_grid_frequency = new Sensor();
Sensor *isolation_resistance = new Sensor();
Sensor *dc_dc_v_bulk = new Sensor();
Sensor *average_grid_voltage = new Sensor();
Sensor *v_bulk_mid = new Sensor();
Sensor *grid_voltage_neutral = new Sensor();
Sensor *wind_generator_frequency = new Sensor();
Sensor *grid_voltage_neutral_phase = new Sensor();
Sensor *grid_current_phase_r = new Sensor();
Sensor *grid_current_phase_s = new Sensor();
Sensor *grid_current_phase_t = new Sensor();
Sensor *frequency_phase_r = new Sensor();
Sensor *frequency_phase_s = new Sensor();
Sensor *frequency_phase_t = new Sensor();
Sensor *v_bulk_positive = new Sensor();
Sensor *v_bulk_negative = new Sensor();
Sensor *temperature_supervisor = new Sensor();
Sensor *temperature_alim = new Sensor();
Sensor *temperature_heat_sink = new Sensor();
Sensor *temperature_1 = new Sensor();
Sensor *temperature_2 = new Sensor();
Sensor *temperature_3 = new Sensor();
Sensor *fan_speed_1 = new Sensor();
Sensor *fan_speed_2 = new Sensor();
Sensor *fan_speed_3 = new Sensor();
Sensor *fan_speed_4 = new Sensor();
Sensor *fan_speed_5 = new Sensor();
Sensor *power_saturation_limit = new Sensor();
Sensor *v_panel_micro = new Sensor();
Sensor *grid_voltage_phase_r = new Sensor();
Sensor *grid_voltage_phase_s = new Sensor();
Sensor *grid_voltage_phase_t = new Sensor();

void setup() override
{
ESP_LOGD(TAG, "Setupping");
ESP_LOGD(TAG, "Setting up");
pinMode(LED, OUTPUT);
led_state = LOW;
ABBAurora::setup(INVERTER_MONITOR_SERIAL, RX, TX, TX_CONTROL_GPIO);
inverter = new ABBAurora(INVERTER_ADDRESS);
connection_status->publish_state(DISCONNECTED);
}

void publish_dsp_value(DSP_VALUE_TYPE type, Sensor *sensor)
{
if (inverter->ReadDSPValue(type, MODULE_MEASUREMENT)) {
ESP_LOGD(TAG, "ReadDSPValue %d %f", type, inverter->DSP.Value);
sensor->publish_state(inverter->DSP.Value);
}
yield();
}

void publish_temperature(DSP_VALUE_TYPE type, Sensor *sensor)
{
if (inverter->ReadDSPValue(type, MODULE_MEASUREMENT)) {
float temp = inverter->DSP.Value / 10;
ESP_LOGD(TAG, "ReadDSPValue %d %f", type, temp);
sensor->publish_state(temp);
}
yield();
}

void publish_cumulated_energy(CUMULATED_ENERGY_TYPE type, Sensor *sensor)
{
if (inverter->ReadCumulatedEnergy(type)) {
ESP_LOGD(TAG, "ReadCumulatedEnergy %d %f.0", type, inverter->CumulatedEnergy.Energy);
sensor->publish_state(inverter->CumulatedEnergy.Energy);
}
yield();
}

void update() override
{
//If inverter is connected
Expand All @@ -99,82 +165,62 @@ class InverterMonitor : public PollingComponent
}
turn_led_on();

ESP_LOGD(TAG, "ReadDSPValue V_IN_1");
if (inverter->ReadDSPValue(V_IN_1, MODULE_MESSUREMENT))
v_in_1->publish_state(inverter->DSP.Value);
yield();

ESP_LOGD(TAG, "ReadDSPValue V_IN_2");
if (inverter->ReadDSPValue(V_IN_2, MODULE_MESSUREMENT))
v_in_2->publish_state(inverter->DSP.Value);
yield();

ESP_LOGD(TAG, "ReadDSPValue I_IN_1");
if (inverter->ReadDSPValue(I_IN_1, MODULE_MESSUREMENT))
i_in_1->publish_state(inverter->DSP.Value);
yield();

ESP_LOGD(TAG, "ReadDSPValue I_IN_2");
if (inverter->ReadDSPValue(I_IN_2, MODULE_MESSUREMENT))
i_in_2->publish_state(inverter->DSP.Value);
yield();

ESP_LOGD(TAG, "ReadDSPValue POWER_IN_1");
if (inverter->ReadDSPValue(POWER_IN_1, MODULE_MESSUREMENT))
power_in_1->publish_state(inverter->DSP.Value);
yield();

ESP_LOGD(TAG, "ReadDSPValue POWER_IN_2");
if (inverter->ReadDSPValue(POWER_IN_2, MODULE_MESSUREMENT))
power_in_2->publish_state(inverter->DSP.Value);
yield();

publish_dsp_value(V_IN_1, v_in_1);
publish_dsp_value(V_IN_2, v_in_2);
publish_dsp_value(I_IN_1, i_in_1);
publish_dsp_value(I_IN_2, i_in_2);
publish_dsp_value(POWER_IN_1, power_in_1);
publish_dsp_value(POWER_IN_2, power_in_2);
power_in_total->publish_state(power_in_1->get_state() + power_in_2->get_state());

ESP_LOGD(TAG, "ReadDSPValue POWER_PEAK_TODAY");
if (inverter->ReadDSPValue(POWER_PEAK_TODAY, MODULE_MESSUREMENT))
power_peak_today->publish_state(inverter->DSP.Value);
yield();

ESP_LOGD(TAG, "ReadDSPValue POWER_PEAK");
if (inverter->ReadDSPValue(POWER_PEAK, MODULE_MESSUREMENT))
power_peak_max->publish_state(inverter->DSP.Value);
yield();

ESP_LOGD(TAG, "ReadDSPValue TEMPERATURE_INVERTER");
if (inverter->ReadDSPValue(TEMPERATURE_INVERTER, MODULE_MESSUREMENT))
temperature_inverter->publish_state(inverter->DSP.Value);
yield();

ESP_LOGD(TAG, "ReadDSPValue TEMPERATURE_BOOSTER");
if (inverter->ReadDSPValue(TEMPERATURE_BOOSTER, MODULE_MESSUREMENT))
temperature_booster->publish_state(inverter->DSP.Value);
yield();

ESP_LOGD(TAG, "ReadCumulatedEnergy CUMULATED_ENERGY_CURRENT_DAY");
if (inverter->ReadCumulatedEnergy(CURRENT_DAY))
cumulated_energy_today->publish_state(inverter->CumulatedEnergy.Energy);
yield();

ESP_LOGD(TAG, "ReadCumulatedEnergy CUMULATED_ENERGY_CURRENT_WEEK");
if (inverter->ReadCumulatedEnergy(CURRENT_WEEK))
cumulated_energy_week->publish_state(inverter->CumulatedEnergy.Energy);
yield();

ESP_LOGD(TAG, "ReadCumulatedEnergy CUMULATED_ENERGY_CURRENT_MONTH");
if (inverter->ReadCumulatedEnergy(CURRENT_MONTH))
cumulated_energy_month->publish_state(inverter->CumulatedEnergy.Energy);
yield();

ESP_LOGD(TAG, "ReadCumulatedEnergy CUMULATED_ENERGY_CURRENT_YEAR");
if (inverter->ReadCumulatedEnergy(CURRENT_YEAR))
cumulated_energy_year->publish_state(inverter->CumulatedEnergy.Energy);
yield();

ESP_LOGD(TAG, "ReadCumulatedEnergy CUMULATED_ENERGY_TOTAL");
if (inverter->ReadCumulatedEnergy(TOTAL))
cumulated_energy_total->publish_state(inverter->CumulatedEnergy.Energy);
yield();
publish_dsp_value(POWER_PEAK_TODAY, power_peak_today);
publish_dsp_value(POWER_PEAK, power_peak_max);
publish_dsp_value(TEMPERATURE_INVERTER, temperature_inverter);
publish_dsp_value(TEMPERATURE_BOOSTER, temperature_booster);
publish_cumulated_energy(CURRENT_DAY, cumulated_energy_today);
publish_cumulated_energy(CURRENT_WEEK, cumulated_energy_week);
publish_cumulated_energy(CURRENT_MONTH, cumulated_energy_month);
publish_cumulated_energy(CURRENT_YEAR, cumulated_energy_year);
publish_cumulated_energy(TOTAL, cumulated_energy_total);
publish_dsp_value(GRID_VOLTAGE, grid_voltage);
publish_dsp_value(GRID_CURRENT, grid_current);
publish_dsp_value(GRID_POWER, grid_power);
publish_dsp_value(FREQUENCY, frequency);
publish_dsp_value(V_BULK, v_bulk);
publish_dsp_value(I_LEAK_DC_DC, i_leak_dc_dc);
publish_dsp_value(I_LEAK_INVERTER, i_leak_inverter);
publish_dsp_value(DC_DC_GRID_VOLTAGE, dc_dc_grid_voltage);
publish_dsp_value(DC_DC_GRID_FREQUENCY, dc_dc_grid_frequency);
publish_dsp_value(ISOLATION_RESISTANCE, isolation_resistance);
publish_dsp_value(DC_DC_V_BULK, dc_dc_v_bulk);
publish_dsp_value(AVERAGE_GRID_VOLTAGE, average_grid_voltage);
publish_dsp_value(V_BULK_MID, v_bulk_mid);
publish_dsp_value(GRID_VOLTAGE_NEUTRAL, grid_voltage_neutral);
publish_dsp_value(WIND_GENERATOR_FREQENCY, wind_generator_frequency);
publish_dsp_value(GRID_VOLTAGE_NEUTRAL_PHASE, grid_voltage_neutral_phase);
publish_dsp_value(GRID_CURRENT_PHASE_R, grid_current_phase_r);
publish_dsp_value(GRID_CURRENT_PHASE_S, grid_current_phase_s);
publish_dsp_value(GRID_CURRENT_PHASE_T, grid_current_phase_t);
publish_dsp_value(FREQUENCY_PHASE_R, frequency_phase_r);
publish_dsp_value(FREQUENCY_PHASE_S, frequency_phase_s);
publish_dsp_value(FREQUENCY_PHASE_T, frequency_phase_t);
publish_dsp_value(V_BULK_POSITIVE, v_bulk_positive);
publish_dsp_value(V_BULK_NEGATIVE, v_bulk_negative);
publish_temperature(TEMPERATURE_SUPERVISOR, temperature_supervisor);
publish_temperature(TEMPERATURE_ALIM, temperature_alim);
publish_temperature(TEMPERATURE_HEAT_SINK, temperature_heat_sink);
publish_temperature(TEMPERATURE_1, temperature_1);
publish_temperature(TEMPERATURE_2, temperature_2);
publish_temperature(TEMPERATURE_3, temperature_3);
publish_dsp_value(FAN_SPEED_1, fan_speed_1);
publish_dsp_value(FAN_SPEED_2, fan_speed_2);
publish_dsp_value(FAN_SPEED_3, fan_speed_3);
publish_dsp_value(FAN_SPEED_4, fan_speed_4);
publish_dsp_value(FAN_SPEED_5, fan_speed_5);
publish_dsp_value(POWER_SATURATION_LIMIT, power_saturation_limit);
publish_dsp_value(V_PANEL_MICRO, v_panel_micro);
publish_dsp_value(GRID_VOLTAGE_PHASE_R, grid_voltage_phase_r);
publish_dsp_value(GRID_VOLTAGE_PHASE_S, grid_voltage_phase_s);
publish_dsp_value(GRID_VOLTAGE_PHASE_T, grid_voltage_phase_t);

turn_led_off();
}
Expand All @@ -185,24 +231,18 @@ class InverterMonitor : public PollingComponent
connection = 0;
connection_status->publish_state(DISCONNECTED);
}
ESP_LOGD(TAG, "Inverter not conntected");
ESP_LOGD(TAG, "Inverter not connected");
}
}

void turn_led_on()
{
if (led_state)
return;
led_state = HIGH;
digitalWrite(LED, led_state);
digitalWrite(LED, HIGH);
}

void turn_led_off()
{
if (!led_state)
return;
led_state = LOW;
digitalWrite(LED, led_state);
digitalWrite(LED, LOW);
}
};

Expand Down
Loading