refactor how values are rendered to screen and to json. added space before suffix

This commit is contained in:
proddy
2020-10-07 19:16:21 +02:00
parent 442349fa33
commit f6da8d7406
9 changed files with 345 additions and 297 deletions

View File

@@ -165,7 +165,7 @@ class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesF
{sensorData.id} {sensorData.id}
</TableCell> </TableCell>
<TableCell align="right"> <TableCell align="right">
{sensorData.temp.toFixed(1)}&deg;C {sensorData.temp.toFixed(1)}&nbsp;&deg;C
</TableCell> </TableCell>
</TableRow> </TableRow>
))} ))}
@@ -284,12 +284,12 @@ class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesF
</TableHead> </TableHead>
<TableBody> <TableBody>
{deviceData.deviceData.map(deviceData => ( {deviceData.deviceData.map(deviceData => (
<TableRow key={deviceData.name}> <TableRow key={deviceData.n}>
<TableCell component="th" scope="row"> <TableCell component="th" scope="row">
{deviceData.name} {deviceData.n}
</TableCell> </TableCell>
<TableCell align="right"> <TableCell align="right">
{deviceData.value} {deviceData.v}
</TableCell> </TableCell>
</TableRow> </TableRow>
))} ))}

View File

@@ -167,68 +167,73 @@ void Boiler::register_mqtt_ha_config() {
// send stuff to the Web UI // send stuff to the Web UI
void Boiler::device_info_web(JsonArray & root) { void Boiler::device_info_web(JsonArray & root) {
JsonObject dataElement; // fetch the values into a JSON document
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_LARGE> doc;
JsonObject output = doc.to<JsonObject>();
if (!export_values(output)) {
return; // empty
}
render_value_json(root, "", F_(heatingActive), heatingActive_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("heatingActive"), nullptr, F_(heatingActive), nullptr, output);
render_value_json(root, "", F_(tapwaterActive), tapwaterActive_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("tapwaterActive"), nullptr, F_(tapwaterActive), nullptr, output);
render_value_json(root, "", F_(serviceCode), serviceCode_, nullptr); print_value_json(root, F("serviceCode"), nullptr, F_(serviceCode), nullptr, output);
render_value_json(root, "", F_(serviceCodeNumber), serviceCodeNumber_, nullptr); print_value_json(root, F("serviceCodeNumber"), nullptr, F_(serviceCodeNumber), nullptr, output);
render_value_json(root, "", F_(wWSelTemp), wWSelTemp_, F_(degrees)); print_value_json(root, F("wWSelTemp"), nullptr, F_(wWSelTemp), F_(degrees), output);
render_value_json(root, "", F_(wWSetTemp), wWSetTemp_, F_(degrees)); print_value_json(root, F("wWSetTemp"), nullptr, F_(wWSetTemp), F_(degrees), output);
render_value_json(root, "", F_(wWDisinfectionTemp), wWDisinfectionTemp_, F_(degrees)); print_value_json(root, F("wWDisinfectionTemp"), nullptr, F_(wWDisinfectionTemp), F_(degrees), output);
render_value_json(root, "", F_(selFlowTemp), selFlowTemp_, F_(degrees)); print_value_json(root, F("selFlowTemp"), nullptr, F_(selFlowTemp), F_(degrees), output);
render_value_json(root, "", F_(selBurnPow), selBurnPow_, F_(percent)); print_value_json(root, F("selBurnPow"), nullptr, F_(selBurnPow), F_(percent), output);
render_value_json(root, "", F_(curBurnPow), curBurnPow_, F_(percent)); print_value_json(root, F("curBurnPow"), nullptr, F_(curBurnPow), F_(percent), output);
render_value_json(root, "", F_(pumpMod), pumpMod_, F_(percent)); print_value_json(root, F("pumpMod"), nullptr, F_(pumpMod), F_(percent), output);
render_value_json(root, "", F_(pumpMod2), pumpMod2_, F_(percent)); print_value_json(root, F("pumpMod2"), nullptr, F_(pumpMod2), F_(percent), output);
render_value_json(root, "", F_(wWType), wWType_, nullptr); print_value_json(root, F("wWType"), nullptr, F_(wWType), nullptr, output);
render_value_json(root, "", F_(wWChargeType), wWChargeType_, nullptr); print_value_json(root, F("wWChargeType"), nullptr, F_(wWChargeType), nullptr, output);
render_value_json(root, "", F_(wWCircPump), wWCircPump_, nullptr); print_value_json(root, F("wWCircPump"), nullptr, F_(wWCircPump), nullptr, output);
render_value_json(root, "", F_(wWCircPumpMode), wWCircPumpMode_, nullptr); print_value_json(root, F("wWCircPumpMode"), nullptr, F_(wWCircPumpMode), nullptr, output);
render_value_json(root, "", F_(wWCirc), wWCirc_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("wWCirc"), nullptr, F_(wWCirc), nullptr, output);
render_value_json(root, "", F_(outdoorTemp), outdoorTemp_, F_(degrees), 10); print_value_json(root, F("outdoorTemp"), nullptr, F_(outdoorTemp), F_(degrees), output);
render_value_json(root, "", F_(wWCurTemp), wWCurTemp_, F_(degrees), 10); print_value_json(root, F("wWCurTemp"), nullptr, F_(wWCurTemp), F_(degrees), output);
render_value_json(root, "", F_(wWCurTemp2), wWCurTemp2_, F_(degrees), 10); print_value_json(root, F("wWCurTemp2"), nullptr, F_(wWCurTemp2), F_(degrees), output);
render_value_json(root, "", F_(wWCurFlow), wWCurFlow_, F("l/min"), 10); print_value_json(root, F("wWCurFlow"), nullptr, F_(wWCurFlow), F("l/min"), output);
render_value_json(root, "", F_(curFlowTemp), curFlowTemp_, F_(degrees), 10); print_value_json(root, F("curFlowTemp"), nullptr, F_(curFlowTemp), F_(degrees), output);
render_value_json(root, "", F_(retTemp), retTemp_, F_(degrees), 10); print_value_json(root, F("retTemp"), nullptr, F_(retTemp), F_(degrees), output);
render_value_json(root, "", F_(switchTemp), switchTemp_, F_(degrees), 10); print_value_json(root, F("switchTemp"), nullptr, F_(switchTemp), F_(degrees), output);
render_value_json(root, "", F_(sysPress), sysPress_, F_(bar), 10); print_value_json(root, F("sysPress"), nullptr, F_(sysPress), nullptr, output);
render_value_json(root, "", F_(boilTemp), boilTemp_, F_(degrees), 10); print_value_json(root, F("boilTemp"), nullptr, F_(boilTemp), F_(degrees), output);
render_value_json(root, "", F_(wwStorageTemp1), wwStorageTemp1_, F_(degrees), 10); print_value_json(root, F("wwStorageTemp1"), nullptr, F_(wwStorageTemp1), F_(degrees), output);
render_value_json(root, "", F_(wwStorageTemp2), wwStorageTemp2_, F_(degrees), 10); print_value_json(root, F("wwStorageTemp2"), nullptr, F_(wwStorageTemp2), F_(degrees), output);
render_value_json(root, "", F_(exhaustTemp), exhaustTemp_, F_(degrees), 10); print_value_json(root, F("exhaustTemp"), nullptr, F_(exhaustTemp), F_(degrees), output);
render_value_json(root, "", F_(wWActivated), wWActivated_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("wWActivated"), nullptr, F_(wWActivated), nullptr, output);
render_value_json(root, "", F_(wWOneTime), wWOneTime_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("wWOneTime"), nullptr, F_(wWOneTime), nullptr, output);
render_value_json(root, "", F_(wWDisinfecting), wWDisinfecting_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("wWDisinfecting"), nullptr, F_(wWDisinfecting), nullptr, output);
render_value_json(root, "", F_(wWCharging), wWCharging_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("wWCharging"), nullptr, F_(wWCharging), nullptr, output);
render_value_json(root, "", F_(wWRecharging), wWRecharging_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("wWRecharging"), nullptr, F_(wWRecharging), nullptr, output);
render_value_json(root, "", F_(wWTempOK), wWTempOK_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("wWTempOK"), nullptr, F_(wWTempOK), nullptr, output);
render_value_json(root, "", F_(wWActive), wWActive_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("wWActive"), nullptr, F_(wWActive), nullptr, output);
render_value_json(root, "", F_(burnGas), burnGas_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("burnGas"), nullptr, F_(burnGas), nullptr, output);
render_value_json(root, "", F_(flameCurr), flameCurr_, F_(uA), 10); print_value_json(root, F("flameCurr"), nullptr, F_(flameCurr), F_(uA), output);
render_value_json(root, "", F_(heatPump), heatPump_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("heatPump"), nullptr, F_(heatPump), nullptr, output);
render_value_json(root, "", F_(fanWork), fanWork_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("fanWork"), nullptr, F_(fanWork), nullptr, output);
render_value_json(root, "", F_(ignWork), ignWork_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("ignWork"), nullptr, F_(ignWork), nullptr, output);
render_value_json(root, "", F_(wWHeat), wWHeat_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("wWHeat"), nullptr, F_(wWHeat), nullptr, output);
render_value_json(root, "", F_(heatingActivated), heatingActivated_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("heatingActivated"), nullptr, F_(heatingActivated), nullptr, output);
render_value_json(root, "", F_(heatingTemp), heatingTemp_, F_(degrees)); print_value_json(root, F("heatingTemp"), nullptr, F_(heatingTemp), F_(degrees), output);
render_value_json(root, "", F_(pumpModMax), pumpModMax_, F_(percent)); print_value_json(root, F("pumpModMax"), nullptr, F_(pumpModMax), F_(percent), output);
render_value_json(root, "", F_(pumpModMin), pumpModMin_, F_(percent)); print_value_json(root, F("pumpModMin"), nullptr, F_(pumpModMin), F_(percent), output);
render_value_json(root, "", F_(pumpDelay), pumpDelay_, F_(min)); print_value_json(root, F("pumpDelay"), nullptr, F_(pumpDelay), F_(min), output);
render_value_json(root, "", F_(burnMinPeriod), burnMinPeriod_, F_(min)); print_value_json(root, F("burnMinPeriod"), nullptr, F_(burnMinPeriod), F_(min), output);
render_value_json(root, "", F_(burnMinPower), burnMinPower_, F_(percent)); print_value_json(root, F("burnMinPower"), nullptr, F_(burnMinPower), F_(percent), output);
render_value_json(root, "", F_(burnMaxPower), burnMaxPower_, F_(percent)); print_value_json(root, F("burnMaxPower"), nullptr, F_(burnMaxPower), F_(percent), output);
render_value_json(root, "", F_(boilHystOn), boilHystOn_, F_(degrees)); print_value_json(root, F("boilHystOn"), nullptr, F_(boilHystOn), F_(degrees), output);
render_value_json(root, "", F_(boilHystOff), boilHystOff_, F_(degrees)); print_value_json(root, F("boilHystOff"), nullptr, F_(boilHystOff), F_(degrees), output);
render_value_json(root, "", F_(setFlowTemp), setFlowTemp_, F_(degrees)); print_value_json(root, F("setFlowTemp"), nullptr, F_(setFlowTemp), F_(degrees), output);
render_value_json(root, "", F_(wWSetPumpPower), wWSetPumpPower_, F_(percent)); print_value_json(root, F("wWSetPumpPower"), nullptr, F_(wWSetPumpPower), F_(percent), output);
render_value_json(root, "", F_(wwMixTemperature), wwMixTemperature_, F_(degrees)); print_value_json(root, F("wwMixTemperature"), nullptr, F_(wwMixTemperature), F_(degrees), output);
render_value_json(root, "", F_(wwBufferBoilerTemperature), wwBufferBoilerTemperature_, F_(degrees)); print_value_json(root, F("wwBufferBoilerTemperature"), nullptr, F_(wwBufferBoilerTemperature), F_(degrees), output);
render_value_json(root, "", F_(wWStarts), wWStarts_, nullptr); print_value_json(root, F("wWStarts"), nullptr, F_(wWStarts), nullptr, output);
render_value_json(root, "", F_(wWWorkM), wWWorkM_, nullptr); print_value_json(root, F("wWWorkM"), nullptr, F_(wWWorkM), nullptr, output);
render_value_json(root, "", F_(setBurnPow), setBurnPow_, F_(percent)); print_value_json(root, F("setBurnPow"), nullptr, F_(setBurnPow), F_(percent), output);
render_value_json(root, "", F_(burnStarts), burnStarts_, nullptr); print_value_json(root, F("burnStarts"), nullptr, F_(burnStarts), nullptr, output);
} }
bool Boiler::command_info(const char * value, const int8_t id, JsonObject & output) { bool Boiler::command_info(const char * value, const int8_t id, JsonObject & output) {
@@ -623,66 +628,66 @@ void Boiler::show_values(uuid::console::Shell & shell) {
return; // empty return; // empty
} }
print_value_json(shell, F("heatingActive"), F_(heatingActive), nullptr, output); print_value_json(shell, F("heatingActive"), nullptr, F_(heatingActive), nullptr, output);
print_value_json(shell, F("tapwaterActive"), F_(tapwaterActive), nullptr, output); print_value_json(shell, F("tapwaterActive"), nullptr, F_(tapwaterActive), nullptr, output);
print_value_json(shell, F("serviceCode"), F_(serviceCode), nullptr, output); print_value_json(shell, F("serviceCode"), nullptr, F_(serviceCode), nullptr, output);
print_value_json(shell, F("serviceCodeNumber"), F_(serviceCodeNumber), nullptr, output); print_value_json(shell, F("serviceCodeNumber"), nullptr, F_(serviceCodeNumber), nullptr, output);
print_value_json(shell, F("wWSelTemp"), F_(wWSelTemp), F_(degrees), output); print_value_json(shell, F("wWSelTemp"), nullptr, F_(wWSelTemp), F_(degrees), output);
print_value_json(shell, F("wWSetTemp"), F_(wWSetTemp), F_(degrees), output); print_value_json(shell, F("wWSetTemp"), nullptr, F_(wWSetTemp), F_(degrees), output);
print_value_json(shell, F("wWDisinfectionTemp"), F_(wWDisinfectionTemp), F_(degrees), output); print_value_json(shell, F("wWDisinfectionTemp"), nullptr, F_(wWDisinfectionTemp), F_(degrees), output);
print_value_json(shell, F("selFlowTemp"), F_(selFlowTemp), F_(degrees), output); print_value_json(shell, F("selFlowTemp"), nullptr, F_(selFlowTemp), F_(degrees), output);
print_value_json(shell, F("selBurnPow"), F_(selBurnPow), F_(percent), output); print_value_json(shell, F("selBurnPow"), nullptr, F_(selBurnPow), F_(percent), output);
print_value_json(shell, F("curBurnPow"), F_(curBurnPow), F_(percent), output); print_value_json(shell, F("curBurnPow"), nullptr, F_(curBurnPow), F_(percent), output);
print_value_json(shell, F("pumpMod"), F_(pumpMod), F_(percent), output); print_value_json(shell, F("pumpMod"), nullptr, F_(pumpMod), F_(percent), output);
print_value_json(shell, F("pumpMod2"), F_(pumpMod2), F_(percent), output); print_value_json(shell, F("pumpMod2"), nullptr, F_(pumpMod2), F_(percent), output);
print_value_json(shell, F("wWType"), F_(wWType), nullptr, output); print_value_json(shell, F("wWType"), nullptr, F_(wWType), nullptr, output);
print_value_json(shell, F("wWChargeType"), F_(wWChargeType), nullptr, output); print_value_json(shell, F("wWChargeType"), nullptr, F_(wWChargeType), nullptr, output);
print_value_json(shell, F("wWCircPump"), F_(wWCircPump), nullptr, output); print_value_json(shell, F("wWCircPump"), nullptr, F_(wWCircPump), nullptr, output);
print_value_json(shell, F("wWCircPumpMode"), F_(wWCircPumpMode), nullptr, output); print_value_json(shell, F("wWCircPumpMode"), nullptr, F_(wWCircPumpMode), nullptr, output);
print_value_json(shell, F("wWCirc"), F_(wWCirc), nullptr, output); print_value_json(shell, F("wWCirc"), nullptr, F_(wWCirc), nullptr, output);
print_value_json(shell, F("outdoorTemp"), F_(outdoorTemp), F_(degrees), output); print_value_json(shell, F("outdoorTemp"), nullptr, F_(outdoorTemp), F_(degrees), output);
print_value_json(shell, F("wWCurTemp"), F_(wWCurTemp), F_(degrees), output); print_value_json(shell, F("wWCurTemp"), nullptr, F_(wWCurTemp), F_(degrees), output);
print_value_json(shell, F("wWCurTemp2"), F_(wWCurTemp2), F_(degrees), output); print_value_json(shell, F("wWCurTemp2"), nullptr, F_(wWCurTemp2), F_(degrees), output);
print_value_json(shell, F("wWCurFlow"), F_(wWCurFlow), F("l/min"), output); print_value_json(shell, F("wWCurFlow"), nullptr, F_(wWCurFlow), F("l/min"), output);
print_value_json(shell, F("curFlowTemp"), F_(curFlowTemp), F_(degrees), output); print_value_json(shell, F("curFlowTemp"), nullptr, F_(curFlowTemp), F_(degrees), output);
print_value_json(shell, F("retTemp"), F_(retTemp), F_(degrees), output); print_value_json(shell, F("retTemp"), nullptr, F_(retTemp), F_(degrees), output);
print_value_json(shell, F("switchTemp"), F_(switchTemp), F_(degrees), output); print_value_json(shell, F("switchTemp"), nullptr, F_(switchTemp), F_(degrees), output);
print_value_json(shell, F("sysPress"), F_(sysPress), nullptr, output); print_value_json(shell, F("sysPress"), nullptr, F_(sysPress), nullptr, output);
print_value_json(shell, F("boilTemp"), F_(boilTemp), F_(degrees), output); print_value_json(shell, F("boilTemp"), nullptr, F_(boilTemp), F_(degrees), output);
print_value_json(shell, F("wwStorageTemp1"), F_(wwStorageTemp1), F_(degrees), output); print_value_json(shell, F("wwStorageTemp1"), nullptr, F_(wwStorageTemp1), F_(degrees), output);
print_value_json(shell, F("wwStorageTemp2"), F_(wwStorageTemp2), F_(degrees), output); print_value_json(shell, F("wwStorageTemp2"), nullptr, F_(wwStorageTemp2), F_(degrees), output);
print_value_json(shell, F("exhaustTemp"), F_(exhaustTemp), F_(degrees), output); print_value_json(shell, F("exhaustTemp"), nullptr, F_(exhaustTemp), F_(degrees), output);
print_value_json(shell, F("wWActivated"), F_(wWActivated), nullptr, output); print_value_json(shell, F("wWActivated"), nullptr, F_(wWActivated), nullptr, output);
print_value_json(shell, F("wWOneTime"), F_(wWOneTime), nullptr, output); print_value_json(shell, F("wWOneTime"), nullptr, F_(wWOneTime), nullptr, output);
print_value_json(shell, F("wWDisinfecting"), F_(wWDisinfecting), nullptr, output); print_value_json(shell, F("wWDisinfecting"), nullptr, F_(wWDisinfecting), nullptr, output);
print_value_json(shell, F("wWCharging"), F_(wWCharging), nullptr, output); print_value_json(shell, F("wWCharging"), nullptr, F_(wWCharging), nullptr, output);
print_value_json(shell, F("wWRecharging"), F_(wWRecharging), nullptr, output); print_value_json(shell, F("wWRecharging"), nullptr, F_(wWRecharging), nullptr, output);
print_value_json(shell, F("wWTempOK"), F_(wWTempOK), nullptr, output); print_value_json(shell, F("wWTempOK"), nullptr, F_(wWTempOK), nullptr, output);
print_value_json(shell, F("wWActive"), F_(wWActive), nullptr, output); print_value_json(shell, F("wWActive"), nullptr, F_(wWActive), nullptr, output);
print_value_json(shell, F("burnGas"), F_(burnGas), nullptr, output); print_value_json(shell, F("burnGas"), nullptr, F_(burnGas), nullptr, output);
print_value_json(shell, F("flameCurr"), F_(flameCurr), F_(uA), output); print_value_json(shell, F("flameCurr"), nullptr, F_(flameCurr), F_(uA), output);
print_value_json(shell, F("heatPump"), F_(heatPump), nullptr, output); print_value_json(shell, F("heatPump"), nullptr, F_(heatPump), nullptr, output);
print_value_json(shell, F("fanWork"), F_(fanWork), nullptr, output); print_value_json(shell, F("fanWork"), nullptr, F_(fanWork), nullptr, output);
print_value_json(shell, F("ignWork"), F_(ignWork), nullptr, output); print_value_json(shell, F("ignWork"), nullptr, F_(ignWork), nullptr, output);
print_value_json(shell, F("wWHeat"), F_(wWHeat), nullptr, output); print_value_json(shell, F("wWHeat"), nullptr, F_(wWHeat), nullptr, output);
print_value_json(shell, F("heatingActivated"), F_(heatingActivated), nullptr, output); print_value_json(shell, F("heatingActivated"), nullptr, F_(heatingActivated), nullptr, output);
print_value_json(shell, F("heatingTemp"), F_(heatingTemp), F_(degrees), output); print_value_json(shell, F("heatingTemp"), nullptr, F_(heatingTemp), F_(degrees), output);
print_value_json(shell, F("pumpModMax"), F_(pumpModMax), F_(percent), output); print_value_json(shell, F("pumpModMax"), nullptr, F_(pumpModMax), F_(percent), output);
print_value_json(shell, F("pumpModMin"), F_(pumpModMin), F_(percent), output); print_value_json(shell, F("pumpModMin"), nullptr, F_(pumpModMin), F_(percent), output);
print_value_json(shell, F("pumpDelay"), F_(pumpDelay), F_(min), output); print_value_json(shell, F("pumpDelay"), nullptr, F_(pumpDelay), F_(min), output);
print_value_json(shell, F("burnMinPeriod"), F_(burnMinPeriod), F_(min), output); print_value_json(shell, F("burnMinPeriod"), nullptr, F_(burnMinPeriod), F_(min), output);
print_value_json(shell, F("burnMinPower"), F_(burnMinPower), F_(percent), output); print_value_json(shell, F("burnMinPower"), nullptr, F_(burnMinPower), F_(percent), output);
print_value_json(shell, F("burnMaxPower"), F_(burnMaxPower), F_(percent), output); print_value_json(shell, F("burnMaxPower"), nullptr, F_(burnMaxPower), F_(percent), output);
print_value_json(shell, F("boilHystOn"), F_(boilHystOn), F_(degrees), output); print_value_json(shell, F("boilHystOn"), nullptr, F_(boilHystOn), F_(degrees), output);
print_value_json(shell, F("boilHystOff"), F_(boilHystOff), F_(degrees), output); print_value_json(shell, F("boilHystOff"), nullptr, F_(boilHystOff), F_(degrees), output);
print_value_json(shell, F("setFlowTemp"), F_(setFlowTemp), F_(degrees), output); print_value_json(shell, F("setFlowTemp"), nullptr, F_(setFlowTemp), F_(degrees), output);
print_value_json(shell, F("wWSetPumpPower"), F_(wWSetPumpPower), F_(percent), output); print_value_json(shell, F("wWSetPumpPower"), nullptr, F_(wWSetPumpPower), F_(percent), output);
print_value_json(shell, F("wwMixTemperature"), F_(wwMixTemperature), F_(degrees), output); print_value_json(shell, F("wwMixTemperature"), nullptr, F_(wwMixTemperature), F_(degrees), output);
print_value_json(shell, F("wwBufferBoilerTemperature"), F_(wwBufferBoilerTemperature), F_(degrees), output); print_value_json(shell, F("wwBufferBoilerTemperature"), nullptr, F_(wwBufferBoilerTemperature), F_(degrees), output);
print_value_json(shell, F("wWStarts"), F_(wWStarts), nullptr, output); print_value_json(shell, F("wWStarts"), nullptr, F_(wWStarts), nullptr, output);
print_value_json(shell, F("wWWorkM"), F_(wWWorkM), nullptr, output); print_value_json(shell, F("wWWorkM"), nullptr, F_(wWWorkM), nullptr, output);
print_value_json(shell, F("setBurnPow"), F_(setBurnPow), F_(percent), output); print_value_json(shell, F("setBurnPow"), nullptr, F_(setBurnPow), F_(percent), output);
print_value_json(shell, F("burnStarts"), F_(burnStarts), nullptr, output); print_value_json(shell, F("burnStarts"), nullptr, F_(burnStarts), nullptr, output);
if (Helpers::hasValue(wWWorkM_)) { if (Helpers::hasValue(wWWorkM_)) {
shell.printfln(F(" Warm Water active time: %d days %d hours %d minutes"), wWWorkM_ / 1440, (wWWorkM_ % 1440) / 60, wWWorkM_ % 60); shell.printfln(F(" Warm Water active time: %d days %d hours %d minutes"), wWWorkM_ / 1440, (wWWorkM_ % 1440) / 60, wWWorkM_ % 60);

View File

@@ -66,18 +66,25 @@ void Mixing::device_info_web(JsonArray & root) {
return; // don't have any values yet return; // don't have any values yet
} }
// fetch the values into a JSON document
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> doc;
JsonObject output = doc.to<JsonObject>();
if (!export_values(output)) {
return; // empty
}
char prefix_str[10];
if (type() == Type::WWC) { if (type() == Type::WWC) {
render_value_json(root, "", F("Warm Water Circuit"), hc_, nullptr); snprintf_P(prefix_str, sizeof(prefix_str), PSTR("(wwc %d) "), hc_);
render_value_json(root, "", F("Current warm water temperature"), flowTemp_, F_(degrees), 10); print_value_json(root, F("wwTemp"), FPSTR(prefix_str), F_(wwTemp), F_(degrees), output);
render_value_json(root, "", F("Current pump status"), pump_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("pumpStatus"), FPSTR(prefix_str), F_(pumpStatus), nullptr, output);
render_value_json(root, "", F("Current temperature status"), status_, nullptr); print_value_json(root, F("tempStatus"), FPSTR(prefix_str), F_(tempStatus), nullptr, output);
} else { } else {
// HC snprintf_P(prefix_str, sizeof(prefix_str), PSTR("(hc %d) "), hc_);
render_value_json(root, "", F("Heating Circuit"), hc_, nullptr); print_value_json(root, F("flowTemp"), FPSTR(prefix_str), F_(flowTemp), F_(degrees), output);
render_value_json(root, "", F("Current flow temperature"), flowTemp_, F_(degrees), 10); print_value_json(root, F("flowSetTemp"), FPSTR(prefix_str), F_(flowSetTemp), F_(degrees), output);
render_value_json(root, "", F("Setpoint flow temperature"), flowSetTemp_, F_(degrees)); print_value_json(root, F("pumpStatus"), FPSTR(prefix_str), F_(pumpStatus), nullptr, output);
render_value_json(root, "", F("Current pump status"), pump_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("valveStatus"), FPSTR(prefix_str), F_(valveStatus), F_(percent), output);
render_value_json(root, "", F("Current valve status"), status_, F_(percent));
} }
} }
@@ -107,15 +114,15 @@ void Mixing::show_values(uuid::console::Shell & shell) {
if (type() == Type::WWC) { if (type() == Type::WWC) {
shell.println(F_(ww_hc)); shell.println(F_(ww_hc));
print_value_json(shell, F("wwTemp"), F_(wwTemp), F_(degrees), output); print_value_json(shell, F("wwTemp"), nullptr, F_(wwTemp), F_(degrees), output);
print_value_json(shell, F("pumpStatus"), F_(pumpStatus), nullptr, output); print_value_json(shell, F("pumpStatus"), nullptr, F_(pumpStatus), nullptr, output);
print_value_json(shell, F("tempStatus"), F_(tempStatus), nullptr, output); print_value_json(shell, F("tempStatus"), nullptr, F_(tempStatus), nullptr, output);
} else { } else {
shell.println(F_(hc)); shell.println(F_(hc));
print_value_json(shell, F("flowTemp"), F_(flowTemp), F_(degrees), output); print_value_json(shell, F("flowTemp"), nullptr, F_(flowTemp), F_(degrees), output);
print_value_json(shell, F("flowSetTemp"), F_(flowSetTemp), F_(degrees), output); print_value_json(shell, F("flowSetTemp"), nullptr, F_(flowSetTemp), F_(degrees), output);
print_value_json(shell, F("pumpStatus"), F_(pumpStatus), nullptr, output); print_value_json(shell, F("pumpStatus"), nullptr, F_(pumpStatus), nullptr, output);
print_value_json(shell, F("valveStatus"), F_(valveStatus), F_(percent), output); print_value_json(shell, F("valveStatus"), nullptr, F_(valveStatus), F_(percent), output);
} }
shell.println(); shell.println();
@@ -192,9 +199,9 @@ bool Mixing::export_values(JsonObject & output) {
if (Helpers::hasValue(flowSetTemp_)) { if (Helpers::hasValue(flowSetTemp_)) {
output["flowSetTemp"] = flowSetTemp_; output["flowSetTemp"] = flowSetTemp_;
} }
if (Helpers::hasValue(pump_)) { if (Helpers::hasValue(pumpStatus_)) {
char s[5]; // for formatting strings char s[5]; // for formatting strings
output["pumpStatus"] = Helpers::render_value(s, pump_, EMS_VALUE_BOOL); output["pumpStatus"] = Helpers::render_value(s, pumpStatus_, EMS_VALUE_BOOL);
} }
if (Helpers::hasValue(status_)) { if (Helpers::hasValue(status_)) {
output["valveStatus"] = status_; output["valveStatus"] = status_;
@@ -206,9 +213,9 @@ bool Mixing::export_values(JsonObject & output) {
if (Helpers::hasValue(flowTemp_)) { if (Helpers::hasValue(flowTemp_)) {
output["wwTemp"] = (float)flowTemp_ / 10; output["wwTemp"] = (float)flowTemp_ / 10;
} }
if (Helpers::hasValue(pump_)) { if (Helpers::hasValue(pumpStatus_)) {
char s[5]; // for formatting strings char s[5]; // for formatting strings
output["pumpStatus"] = Helpers::render_value(s, pump_, EMS_VALUE_BOOL); output["pumpStatus"] = Helpers::render_value(s, pumpStatus_, EMS_VALUE_BOOL);
} }
if (Helpers::hasValue(status_)) { if (Helpers::hasValue(status_)) {
output["tempStatus"] = status_; output["tempStatus"] = status_;
@@ -232,7 +239,7 @@ void Mixing::process_MMPLUSStatusMessage_HC(std::shared_ptr<const Telegram> tele
hc_ = telegram->type_id - 0x02D7 + 1; // determine which circuit this is hc_ = telegram->type_id - 0x02D7 + 1; // determine which circuit this is
changed_ |= telegram->read_value(flowTemp_, 3); // is * 10 changed_ |= telegram->read_value(flowTemp_, 3); // is * 10
changed_ |= telegram->read_value(flowSetTemp_, 5); changed_ |= telegram->read_value(flowSetTemp_, 5);
changed_ |= telegram->read_bitvalue(pump_, 2, 0); changed_ |= telegram->read_bitvalue(pumpStatus_, 2, 0);
changed_ |= telegram->read_value(status_, 2); // valve status changed_ |= telegram->read_value(status_, 2); // valve status
} }
@@ -243,7 +250,7 @@ void Mixing::process_MMPLUSStatusMessage_WWC(std::shared_ptr<const Telegram> tel
type(Type::WWC); type(Type::WWC);
hc_ = telegram->type_id - 0x0331 + 1; // determine which circuit this is. There are max 2. hc_ = telegram->type_id - 0x0331 + 1; // determine which circuit this is. There are max 2.
changed_ |= telegram->read_value(flowTemp_, 0); // is * 10 changed_ |= telegram->read_value(flowTemp_, 0); // is * 10
changed_ |= telegram->read_bitvalue(pump_, 2, 0); changed_ |= telegram->read_bitvalue(pumpStatus_, 2, 0);
changed_ |= telegram->read_value(status_, 11); // temp status changed_ |= telegram->read_value(status_, 11); // temp status
} }
@@ -265,7 +272,7 @@ void Mixing::process_IPMStatusMessage(std::shared_ptr<const Telegram> telegram)
changed_ |= telegram->read_value(status_, 2); // valve status changed_ |= telegram->read_value(status_, 2); // valve status
} }
changed_ |= telegram->read_bitvalue(pump_, 1, 0); // pump is also in unmixed circuits changed_ |= telegram->read_bitvalue(pumpStatus_, 1, 0); // pump is also in unmixed circuits
} }
// Mixing on a MM10 - 0xAB // Mixing on a MM10 - 0xAB
@@ -279,7 +286,7 @@ void Mixing::process_MMStatusMessage(std::shared_ptr<const Telegram> telegram) {
// see https://github.com/proddy/EMS-ESP/issues/270 and https://github.com/proddy/EMS-ESP/issues/386#issuecomment-629610918 // see https://github.com/proddy/EMS-ESP/issues/270 and https://github.com/proddy/EMS-ESP/issues/386#issuecomment-629610918
hc_ = device_id() - 0x20 + 1; hc_ = device_id() - 0x20 + 1;
changed_ |= telegram->read_value(flowTemp_, 1); // is * 10 changed_ |= telegram->read_value(flowTemp_, 1); // is * 10
changed_ |= telegram->read_bitvalue(pump_, 3, 0); changed_ |= telegram->read_bitvalue(pumpStatus_, 3, 0);
changed_ |= telegram->read_value(flowSetTemp_, 0); changed_ |= telegram->read_value(flowSetTemp_, 0);
changed_ |= telegram->read_value(status_, 4); // valve status -100 to 100 changed_ |= telegram->read_value(status_, 4); // valve status -100 to 100
} }

View File

@@ -72,7 +72,7 @@ class Mixing : public EMSdevice {
private: private:
uint16_t hc_ = EMS_VALUE_USHORT_NOTSET; uint16_t hc_ = EMS_VALUE_USHORT_NOTSET;
uint16_t flowTemp_ = EMS_VALUE_USHORT_NOTSET; uint16_t flowTemp_ = EMS_VALUE_USHORT_NOTSET;
uint8_t pump_ = EMS_VALUE_UINT_NOTSET; uint8_t pumpStatus_ = EMS_VALUE_UINT_NOTSET;
int8_t status_ = EMS_VALUE_UINT_NOTSET; int8_t status_ = EMS_VALUE_UINT_NOTSET;
uint8_t flowSetTemp_ = EMS_VALUE_UINT_NOTSET; uint8_t flowSetTemp_ = EMS_VALUE_UINT_NOTSET;
Type type_ = Type::NONE; Type type_ = Type::NONE;

View File

@@ -60,27 +60,33 @@ bool Solar::command_info(const char * value, const int8_t id, JsonObject & outpu
// print to web // print to web
void Solar::device_info_web(JsonArray & root) { void Solar::device_info_web(JsonArray & root) {
render_value_json(root, "", F_(collectorTemp), collectorTemp_, F_(degrees), 10); // fetch the values into a JSON document
render_value_json(root, "", F_(tankBottomTemp), tankBottomTemp_, F_(degrees), 10); StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> doc;
render_value_json(root, "", F_(tankBottomTemp2), tankBottomTemp2_, F_(degrees), 10); JsonObject output = doc.to<JsonObject>();
render_value_json(root, "", F_(heatExchangerTemp), heatExchangerTemp_, F_(degrees), 10); if (!export_values(output)) {
render_value_json(root, "", F_(solarPumpModulation), solarPumpModulation_, F_(percent)); return; // empty
render_value_json(root, "", F_(cylinderPumpModulation), cylinderPumpModulation_, F_(percent)); }
render_value_json(root, "", F_(valveStatus), valveStatus_, nullptr, EMS_VALUE_BOOL);
render_value_json(root, "", F_(solarPump), solarPump_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("collectorTemp"), nullptr, F_(collectorTemp), F_(degrees), output);
render_value_json(root, "", F_(tankHeated), tankHeated_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("tankBottomTemp"), nullptr, F_(tankBottomTemp), F_(degrees), output);
render_value_json(root, "", F_(collectorShutdown), collectorShutdown_, nullptr, EMS_VALUE_BOOL); print_value_json(root, F("tankBottomTemp2"), nullptr, F_(tankBottomTemp2), F_(degrees), output);
render_value_json(root, "", F_(energyLastHour), energyLastHour_, F_(wh), 10); print_value_json(root, F("heatExchangerTemp"), nullptr, F_(heatExchangerTemp), F_(degrees), output);
render_value_json(root, "", F_(energyToday), energyToday_, F_(wh)); print_value_json(root, F("solarPumpModulation"), nullptr, F_(solarPumpModulation), F_(percent), output);
render_value_json(root, "", F_(energyTotal), energyTotal_, F_(kwh), 10); print_value_json(root, F("cylinderPumpModulation"), nullptr, F_(cylinderPumpModulation), F_(percent), output);
print_value_json(root, F("valveStatus"), nullptr, F_(valveStatus), nullptr, output);
print_value_json(root, F("solarPump"), nullptr, F_(solarPump), nullptr, output);
print_value_json(root, F("tankHeated"), nullptr, F_(tankHeated), nullptr, output);
print_value_json(root, F("collectorShutdown"), nullptr, F_(collectorShutdown), nullptr, output);
print_value_json(root, F("energyLastHour"), nullptr, F_(energyLastHour), F_(wh), output);
print_value_json(root, F("energyToday"), nullptr, F_(energyToday), F_(wh), output);
print_value_json(root, F("energyTotal"), nullptr, F_(energyTotal), F_(kwh), output);
if (Helpers::hasValue(pumpWorkMin_)) { if (Helpers::hasValue(pumpWorkMin_)) {
JsonObject dataElement; JsonObject dataElement = root.createNestedObject();
dataElement = root.createNestedObject(); dataElement["n"] = F_(pumpWorkMin);
dataElement["name"] = F_(pumpWorkMin);
char time_str[60]; char time_str[60];
snprintf_P(time_str, sizeof(time_str), PSTR("%d days %d hours %d minutes"), pumpWorkMin_ / 1440, (pumpWorkMin_ % 1440) / 60, pumpWorkMin_ % 60); snprintf_P(time_str, sizeof(time_str), PSTR("%d days %d hours %d minutes"), pumpWorkMin_ / 1440, (pumpWorkMin_ % 1440) / 60, pumpWorkMin_ % 60);
dataElement["value"] = time_str; dataElement["v"] = time_str;
} }
} }
@@ -95,19 +101,19 @@ void Solar::show_values(uuid::console::Shell & shell) {
return; // empty return; // empty
} }
print_value_json(shell, F("collectorTemp"), F_(collectorTemp), F_(degrees), output); print_value_json(shell, F("collectorTemp"), nullptr, F_(collectorTemp), F_(degrees), output);
print_value_json(shell, F("tankBottomTemp"), F_(tankBottomTemp), F_(degrees), output); print_value_json(shell, F("tankBottomTemp"), nullptr, F_(tankBottomTemp), F_(degrees), output);
print_value_json(shell, F("tankBottomTemp2"), F_(tankBottomTemp2), F_(degrees), output); print_value_json(shell, F("tankBottomTemp2"), nullptr, F_(tankBottomTemp2), F_(degrees), output);
print_value_json(shell, F("heatExchangerTemp"), F_(heatExchangerTemp), F_(degrees), output); print_value_json(shell, F("heatExchangerTemp"), nullptr, F_(heatExchangerTemp), F_(degrees), output);
print_value_json(shell, F("solarPumpModulation"), F_(solarPumpModulation), F_(percent), output); print_value_json(shell, F("solarPumpModulation"), nullptr, F_(solarPumpModulation), F_(percent), output);
print_value_json(shell, F("cylinderPumpModulation"), F_(cylinderPumpModulation), F_(percent), output); print_value_json(shell, F("cylinderPumpModulation"), nullptr, F_(cylinderPumpModulation), F_(percent), output);
print_value_json(shell, F("valveStatus"), F_(valveStatus), nullptr, output); print_value_json(shell, F("valveStatus"), nullptr, F_(valveStatus), nullptr, output);
print_value_json(shell, F("solarPump"), F_(solarPump), nullptr, output); print_value_json(shell, F("solarPump"), nullptr, F_(solarPump), nullptr, output);
print_value_json(shell, F("tankHeated"), F_(tankHeated), nullptr, output); print_value_json(shell, F("tankHeated"), nullptr, F_(tankHeated), nullptr, output);
print_value_json(shell, F("collectorShutdown"), F_(collectorShutdown), nullptr, output); print_value_json(shell, F("collectorShutdown"), nullptr, F_(collectorShutdown), nullptr, output);
print_value_json(shell, F("energyLastHour"), F_(energyLastHour), F_(wh), output); print_value_json(shell, F("energyLastHour"), nullptr, F_(energyLastHour), F_(wh), output);
print_value_json(shell, F("energyToday"), F_(energyToday), F_(wh), output); print_value_json(shell, F("energyToday"), nullptr, F_(energyToday), F_(wh), output);
print_value_json(shell, F("energyTotal"), F_(energyTotal), F_(kwh), output); print_value_json(shell, F("energyTotal"), nullptr, F_(energyTotal), F_(kwh), output);
if (Helpers::hasValue(pumpWorkMin_)) { if (Helpers::hasValue(pumpWorkMin_)) {
shell.printfln(F(" %s: %d days %d hours %d minutes"), shell.printfln(F(" %s: %d days %d hours %d minutes"),

View File

@@ -168,59 +168,56 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
// prepare data for Web UI // prepare data for Web UI
void Thermostat::device_info_web(JsonArray & root) { void Thermostat::device_info_web(JsonArray & root) {
uint8_t flags = this->model(); StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc_main;
JsonObject output_main = doc_main.to<JsonObject>();
if (export_values_main(output_main)) {
print_value_json(root, F("time"), nullptr, F_(time), nullptr, output_main);
print_value_json(root, F("display"), nullptr, F_(display), nullptr, output_main);
print_value_json(root, F("language"), nullptr, F_(language), nullptr, output_main);
print_value_json(root, F("offsetclock"), nullptr, F_(offsetclock), nullptr, output_main);
print_value_json(root, F("dampedtemp"), nullptr, F_(dampedtemp), F_(degrees), output_main);
print_value_json(root, F("inttemp1"), nullptr, F_(inttemp1), F_(degrees), output_main);
print_value_json(root, F("inttemp2"), nullptr, F_(inttemp2), F_(degrees), output_main);
print_value_json(root, F("intoffset"), nullptr, F_(intoffset), nullptr, output_main);
print_value_json(root, F("minexttemp"), nullptr, F_(minexttemp), F_(degrees), output_main);
print_value_json(root, F("building"), nullptr, F_(building), nullptr, output_main);
print_value_json(root, F("wwmode"), nullptr, F_(wwmode), nullptr, output_main);
print_value_json(root, F("wwcircmode"), nullptr, F_(wwcircmode), nullptr, output_main);
}
for (const auto & hc : heating_circuits_) { StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> doc_hc;
if (!Helpers::hasValue(hc->setpoint_roomTemp)) { JsonObject output_hc = doc_hc.to<JsonObject>();
break; // skip this HC if (export_values_hc(Mqtt::Format::NESTED, output_hc)) {
} // display for each active heating circuit
for (const auto & hc : heating_circuits_) {
if (hc->is_active()) {
char prefix_str[10];
snprintf_P(prefix_str, sizeof(prefix_str), PSTR("(hc %d) "), hc->hc_num());
// different thermostat types store their temperature values differently char hc_name[10]; // hc{1-4}
uint8_t format_setpoint, format_curr; strlcpy(hc_name, "hc", 10);
switch (flags) { char s[3];
case EMS_DEVICE_FLAG_EASY: strlcat(hc_name, Helpers::itoa(s, hc->hc_num()), 10);
format_setpoint = 100; // *100 JsonObject output = output_hc[hc_name];
format_curr = 100; // *100
break;
case EMS_DEVICE_FLAG_JUNKERS:
format_setpoint = 10; // *10
format_curr = 10; // *10
break;
default: // RC30, RC35 etc...
format_setpoint = 2; // *2
format_curr = 10; // *10
break;
}
// create prefix with heating circuit number print_value_json(root, F("seltemp"), FPSTR(prefix_str), F_(seltemp), F_(degrees), output);
char hc_str[5]; print_value_json(root, F("currtemp"), FPSTR(prefix_str), F_(currtemp), F_(degrees), output);
snprintf_P(hc_str, sizeof(hc_str), PSTR("hc%d: "), hc->hc_num()); print_value_json(root, F("heattemp"), FPSTR(prefix_str), F_(heattemp), F_(degrees), output);
print_value_json(root, F("comforttemp"), FPSTR(prefix_str), F_(comforttemp), F_(degrees), output);
render_value_json(root, hc_str, F_(currtemp), hc->curr_roomTemp, F_(degrees), format_curr); print_value_json(root, F("daytemp"), FPSTR(prefix_str), F_(daytemp), F_(degrees), output);
render_value_json(root, hc_str, F_(seltemp), hc->setpoint_roomTemp, F_(degrees), format_setpoint); print_value_json(root, F("ecotemp"), FPSTR(prefix_str), F_(ecotemp), F_(degrees), output);
if (Helpers::hasValue(hc->mode)) { print_value_json(root, F("nighttemp"), FPSTR(prefix_str), F_(nighttemp), F_(degrees), output);
JsonObject dataElement; print_value_json(root, F("manualtemp"), FPSTR(prefix_str), F_(manualtemp), F_(degrees), output);
dataElement = root.createNestedObject(); print_value_json(root, F("holidaytemp"), FPSTR(prefix_str), F_(holidaytemp), F_(degrees), output);
print_value_json(root, F("nofrosttemp"), FPSTR(prefix_str), F_(nofrosttemp), F_(degrees), output);
char mode_str[15]; print_value_json(root, F("targetflowtemp"), FPSTR(prefix_str), F_(targetflowtemp), F_(degrees), output);
snprintf_P(mode_str, sizeof(mode_str), PSTR("%sMode"), hc_str); print_value_json(root, F("offsettemp"), FPSTR(prefix_str), F_(offsettemp), F_(degrees), output);
dataElement["name"] = mode_str; print_value_json(root, F("designtemp"), FPSTR(prefix_str), F_(designtemp), F_(degrees), output);
print_value_json(root, F("summertemp"), FPSTR(prefix_str), F_(summertemp), F_(degrees), output);
char modetype_str[20]; print_value_json(root, F("summermode"), FPSTR(prefix_str), F_(summermode), F_(degrees), output);
if (Helpers::hasValue(hc->summer_mode) && hc->summer_mode) { print_value_json(root, F("mode"), FPSTR(prefix_str), F_(mode), nullptr, output);
snprintf_P(modetype_str, sizeof(modetype_str), PSTR("%s - summer"), mode_tostring(hc->get_mode(flags)).c_str()); print_value_json(root, F("modetype"), FPSTR(prefix_str), F_(modetype), nullptr, output);
} else if (Helpers::hasValue(hc->holiday_mode) && hc->holiday_mode) {
snprintf_P(modetype_str, sizeof(modetype_str), PSTR("%s - holiday"), mode_tostring(hc->get_mode(flags)).c_str());
} else if (Helpers::hasValue(hc->mode_type)) {
snprintf_P(modetype_str,
sizeof(modetype_str),
PSTR("%s - %s"),
mode_tostring(hc->get_mode(flags)).c_str(),
mode_tostring(hc->get_mode_type(flags)).c_str());
} else {
snprintf_P(modetype_str, sizeof(modetype_str), mode_tostring(hc->get_mode(flags)).c_str());
} }
dataElement["value"] = modetype_str;
} }
} }
} }
@@ -255,18 +252,18 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc_main; StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc_main;
JsonObject output_main = doc_main.to<JsonObject>(); JsonObject output_main = doc_main.to<JsonObject>();
if (export_values_main(output_main)) { if (export_values_main(output_main)) {
print_value_json(shell, F("time"), F_(time), nullptr, output_main); print_value_json(shell, F("time"), nullptr, F_(time), nullptr, output_main);
print_value_json(shell, F("display"), F_(display), nullptr, output_main); print_value_json(shell, F("display"), nullptr, F_(display), nullptr, output_main);
print_value_json(shell, F("language"), F_(language), nullptr, output_main); print_value_json(shell, F("language"), nullptr, F_(language), nullptr, output_main);
print_value_json(shell, F("offsetclock"), F_(offsetclock), nullptr, output_main); print_value_json(shell, F("offsetclock"), nullptr, F_(offsetclock), nullptr, output_main);
print_value_json(shell, F("dampedtemp"), F_(dampedtemp), F_(degrees), output_main); print_value_json(shell, F("dampedtemp"), nullptr, F_(dampedtemp), F_(degrees), output_main);
print_value_json(shell, F("inttemp1"), F_(inttemp1), F_(degrees), output_main); print_value_json(shell, F("inttemp1"), nullptr, F_(inttemp1), F_(degrees), output_main);
print_value_json(shell, F("inttemp2"), F_(inttemp2), F_(degrees), output_main); print_value_json(shell, F("inttemp2"), nullptr, F_(inttemp2), F_(degrees), output_main);
print_value_json(shell, F("intoffset"), F_(intoffset), nullptr, output_main); print_value_json(shell, F("intoffset"), nullptr, F_(intoffset), nullptr, output_main);
print_value_json(shell, F("minexttemp"), F_(minexttemp), F_(degrees), output_main); print_value_json(shell, F("minexttemp"), nullptr, F_(minexttemp), F_(degrees), output_main);
print_value_json(shell, F("building"), F_(building), nullptr, output_main); print_value_json(shell, F("building"), nullptr, F_(building), nullptr, output_main);
print_value_json(shell, F("wwmode"), F_(wwmode), nullptr, output_main); print_value_json(shell, F("wwmode"), nullptr, F_(wwmode), nullptr, output_main);
print_value_json(shell, F("wwcircmode"), F_(wwcircmode), nullptr, output_main); print_value_json(shell, F("wwcircmode"), nullptr, F_(wwcircmode), nullptr, output_main);
} }
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> doc_hc; StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> doc_hc;
@@ -277,7 +274,7 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
// display for each active heating circuit // display for each active heating circuit
for (const auto & hc : heating_circuits_) { for (const auto & hc : heating_circuits_) {
if (hc->is_active()) { if (hc->is_active()) {
shell.printfln("Heating Circuit %d:", hc->hc_num()); shell.printfln(" Heating Circuit %d:", hc->hc_num());
char hc_name[10]; // hc{1-4} char hc_name[10]; // hc{1-4}
strlcpy(hc_name, "hc", 10); strlcpy(hc_name, "hc", 10);
@@ -285,23 +282,23 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
strlcat(hc_name, Helpers::itoa(s, hc->hc_num()), 10); strlcat(hc_name, Helpers::itoa(s, hc->hc_num()), 10);
JsonObject output = output_hc[hc_name]; JsonObject output = output_hc[hc_name];
print_value_json(shell, F("seltemp"), F_(seltemp), F_(degrees), output); print_value_json(shell, F("seltemp"), F(" "), F_(seltemp), F_(degrees), output);
print_value_json(shell, F("currtemp"), F_(currtemp), F_(degrees), output); print_value_json(shell, F("currtemp"), F(" "), F_(currtemp), F_(degrees), output);
print_value_json(shell, F("heattemp"), F_(heattemp), F_(degrees), output); print_value_json(shell, F("heattemp"), F(" "), F_(heattemp), F_(degrees), output);
print_value_json(shell, F("comforttemp"), F_(comforttemp), F_(degrees), output); print_value_json(shell, F("comforttemp"), F(" "), F_(comforttemp), F_(degrees), output);
print_value_json(shell, F("daytemp"), F_(daytemp), F_(degrees), output); print_value_json(shell, F("daytemp"), F(" "), F_(daytemp), F_(degrees), output);
print_value_json(shell, F("ecotemp"), F_(ecotemp), F_(degrees), output); print_value_json(shell, F("ecotemp"), F(" "), F_(ecotemp), F_(degrees), output);
print_value_json(shell, F("nighttemp"), F_(nighttemp), F_(degrees), output); print_value_json(shell, F("nighttemp"), F(" "), F_(nighttemp), F_(degrees), output);
print_value_json(shell, F("manualtemp"), F_(manualtemp), F_(degrees), output); print_value_json(shell, F("manualtemp"), F(" "), F_(manualtemp), F_(degrees), output);
print_value_json(shell, F("holidaytemp"), F_(holidaytemp), F_(degrees), output); print_value_json(shell, F("holidaytemp"), F(" "), F_(holidaytemp), F_(degrees), output);
print_value_json(shell, F("nofrosttemp"), F_(nofrosttemp), F_(degrees), output); print_value_json(shell, F("nofrosttemp"), F(" "), F_(nofrosttemp), F_(degrees), output);
print_value_json(shell, F("targetflowtemp"), F_(targetflowtemp), F_(degrees), output); print_value_json(shell, F("targetflowtemp"), F(" "), F_(targetflowtemp), F_(degrees), output);
print_value_json(shell, F("offsettemp"), F_(offsettemp), F_(degrees), output); print_value_json(shell, F("offsettemp"), F(" "), F_(offsettemp), F_(degrees), output);
print_value_json(shell, F("designtemp"), F_(designtemp), F_(degrees), output); print_value_json(shell, F("designtemp"), F(" "), F_(designtemp), F_(degrees), output);
print_value_json(shell, F("summertemp"), F_(summertemp), F_(degrees), output); print_value_json(shell, F("summertemp"), F(" "), F_(summertemp), F_(degrees), output);
print_value_json(shell, F("summermode"), F_(summermode), F_(degrees), output); print_value_json(shell, F("summermode"), F(" "), F_(summermode), F_(degrees), output);
print_value_json(shell, F("mode"), F_(mode), nullptr, output); print_value_json(shell, F("mode"), F(" "), F_(mode), nullptr, output);
print_value_json(shell, F("modetype"), F_(modetype), nullptr, output); print_value_json(shell, F("modetype"), F(" "), F_(modetype), nullptr, output);
} }
} }
} }

View File

@@ -386,6 +386,7 @@ void EMSdevice::print_value(uuid::console::Shell & shell, uint8_t padding, const
// print value to shell from the json doc // print value to shell from the json doc
void EMSdevice::print_value_json(uuid::console::Shell & shell, void EMSdevice::print_value_json(uuid::console::Shell & shell,
const __FlashStringHelper * key, const __FlashStringHelper * key,
const __FlashStringHelper * prefix,
const __FlashStringHelper * name, const __FlashStringHelper * name,
const __FlashStringHelper * suffix, const __FlashStringHelper * suffix,
JsonObject & json) { JsonObject & json) {
@@ -394,7 +395,11 @@ void EMSdevice::print_value_json(uuid::console::Shell & shell,
return; // doesn't exist return; // doesn't exist
} }
shell.printf(PSTR(" %s: "), uuid::read_flash_string(name).c_str()); if (prefix != nullptr) {
shell.printf(PSTR(" %s%s: "), uuid::read_flash_string(prefix).c_str(), uuid::read_flash_string(name).c_str());
} else {
shell.printf(PSTR(" %s: "), uuid::read_flash_string(name).c_str());
}
if (data.is<char *>()) { if (data.is<char *>()) {
shell.printf(PSTR("%s"), data.as<char *>()); shell.printf(PSTR("%s"), data.as<char *>());
@@ -409,10 +414,58 @@ void EMSdevice::print_value_json(uuid::console::Shell & shell,
} }
if (suffix != nullptr) { if (suffix != nullptr) {
shell.print(' ');
shell.print(uuid::read_flash_string(suffix).c_str()); shell.print(uuid::read_flash_string(suffix).c_str());
} }
shell.println(); shell.println();
} }
// print value to shell from the json doc into a name/value pair
void EMSdevice::print_value_json(JsonArray & root,
const __FlashStringHelper * key,
const __FlashStringHelper * prefix,
const __FlashStringHelper * name,
const __FlashStringHelper * suffix,
JsonObject & json) {
JsonVariant data = json[uuid::read_flash_string(key)];
if (data == nullptr) {
return; // doesn't exist
}
JsonObject dataElement = root.createNestedObject();
// add prefix to name
if (prefix != nullptr) {
char name_text[100];
snprintf_P(name_text, sizeof(name_text), PSTR("%s%s"), uuid::read_flash_string(prefix).c_str(), uuid::read_flash_string(name).c_str());
dataElement["n"] = name_text;
} else {
dataElement["n"] = name;
}
// convert to string and add the suffix, this is to save space when sending to the web as json
// which is why we use n and v instead of name and value
std::string suffix_string(10, '\0');
if (suffix == nullptr) {
suffix_string = "";
} else {
suffix_string = " " + uuid::read_flash_string(suffix);
}
char data_string[20];
if (data.is<char *>()) {
snprintf_P(data_string, sizeof(data_string), PSTR("%s%s"), data.as<char *>(), suffix_string.c_str());
} else if (data.is<int>()) {
snprintf_P(data_string, sizeof(data_string), PSTR("%d%s"), data.as<int>(), suffix_string.c_str());
} else if (data.is<float>()) {
char s[10];
snprintf_P(data_string, sizeof(data_string), PSTR("%s%s"), Helpers::render_value(s, (float)data.as<float>(), 1), suffix_string.c_str());
} else if (data.is<bool>()) {
char s[10];
snprintf_P(data_string, sizeof(data_string), PSTR("%s%s"), Helpers::render_boolean(s, data.as<bool>()), suffix_string.c_str());
}
dataElement["v"] = data_string;
}
} // namespace emsesp } // namespace emsesp

View File

@@ -151,11 +151,19 @@ class EMSdevice {
static void print_value_json(uuid::console::Shell & shell, static void print_value_json(uuid::console::Shell & shell,
const __FlashStringHelper * key, const __FlashStringHelper * key,
const __FlashStringHelper * prefix,
const __FlashStringHelper * name, const __FlashStringHelper * name,
const __FlashStringHelper * suffix, const __FlashStringHelper * suffix,
JsonObject & json); JsonObject & json);
// prints a ems device value to the console, handling the correct rendering of the type static void print_value_json(JsonArray & root,
const __FlashStringHelper * key,
const __FlashStringHelper * prefix,
const __FlashStringHelper * name,
const __FlashStringHelper * suffix,
JsonObject & json);
// prints an EMS device value to the console, handling the correct rendering of the type
// padding is # white space // padding is # white space
// name is the name of the parameter // name is the name of the parameter
// suffix is any string to be appended after the value // suffix is any string to be appended after the value
@@ -183,44 +191,13 @@ class EMSdevice {
shell.printf(PSTR("%s: %s"), uuid::read_flash_string(name).c_str(), buffer); shell.printf(PSTR("%s: %s"), uuid::read_flash_string(name).c_str(), buffer);
if (suffix != nullptr) { if (suffix != nullptr) {
shell.print(' ');
shell.println(uuid::read_flash_string(suffix).c_str()); shell.println(uuid::read_flash_string(suffix).c_str());
} else { } else {
shell.println(); shell.println();
} }
} }
// takes a value from an ems device and creates a nested json (name, value)
// which can be passed to the web UI
template <typename Value>
static void render_value_json(JsonArray & json,
const std::string & prefix,
const __FlashStringHelper * name,
Value & value,
const __FlashStringHelper * suffix,
const uint8_t format = 0) {
// create the value as a string using the render_value function
char buffer[15];
if (Helpers::render_value(buffer, value, format) == nullptr) {
return;
}
JsonObject dataElement = json.createNestedObject();
// append suffix to end
if (suffix != nullptr) {
char text[20];
snprintf_P(text, sizeof(text), PSTR("%s%s"), buffer, uuid::read_flash_string(suffix).c_str());
dataElement["value"] = text;
} else {
dataElement["value"] = buffer;
}
// add prefix to name
char text2[100];
snprintf_P(text2, sizeof(text2), PSTR("%s%s"), prefix.c_str(), uuid::read_flash_string(name).c_str());
dataElement["name"] = text2;
}
static void print_value(uuid::console::Shell & shell, uint8_t padding, const __FlashStringHelper * name, const __FlashStringHelper * value); static void print_value(uuid::console::Shell & shell, uint8_t padding, const __FlashStringHelper * name, const __FlashStringHelper * value);
static void print_value(uuid::console::Shell & shell, uint8_t padding, const __FlashStringHelper * name, const char * value); static void print_value(uuid::console::Shell & shell, uint8_t padding, const __FlashStringHelper * name, const char * value);
@@ -282,7 +259,7 @@ class EMSdevice {
static constexpr uint8_t EMS_DEVICE_FLAG_RC300 = 8; static constexpr uint8_t EMS_DEVICE_FLAG_RC300 = 8;
static constexpr uint8_t EMS_DEVICE_FLAG_RC100 = 9; static constexpr uint8_t EMS_DEVICE_FLAG_RC100 = 9;
static constexpr uint8_t EMS_DEVICE_FLAG_JUNKERS = 10; static constexpr uint8_t EMS_DEVICE_FLAG_JUNKERS = 10;
static constexpr uint8_t EMS_DEVICE_FLAG_JUNKERS_2 = (1 << 6); // 6th bit set if older models static constexpr uint8_t EMS_DEVICE_FLAG_JUNKERS_2 = (1 << 6); // 6th bit set if older models, like FR120, FR100
private: private:
uint8_t unique_id_; uint8_t unique_id_;

View File

@@ -28,7 +28,7 @@ namespace emsesp {
// used with the 'test' command, under su/admin // used with the 'test' command, under su/admin
void Test::run_test(uuid::console::Shell & shell, const std::string & command) { void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
if (command == "default") { if (command == "default") {
run_test(shell, "thermostat"); // add the default test case here run_test(shell, "web"); // add the default test case here
} }
if (command.empty()) { if (command.empty()) {
@@ -219,10 +219,13 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24, uart_telegram({0x98, 0x00, 0xFF, 0x00, 0x01, 0xA5, 0x00, 0xCF, 0x21, 0x2E, 0x00, 0x00, 0x2E, 0x24,
0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03}); 0x03, 0x25, 0x03, 0x03, 0x01, 0x03, 0x25, 0x00, 0xC8, 0x00, 0x00, 0x11, 0x01, 0x03});
// time
uart_telegram({0x98, 0x00, 0x06, 0x00, 0x00, 0x03, 0x04, 0x0C, 0x02, 0x33, 0x06, 00, 00, 00, 00, 00, 00});
shell.invoke_command("show"); shell.invoke_command("show");
StaticJsonDocument<2000> doc; StaticJsonDocument<2000> doc;
JsonObject root = doc.to<JsonObject>(); JsonObject root = doc.to<JsonObject>();
EMSESP::device_info_web(1, root); EMSESP::device_info_web(2, root); // show thermostat. use 1 for boiler
serializeJsonPretty(doc, shell); serializeJsonPretty(doc, shell);
shell.println(); shell.println();
} }