From 9b0acd14f17dd2894d1c355b46c0414303219019 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 15 Mar 2022 17:19:34 +0100 Subject: [PATCH] Add energy column support --- tasmota/xnrg_13_fif_le01mr.ino | 28 +++++++++++++++++-- tasmota/xnrg_18_sdm72.ino | 50 ++++++++++++++++++++++++++++------ tasmota/xnrg_21_sdm230.ino | 34 ++++++++++++++++++++--- 3 files changed, 98 insertions(+), 14 deletions(-) diff --git a/tasmota/xnrg_13_fif_le01mr.ino b/tasmota/xnrg_13_fif_le01mr.ino index 3bc2ebc8a..68aae6c7a 100644 --- a/tasmota/xnrg_13_fif_le01mr.ino +++ b/tasmota/xnrg_13_fif_le01mr.ino @@ -243,8 +243,8 @@ const char HTTP_ENERGY_LE01MR[] PROGMEM = ; #endif // USE_WEBSERVER -void FifLEShow(bool json) -{ +/* +void FifLEShow(bool json) { char total_reactive_chr[FLOATSZ]; dtostrfd(Le01mr.total_reactive, Settings->flag2.energy_resolution, total_reactive_chr); char total_active_chr[FLOATSZ]; @@ -259,6 +259,24 @@ void FifLEShow(bool json) #endif // USE_WEBSERVER } } +*/ + +void FifLEShow(bool json) { + char value_chr[TOPSZ]; + char value2_chr[TOPSZ]; + + if (json) { + ResponseAppend_P(PSTR(",\"" D_JSON_TOTAL_ACTIVE "\":%s,\"" D_JSON_TOTAL_REACTIVE "\":%s"), + EnergyFormat(value_chr, &Le01mr.total_active, Settings->flag2.energy_resolution), + EnergyFormat(value2_chr, &Le01mr.total_reactive, Settings->flag2.energy_resolution)); +#ifdef USE_WEBSERVER + } else { + WSContentSend_PD(HTTP_ENERGY_LE01MR, WebEnergyFormat(value_chr, &Le01mr.total_active, Settings->flag2.energy_resolution), + WebEnergyFormat(value2_chr, &Le01mr.total_reactive, Settings->flag2.energy_resolution)); + +#endif // USE_WEBSERVER + } +} /*********************************************************************************************\ * Interface @@ -276,9 +294,15 @@ bool Xnrg13(uint8_t function) FifLEShow(1); break; #ifdef USE_WEBSERVER +#ifdef USE_ENERGY_COLUMN_GUI + case FUNC_WEB_COL_SENSOR: + FifLEShow(0); + break; +#else // not USE_ENERGY_COLUMN_GUI case FUNC_WEB_SENSOR: FifLEShow(0); break; +#endif // USE_ENERGY_COLUMN_GUI #endif // USE_WEBSERVER case FUNC_ENERGY_RESET: FifLEReset(); diff --git a/tasmota/xnrg_18_sdm72.ino b/tasmota/xnrg_18_sdm72.ino index e13b60a85..ab5c7ce4c 100644 --- a/tasmota/xnrg_18_sdm72.ino +++ b/tasmota/xnrg_18_sdm72.ino @@ -25,6 +25,8 @@ #define XNRG_18 18 +//#define SDM72_IMPEXP + // can be user defined in my_user_config.h #ifndef SDM72_SPEED #define SDM72_SPEED 9600 // default SDM72 Modbus address @@ -148,34 +150,58 @@ void Sdm72DrvInit(void) } } -#ifdef USE_WEBSERVER #ifdef SDM72_IMPEXP + +/* +#ifdef USE_WEBSERVER const char HTTP_ENERGY_SDM72[] PROGMEM = "{s}" D_EXPORT_POWER "{m}%*_f " D_UNIT_WATT "{e}" "{s}" D_IMPORT_POWER "{m}%*_f " D_UNIT_WATT "{e}"; -#endif // SDM72_IMPEXP #endif // USE_WEBSERVER -void Sdm72Show(bool json) -{ +void Sdm72Show(bool json) { if (isnan(Sdm72.total_active)) { return; } if (json) { -#ifdef SDM72_IMPEXP ResponseAppend_P(PSTR(",\"" D_JSON_EXPORT_POWER "\":%*_f,\"" D_JSON_IMPORT_POWER "\":%*_f"), Settings->flag2.wattage_resolution, &Sdm72.export_power, Settings->flag2.wattage_resolution, &Sdm72.import_power); -#endif // SDM72_IMPEXP #ifdef USE_WEBSERVER } else { -#ifdef SDM72_IMPEXP WSContentSend_PD(HTTP_ENERGY_SDM72, Settings->flag2.wattage_resolution, &Sdm72.export_power, Settings->flag2.wattage_resolution, &Sdm72.import_power); -#endif // SDM72_IMPEXP #endif // USE_WEBSERVER } } +*/ + +#ifdef USE_WEBSERVER +const char HTTP_ENERGY_SDM72[] PROGMEM = + "{s}" D_EXPORT_POWER "{m}%s" D_UNIT_WATT "{e}" + "{s}" D_IMPORT_POWER "{m}%s" D_UNIT_WATT "{e}"; +#endif // USE_WEBSERVER + +void Sdm72Show(bool json) { + if (isnan(Sdm72.total_active)) { return; } + + char value_chr[TOPSZ]; + char value2_chr[TOPSZ]; + + if (json) { + ResponseAppend_P(PSTR(",\"" D_JSON_EXPORT_POWER "\":%s,\"" D_JSON_IMPORT_POWER "\":%s"), + EnergyFormat(value_chr, &Sdm72.export_power, Settings->flag2.wattage_resolution), + EnergyFormat(value2_chr, &Sdm72.import_power, Settings->flag2.wattage_resolution)); +#ifdef USE_WEBSERVER + } else { + WSContentSend_PD(HTTP_ENERGY_SDM72, WebEnergyFormat(value_chr, &Sdm72.export_power, Settings->flag2.wattage_resolution), + WebEnergyFormat(value2_chr, &Sdm72.import_power, Settings->flag2.wattage_resolution)); + +#endif // USE_WEBSERVER + } +} + +#endif // SDM72_IMPEXP /*********************************************************************************************\ * Interface @@ -189,14 +215,22 @@ bool Xnrg18(uint8_t function) case FUNC_EVERY_250_MSECOND: Sdm72Every250ms(); break; +#ifdef SDM72_IMPEXP case FUNC_JSON_APPEND: Sdm72Show(1); break; #ifdef USE_WEBSERVER +#ifdef USE_ENERGY_COLUMN_GUI + case FUNC_WEB_COL_SENSOR: + Sdm72Show(0); + break; +#else // not USE_ENERGY_COLUMN_GUI case FUNC_WEB_SENSOR: Sdm72Show(0); break; +#endif // USE_ENERGY_COLUMN_GUI #endif // USE_WEBSERVER +#endif // SDM72_IMPEXP case FUNC_INIT: Sdm72SnsInit(); break; diff --git a/tasmota/xnrg_21_sdm230.ino b/tasmota/xnrg_21_sdm230.ino index e7b28068a..cafe7a031 100644 --- a/tasmota/xnrg_21_sdm230.ino +++ b/tasmota/xnrg_21_sdm230.ino @@ -33,6 +33,8 @@ #define XNRG_21 21 +//#define SDM230_MORE_REGS + // can be user defined in my_user_config.h #ifndef SDM230_SPEED #define SDM230_SPEED 9600 // default SDM230 Modbus baudrate @@ -220,11 +222,9 @@ const char HTTP_ENERGY_SDM230[] PROGMEM = "{s}" D_MAX_POWER "{m}%s " D_UNIT_WATT "{e}" "{s}" D_RESETTABLE_TOTAL_ACTIVE "{m}%s " D_UNIT_KILOWATTHOUR "{e}"; #endif // USE_WEBSERVER -#endif // SDM230_MORE_REGS -#ifdef SDM230_MORE_REGS -void Sdm230Show(bool json) -{ +/* +void Sdm230Show(bool json) { char phase_angle_chr[FLOATSZ]; dtostrfd(Sdm230.phase_angle, 2, phase_angle_chr); char maximum_demand_chr[FLOATSZ]; @@ -241,6 +241,26 @@ void Sdm230Show(bool json) #endif // USE_WEBSERVER } } +*/ + +void Sdm230Show(bool json) { + char value_chr[TOPSZ]; + char value2_chr[TOPSZ]; + char value3_chr[TOPSZ]; + + if (json) { + ResponseAppend_P(PSTR(",\"" D_JSON_PHASE_ANGLE "\":%s,\"" D_JSON_POWERMAX "\":%s,\"" D_JSON_RESETTABLE_TOTAL_ACTIVE "\":%s"), + EnergyFormat(value_chr, &Sdm230.phase_angle, 2), + EnergyFormat(value2_chr, &Sdm230.maximum_total_demand_power_active, Settings->flag2.wattage_resolution), + EnergyFormat(value3_chr, &Sdm230.resettable_total_energy, Settings->flag2.energy_resolution)); +#ifdef USE_WEBSERVER + } else { + WSContentSend_PD(HTTP_ENERGY_SDM230, WebEnergyFormat(value_chr, &Sdm230.phase_angle, 2), + WebEnergyFormat(value2_chr, &Sdm230.maximum_total_demand_power_active, Settings->flag2.wattage_resolution), + WebEnergyFormat(value3_chr, &Sdm230.resettable_total_energy, Settings->flag2.energy_resolution)); +#endif // USE_WEBSERVER + } +} #endif // SDM230_MORE_REGS /*********************************************************************************************\ @@ -260,9 +280,15 @@ bool Xnrg21(uint8_t function) Sdm230Show(1); break; #ifdef USE_WEBSERVER +#ifdef USE_ENERGY_COLUMN_GUI + case FUNC_WEB_COL_SENSOR: + Sdm230Show(0); + break; +#else // not USE_ENERGY_COLUMN_GUI case FUNC_WEB_SENSOR: Sdm230Show(0); break; +#endif // USE_ENERGY_COLUMN_GUI #endif // USE_WEBSERVER #endif // SDM230_MORE_REGS case FUNC_ENERGY_RESET: