Add TotalStartTime to Energy JSON

Add TotalStartTime to Energy JSON message (#3971)
This commit is contained in:
Theo Arends 2018-10-30 17:04:19 +01:00
parent c0f9ea027d
commit e6a8b2d30d
6 changed files with 15 additions and 5 deletions

View File

@ -3,6 +3,7 @@
* Add command SetOption53 0/1 to toggle gui display of Hostname and IP address (#1006, #2091) * Add command SetOption53 0/1 to toggle gui display of Hostname and IP address (#1006, #2091)
* Add token %hostname% to command FullTopic (#3018) * Add token %hostname% to command FullTopic (#3018)
* Add support for two BMP/BME sensors (#4195) * Add support for two BMP/BME sensors (#4195)
* Add TotalStartTime to Energy JSON message (#3971)
* *
* 6.2.1.19 20181023 * 6.2.1.19 20181023
* Fix header file execution order by renaming user_config.h to my_user_config.h * Fix header file execution order by renaming user_config.h to my_user_config.h

View File

@ -127,6 +127,7 @@
#define D_JSON_TIME "Time" #define D_JSON_TIME "Time"
#define D_JSON_TODAY "Today" #define D_JSON_TODAY "Today"
#define D_JSON_TOTAL "Total" #define D_JSON_TOTAL "Total"
#define D_JSON_TOTAL_START_TIME "TotalStartTime"
#define D_JSON_TVOC "TVOC" #define D_JSON_TVOC "TVOC"
#define D_JSON_TYPE "Type" #define D_JSON_TYPE "Type"
#define D_JSON_UPTIME "Uptime" #define D_JSON_UPTIME "Uptime"

View File

@ -322,8 +322,9 @@ struct SYSCFG {
uint16_t mcp230xx_int_timer; // 718 uint16_t mcp230xx_int_timer; // 718
uint8_t rgbwwTable[5]; // 71A uint8_t rgbwwTable[5]; // 71A
byte free_71F[153]; // 71F byte free_71F[149]; // 71F
uint32_t energy_kWhtotal_time; // 7B4
unsigned long weight_item; // 7B8 Weight of one item in gram * 10 unsigned long weight_item; // 7B8 Weight of one item in gram * 10
byte free_7BC[2]; // 7BC byte free_7BC[2]; // 7BC

View File

@ -181,7 +181,7 @@ enum WeekInMonthOptions {Last, First, Second, Third, Fourth};
enum DayOfTheWeekOptions {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat}; enum DayOfTheWeekOptions {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
enum MonthNamesOptions {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec}; enum MonthNamesOptions {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
enum HemisphereOptions {North, South}; enum HemisphereOptions {North, South};
enum GetDateAndTimeOptions { DT_LOCAL, DT_UTC, DT_RESTART }; enum GetDateAndTimeOptions { DT_LOCAL, DT_UTC, DT_RESTART, DT_ENERGY };
enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL}; enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};

View File

@ -1946,6 +1946,10 @@ String GetDateAndTime(byte time_type)
TIME_T tmpTime; TIME_T tmpTime;
switch (time_type) { switch (time_type) {
case DT_ENERGY:
BreakTime(Settings.energy_kWhtotal_time, tmpTime);
tmpTime.year += 1970;
break;
case DT_UTC: case DT_UTC:
BreakTime(utc_time, tmpTime); BreakTime(utc_time, tmpTime);
tmpTime.year += 1970; tmpTime.year += 1970;
@ -1964,7 +1968,8 @@ String GetDateAndTime(byte time_type)
snprintf_P(dt, sizeof(dt), PSTR("%04d-%02d-%02dT%02d:%02d:%02d"), snprintf_P(dt, sizeof(dt), PSTR("%04d-%02d-%02dT%02d:%02d:%02d"),
tmpTime.year, tmpTime.month, tmpTime.day_of_month, tmpTime.hour, tmpTime.minute, tmpTime.second); tmpTime.year, tmpTime.month, tmpTime.day_of_month, tmpTime.hour, tmpTime.minute, tmpTime.second);
if (Settings.flag3.time_append_timezone && (time_type == DT_LOCAL)) { if (Settings.flag3.time_append_timezone && (DT_LOCAL == time_type)) {
// if (Settings.flag3.time_append_timezone && ((DT_LOCAL == time_type) || (DT_ENERGY == time_type))) {
snprintf_P(dt, sizeof(dt), PSTR("%s%+03d:%02d"), dt, time_timezone / 10, abs((time_timezone % 10) * 6)); // if timezone = +2:30 then time_timezone = 25 snprintf_P(dt, sizeof(dt), PSTR("%s%+03d:%02d"), dt, time_timezone / 10, abs((time_timezone % 10) * 6)); // if timezone = +2:30 then time_timezone = 25
} }
@ -2225,6 +2230,7 @@ void RtcSecond()
} }
local_time += time_offset; local_time += time_offset;
time_timezone = time_offset / 360; // (SECS_PER_HOUR / 10) fails as it is defined as UL time_timezone = time_offset / 360; // (SECS_PER_HOUR / 10) fails as it is defined as UL
if (!Settings.energy_kWhtotal_time) { Settings.energy_kWhtotal_time = local_time; }
} }
BreakTime(local_time, RtcTime); BreakTime(local_time, RtcTime);
if (!RtcTime.hour && !RtcTime.minute && !RtcTime.second && RtcTime.valid) { if (!RtcTime.hour && !RtcTime.minute && !RtcTime.second && RtcTime.valid) {

View File

@ -393,6 +393,7 @@ boolean EnergyCommand()
RtcSettings.energy_kWhtotal = lnum *100; RtcSettings.energy_kWhtotal = lnum *100;
Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal; Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal;
energy_total = (float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000; energy_total = (float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000;
if (!energy_total) { Settings.energy_kWhtotal_time = LocalTime(); }
break; break;
} }
} }
@ -612,8 +613,8 @@ void EnergyShow(boolean json)
} }
if (json) { if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_RSLT_ENERGY "\":{\"" D_JSON_TOTAL "\":%s,\"" D_JSON_YESTERDAY "\":%s,\"" D_JSON_TODAY "\":%s%s,\"" D_JSON_POWERUSAGE "\":%s"), snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_RSLT_ENERGY "\":{\"" D_JSON_TOTAL_START_TIME "\":\"%s\",\"" D_JSON_TOTAL "\":%s,\"" D_JSON_YESTERDAY "\":%s,\"" D_JSON_TODAY "\":%s%s,\"" D_JSON_POWERUSAGE "\":%s"),
mqtt_data, energy_total_chr, energy_yesterday_chr, energy_daily_chr, (show_energy_period) ? speriod : "", active_power_chr); mqtt_data, GetDateAndTime(DT_ENERGY).c_str(), energy_total_chr, energy_yesterday_chr, energy_daily_chr, (show_energy_period) ? speriod : "", active_power_chr);
if (!energy_type_dc) { if (!energy_type_dc) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_APPARENT_POWERUSAGE "\":%s,\"" D_JSON_REACTIVE_POWERUSAGE "\":%s,\"" D_JSON_POWERFACTOR "\":%s%s"), snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_APPARENT_POWERUSAGE "\":%s,\"" D_JSON_REACTIVE_POWERUSAGE "\":%s,\"" D_JSON_POWERFACTOR "\":%s%s"),
mqtt_data, apparent_power_chr, reactive_power_chr, power_factor_chr, (!isnan(energy_frequency)) ? sfrequency : ""); mqtt_data, apparent_power_chr, reactive_power_chr, power_factor_chr, (!isnan(energy_frequency)) ? sfrequency : "");