Merge pull request #9124 from jkostorz/development

Add option in my_user_config.h to turn on SDM630 import active energy
This commit is contained in:
Theo Arends 2020-10-03 12:33:15 +02:00 committed by GitHub
commit d0028eb2e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 4 deletions

View File

@ -192,6 +192,7 @@
#define D_JSON_PV2_POWER "Pv2Power"
#define D_JSON_SOLAR_POWER "SolarPower"
#define D_JSON_USAGE "Usage"
#define D_JSON_IMPORT "Import"
#define D_JSON_EXPORT "Export"
#define D_JSON_TOTAL_ACTIVE "TotalActive"

View File

@ -652,6 +652,7 @@
#define SDM120_SPEED 2400 // SDM120-Modbus RS485 serial speed (default: 2400 baud)
//#define USE_SDM630 // Add support for Eastron SDM630-Modbus energy monitor (+0k6 code)
#define SDM630_SPEED 9600 // SDM630-Modbus RS485 serial speed (default: 9600 baud)
//#define SDM630_IMPORT // Show import active energy in MQTT and Web (+0k3 code)
//#define USE_DDS2382 // Add support for Hiking DDS2382 Modbus energy monitor (+0k6 code)
#define DDS2382_SPEED 9600 // Hiking DDS2382 Modbus RS485 serial speed (default: 9600 baud)
//#define USE_DDSU666 // Add support for Chint DDSU666 Modbus energy monitor (+0k6 code)

View File

@ -80,7 +80,9 @@ struct ENERGY {
float power_factor[3] = { NAN, NAN, NAN }; // 0.12
float frequency[3] = { NAN, NAN, NAN }; // 123.1 Hz
// float import_active[3] = { NAN, NAN, NAN }; // 123.123 kWh
#ifdef SDM630_IMPORT
float import_active[3] = { NAN, NAN, NAN }; // 123.123 kWh
#endif
float export_active[3] = { NAN, NAN, NAN }; // 123.123 kWh
float start_energy = 0; // 12345.12345 kWh total previous
@ -921,6 +923,11 @@ const char HTTP_ENERGY_SNS2[] PROGMEM =
const char HTTP_ENERGY_SNS3[] PROGMEM =
"{s}" D_EXPORT_ACTIVE "{m}%s " D_UNIT_KILOWATTHOUR "{e}";
#ifdef SDM630_IMPORT
const char HTTP_ENERGY_SNS4[] PROGMEM =
"{s}" D_IMPORT_ACTIVE "{m}%s " D_UNIT_KILOWATTHOUR "{e}";
#endif // SDM630_IMPORT
#endif // USE_WEBSERVER
void EnergyShow(bool json)
@ -985,11 +992,17 @@ void EnergyShow(bool json)
char voltage_chr[Energy.phase_count][FLOATSZ];
char current_chr[Energy.phase_count][FLOATSZ];
char active_power_chr[Energy.phase_count][FLOATSZ];
#ifdef SDM630_IMPORT
char import_active_chr[Energy.phase_count][FLOATSZ];
#endif
char export_active_chr[Energy.phase_count][FLOATSZ];
for (uint32_t i = 0; i < Energy.phase_count; i++) {
dtostrfd(Energy.voltage[i], Settings.flag2.voltage_resolution, voltage_chr[i]);
dtostrfd(Energy.current[i], Settings.flag2.current_resolution, current_chr[i]);
dtostrfd(Energy.active_power[i], Settings.flag2.wattage_resolution, active_power_chr[i]);
#ifdef SDM630_IMPORT
dtostrfd(Energy.import_active[i], Settings.flag2.energy_resolution, import_active_chr[i]);
#endif
dtostrfd(Energy.export_active[i], Settings.flag2.energy_resolution, export_active_chr[i]);
}
@ -1032,6 +1045,17 @@ void EnergyShow(bool json)
energy_yesterday_chr,
energy_daily_chr);
#ifdef SDM630_IMPORT
if (!isnan(Energy.import_active[0])) {
ResponseAppend_P(PSTR(",\"" D_JSON_IMPORT_ACTIVE "\":%s"),
EnergyFormat(value_chr, import_active_chr[0], json));
if (energy_tariff) {
ResponseAppend_P(PSTR(",\"" D_JSON_IMPORT D_CMND_TARIFF "\":%s"),
EnergyFormatIndex(value_chr, energy_return_chr[0], json, 2));
}
}
#endif
if (!isnan(Energy.export_active[0])) {
ResponseAppend_P(PSTR(",\"" D_JSON_EXPORT_ACTIVE "\":%s"),
EnergyFormat(value_chr, export_active_chr[0], json));
@ -1136,6 +1160,11 @@ void EnergyShow(bool json)
if (!isnan(Energy.export_active[0])) {
WSContentSend_PD(HTTP_ENERGY_SNS3, EnergyFormat(value_chr, export_active_chr[0], json));
}
#ifdef SDM630_IMPORT
if (!isnan(Energy.import_active[0])) {
WSContentSend_PD(HTTP_ENERGY_SNS4, EnergyFormat(value_chr, import_active_chr[0], json));
}
#endif
XnrgCall(FUNC_WEB_SENSOR);
#endif // USE_WEBSERVER

View File

@ -60,9 +60,11 @@ const uint16_t sdm630_start_addresses[] {
0x0160, // + + + kWh Phase 1 export active energy
0x0162, // + + + kWh Phase 2 export active energy
0x0164, // + + + kWh Phase 3 export active energy
// 0x015A, // + + + kWh Phase 1 import active energy
// 0x015C, // + + + kWh Phase 2 import active energy
// 0x015E, // + + + kWh Phase 3 import active energy
#ifdef SDM630_IMPORT
0x015A, // + + + kWh Phase 1 import active energy
0x015C, // + + + kWh Phase 2 import active energy
0x015E, // + + + kWh Phase 3 import active energy
#endif
0x0156 // + + + kWh Total active energy
};
@ -177,6 +179,20 @@ void SDM630Every250ms(void)
break;
case 19:
#ifdef SDM630_IMPORT
Energy.import_active[0] = value;
break;
case 20:
Energy.import_active[1] = value;
break;
case 21:
Energy.import_active[2] = value;
break;
case 22:
#endif
EnergyUpdateTotal(value, true);
break;
}