Add energy column support

This commit is contained in:
Theo Arends 2022-03-15 17:19:34 +01:00
parent a14e849858
commit 9b0acd14f1
3 changed files with 98 additions and 14 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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: