Add Tariff export values to JSON message

Add Tariff export values to JSON message (#6429)
This commit is contained in:
Theo Arends 2019-09-22 14:00:34 +02:00
parent 957272dca4
commit 15024fa348
2 changed files with 13 additions and 10 deletions

View File

@ -113,7 +113,7 @@ const uint16_t SERIALLOG_TIMER = 600; // Seconds to disable SerialLog
const uint8_t OTA_ATTEMPTS = 5; // Number of times to try fetching the new firmware
const uint16_t INPUT_BUFFER_SIZE = 520; // Max number of characters in (serial and http) command buffer
const uint16_t FLOATSZ = 33; // Max number of characters in float result from dtostrfd
const uint16_t FLOATSZ = 16; // Max number of characters in float result from dtostrfd (max 32)
const uint16_t CMDSZ = 24; // Max number of characters in command
const uint16_t TOPSZ = 100; // Max number of characters in topic string
const uint16_t LOGSZ = 520; // Max number of characters in log

View File

@ -929,18 +929,21 @@ void EnergyShow(bool json)
dtostrfd(Energy.daily, Settings.flag2.energy_resolution, energy_daily_chr);
char energy_yesterday_chr[FLOATSZ];
dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr);
char energy_total_chr[3][FLOATSZ];
dtostrfd(Energy.total, Settings.flag2.energy_resolution, energy_total_chr[0]);
char export_active_chr[3][FLOATSZ];
dtostrfd(Energy.export_active, Settings.flag2.energy_resolution, export_active_chr[0]);
uint8_t energy_total_fields = 1;
if (Settings.register8[R8_ENERGY_TARIFF1_ST] != Settings.register8[R8_ENERGY_TARIFF2_ST]) {
dtostrfd((float)RtcSettings.energy_usage.usage1_kWhtotal / 1000, Settings.flag2.energy_resolution, energy_total_chr[1]); // Tariff1
dtostrfd((float)RtcSettings.energy_usage.usage2_kWhtotal / 1000, Settings.flag2.energy_resolution, energy_total_chr[2]); // Tariff2
dtostrfd((float)RtcSettings.energy_usage.return1_kWhtotal / 1000, Settings.flag2.energy_resolution, export_active_chr[1]); // Tariff1
dtostrfd((float)RtcSettings.energy_usage.return2_kWhtotal / 1000, Settings.flag2.energy_resolution, export_active_chr[2]); // Tariff2
energy_total_fields = 3;
}
char export_active_chr[FLOATSZ];
dtostrfd(Energy.export_active, Settings.flag2.energy_resolution, export_active_chr);
char value_chr[FLOATSZ *3];
char value_chr[FLOATSZ *3]; // Used by EnergyFormatIndex
char value2_chr[FLOATSZ *3];
char value3_chr[FLOATSZ *3];
@ -954,7 +957,8 @@ void EnergyShow(bool json)
energy_daily_chr);
if (!isnan(Energy.export_active)) {
ResponseAppend_P(PSTR(",\"" D_JSON_EXPORT_ACTIVE "\":%s"), export_active_chr);
ResponseAppend_P(PSTR(",\"" D_JSON_EXPORT_ACTIVE "\":%s"),
EnergyFormatIndex(value_chr, export_active_chr[0], json, energy_total_fields));
}
if (show_energy_period) {
@ -999,10 +1003,9 @@ void EnergyShow(bool json)
dtostrfd(RtcSettings.energy_usage.usage1_kWhtotal, 1, energy_total_chr[1]); // Tariff1
dtostrfd(RtcSettings.energy_usage.usage2_kWhtotal, 1, energy_total_chr[2]); // Tariff2
char energy_return_chr[2][FLOATSZ];
dtostrfd(RtcSettings.energy_usage.return1_kWhtotal, 1, energy_return_chr[0]);
dtostrfd(RtcSettings.energy_usage.return2_kWhtotal, 1, energy_return_chr[1]);
DomoticzSensorP1SmartMeter(energy_total_chr[1], energy_total_chr[2], energy_return_chr[0], energy_return_chr[1], (int)Energy.active_power[0]);
dtostrfd(RtcSettings.energy_usage.return1_kWhtotal, 1, export_active_chr[1]);
dtostrfd(RtcSettings.energy_usage.return2_kWhtotal, 1, export_active_chr[2]);
DomoticzSensorP1SmartMeter(energy_total_chr[1], energy_total_chr[2], export_active_chr[1], export_active_chr[2], (int)Energy.active_power[0]);
if (Energy.voltage_available) {
DomoticzSensor(DZ_VOLTAGE, voltage_chr[0]); // Voltage
@ -1054,7 +1057,7 @@ void EnergyShow(bool json)
}
WSContentSend_PD(HTTP_ENERGY_SNS2, energy_daily_chr, energy_yesterday_chr, energy_total_chr[0]);
if (!isnan(Energy.export_active)) {
WSContentSend_PD(HTTP_ENERGY_SNS3, export_active_chr);
WSContentSend_PD(HTTP_ENERGY_SNS3, export_active_chr[0]);
}
XnrgCall(FUNC_WEB_SENSOR);