Merge branch 'arendst/development' into development

This commit is contained in:
reloxx13 2018-02-17 21:08:55 +01:00
commit 15adf3ba07
10 changed files with 63 additions and 27 deletions

View File

@ -7,6 +7,9 @@
* Add Russian language file (#1909) * Add Russian language file (#1909)
* Add Webserver upload preflight request support (#1927) * Add Webserver upload preflight request support (#1927)
* Add Home Assistant clear other device (#1931) * Add Home Assistant clear other device (#1931)
* Add Restart time to Status 1 (#1938)
* Change Sonoff SC JSON format (#1939)
* Fix compile error when define HOME_ASSISTANT_DISCOVERY_ENABLE is not set (#1937)
* *
* 5.12.0a * 5.12.0a
* Change platformio option sonoff-ds18x20 to sonoff-xxl enabling ds18x20 and all other sensors in one image * Change platformio option sonoff-ds18x20 to sonoff-xxl enabling ds18x20 and all other sensors in one image

View File

@ -99,6 +99,7 @@
#define D_JSON_SSID "SSId" #define D_JSON_SSID "SSId"
#define D_JSON_STARTDST "StartDST" // Start Daylight Savings Time #define D_JSON_STARTDST "StartDST" // Start Daylight Savings Time
#define D_JSON_STARTED "Started" #define D_JSON_STARTED "Started"
#define D_JSON_STARTUPUTC "StartupUTC"
#define D_JSON_SUBNETMASK "Subnetmask" #define D_JSON_SUBNETMASK "Subnetmask"
#define D_JSON_SUCCESSFUL "Successful" #define D_JSON_SUCCESSFUL "Successful"
#define D_JSON_SWITCH "Switch" #define D_JSON_SWITCH "Switch"

View File

@ -50,6 +50,10 @@
#define MTX_ADDRESS8 0 #define MTX_ADDRESS8 0
#endif #endif
#ifndef HOME_ASSISTANT_DISCOVERY_ENABLE
#define HOME_ASSISTANT_DISCOVERY_ENABLE 0
#endif
/*********************************************************************************************\ /*********************************************************************************************\
* RTC memory * RTC memory
\*********************************************************************************************/ \*********************************************************************************************/

View File

@ -114,6 +114,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, DT_UPTIME };
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

@ -1742,8 +1742,8 @@ void PublishStatus(uint8_t payload)
} }
if ((0 == payload) || (1 == payload)) { if ((0 == payload) || (1 == payload)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS1_PARAMETER "\":{\"" D_JSON_BAUDRATE "\":%d,\"" D_CMND_GROUPTOPIC "\":\"%s\",\"" D_CMND_OTAURL "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\",\"" D_CMND_SLEEP "\":%d,\"" D_JSON_BOOTCOUNT "\":%d,\"" D_JSON_SAVECOUNT "\":%d,\"" D_JSON_SAVEADDRESS "\":\"%X\"}}"), snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS1_PARAMETER "\":{\"" D_JSON_BAUDRATE "\":%d,\"" D_CMND_GROUPTOPIC "\":\"%s\",\"" D_CMND_OTAURL "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\",\"" D_JSON_STARTUPUTC "\":\"%s\",\"" D_CMND_SLEEP "\":%d,\"" D_JSON_BOOTCOUNT "\":%d,\"" D_JSON_SAVECOUNT "\":%d,\"" D_JSON_SAVEADDRESS "\":\"%X\"}}"),
baudrate, Settings.mqtt_grptopic, Settings.ota_url, GetUptime().c_str(), Settings.sleep, Settings.bootcount, Settings.save_flag, GetSettingsAddress()); baudrate, Settings.mqtt_grptopic, Settings.ota_url, GetDateAndTime(DT_UPTIME).c_str(), GetDateAndTime(DT_RESTART).c_str(), Settings.sleep, Settings.bootcount, Settings.save_flag, GetSettingsAddress());
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "1")); MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "1"));
} }
@ -1816,7 +1816,7 @@ void MqttShowState()
{ {
char stemp1[33]; char stemp1[33];
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\""), mqtt_data, GetDateAndTime().c_str(), GetUptime().c_str()); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\""), mqtt_data, GetDateAndTime(DT_LOCAL).c_str(), GetDateAndTime(DT_UPTIME).c_str());
#ifdef USE_ADC_VCC #ifdef USE_ADC_VCC
dtostrfd((double)ESP.getVcc()/1000, 3, stemp1); dtostrfd((double)ESP.getVcc()/1000, 3, stemp1);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_VCC "\":%s"), mqtt_data, stemp1); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_VCC "\":%s"), mqtt_data, stemp1);
@ -1836,7 +1836,7 @@ void MqttShowState()
boolean MqttShowSensor() boolean MqttShowSensor()
{ {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\""), mqtt_data, GetDateAndTime().c_str()); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\""), mqtt_data, GetDateAndTime(DT_LOCAL).c_str());
int json_data_start = strlen(mqtt_data); int json_data_start = strlen(mqtt_data);
for (byte i = 0; i < MAX_SWITCHES; i++) { for (byte i = 0; i < MAX_SWITCHES; i++) {
if (pin[GPIO_SWT1 +i] < 99) { if (pin[GPIO_SWT1 +i] < 99) {
@ -1927,7 +1927,7 @@ void PerformEverySecond()
if ((2 == RtcTime.minute) && latest_uptime_flag) { if ((2 == RtcTime.minute) && latest_uptime_flag) {
latest_uptime_flag = false; latest_uptime_flag = false;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\"}"), GetDateAndTime().c_str(), GetUptime().c_str()); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\"}"), GetDateAndTime(DT_LOCAL).c_str(), GetDateAndTime(DT_UPTIME).c_str());
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_UPTIME)); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_UPTIME));
} }
if ((3 == RtcTime.minute) && !latest_uptime_flag) { if ((3 == RtcTime.minute) && !latest_uptime_flag) {

View File

@ -992,6 +992,7 @@ uint32_t daylight_saving_time = 0;
uint32_t standard_time = 0; uint32_t standard_time = 0;
uint32_t ntp_time = 0; uint32_t ntp_time = 0;
uint32_t midnight = 1451602800; uint32_t midnight = 1451602800;
uint32_t restart_time = 0;
uint8_t midnight_now = 0; uint8_t midnight_now = 0;
uint8_t ntp_sync_minute = 0; uint8_t ntp_sync_minute = 0;
@ -1024,27 +1025,44 @@ String GetBuildDateAndTime()
return String(bdt); return String(bdt);
} }
String GetDateAndTime() String GetDateAndTime(byte time_type)
{ {
// enum GetDateAndTimeOptions { DT_LOCAL, DT_UTC, DT_RESTART, DT_UPTIME };
// "2017-03-07T11:08:02" - ISO8601:2004 // "2017-03-07T11:08:02" - ISO8601:2004
char dt[21]; char dt[21];
snprintf_P(dt, sizeof(dt), PSTR("%04d" D_YEAR_MONTH_SEPARATOR "%02d" D_MONTH_DAY_SEPARATOR "%02d" D_DATE_TIME_SEPARATOR "%02d" D_HOUR_MINUTE_SEPARATOR "%02d" D_MINUTE_SECOND_SEPARATOR "%02d"),
RtcTime.year, RtcTime.month, RtcTime.day_of_month, RtcTime.hour, RtcTime.minute, RtcTime.second);
return String(dt);
}
String GetUtcDateAndTime()
{
// "2017-03-07T11:08:02" - ISO8601:2004
char dt[21];
TIME_T tmpTime; TIME_T tmpTime;
BreakTime(utc_time, tmpTime);
tmpTime.year += 1970;
snprintf_P(dt, sizeof(dt), PSTR("%04d" D_YEAR_MONTH_SEPARATOR "%02d" D_MONTH_DAY_SEPARATOR "%02d" D_DATE_TIME_SEPARATOR "%02d" D_HOUR_MINUTE_SEPARATOR "%02d" D_MINUTE_SECOND_SEPARATOR "%02d"), if (DT_UPTIME == time_type) {
tmpTime.year, tmpTime.month, tmpTime.day_of_month, tmpTime.hour, tmpTime.minute, tmpTime.second); if (restart_time) {
BreakTime(utc_time - restart_time, tmpTime);
} else {
BreakTime(uptime, tmpTime);
}
// "P128DT14H35M44S" - ISO8601:2004 - https://en.wikipedia.org/wiki/ISO_8601 Durations
// snprintf_P(dt, sizeof(dt), PSTR("P%dDT%02dH%02dM%02dS"), ut.days, ut.hour, ut.minute, ut.second);
// "128 14:35:44" - OpenVMS
// "128T14:35:44" - Tasmota
snprintf_P(dt, sizeof(dt), PSTR("%dT%02d:%02d:%02d"),
tmpTime.days, tmpTime.hour, tmpTime.minute, tmpTime.second);
} else {
switch (time_type) {
case DT_UTC:
BreakTime(utc_time, tmpTime);
tmpTime.year += 1970;
break;
case DT_RESTART:
if (restart_time == 0) {
return "";
}
BreakTime(restart_time, tmpTime);
tmpTime.year += 1970;
break;
default:
tmpTime = RtcTime;
}
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);
}
return String(dt); return String(dt);
} }
@ -1053,14 +1071,20 @@ String GetUptime()
char dt[16]; char dt[16];
TIME_T ut; TIME_T ut;
BreakTime(uptime, ut);
if (restart_time) {
BreakTime(utc_time - restart_time, ut);
} else {
BreakTime(uptime, ut);
}
// "P128DT14H35M44S" - ISO8601:2004 - https://en.wikipedia.org/wiki/ISO_8601 Durations // "P128DT14H35M44S" - ISO8601:2004 - https://en.wikipedia.org/wiki/ISO_8601 Durations
// snprintf_P(dt, sizeof(dt), PSTR("P%dDT%02dH%02dM%02dS"), ut.days, ut.hour, ut.minute, ut.second); // snprintf_P(dt, sizeof(dt), PSTR("P%dDT%02dH%02dM%02dS"), ut.days, ut.hour, ut.minute, ut.second);
// "128 14:35:44" - OpenVMS // "128 14:35:44" - OpenVMS
// "128T14:35:44" - Tasmota // "128T14:35:44" - Tasmota
snprintf_P(dt, sizeof(dt), PSTR("%d" D_DATE_TIME_SEPARATOR "%02d" D_HOUR_MINUTE_SEPARATOR "%02d" D_MINUTE_SECOND_SEPARATOR "%02d"), ut.days, ut.hour, ut.minute, ut.second); snprintf_P(dt, sizeof(dt), PSTR("%dT%02d:%02d:%02d"),
ut.days, ut.hour, ut.minute, ut.second);
return String(dt); return String(dt);
} }
@ -1228,6 +1252,9 @@ void RtcSecond()
if (ntp_time) { if (ntp_time) {
utc_time = ntp_time; utc_time = ntp_time;
ntp_sync_minute = 60; // Sync so block further requests ntp_sync_minute = 60; // Sync so block further requests
if (restart_time == 0) {
restart_time = utc_time - uptime; // save first ntp time as restart time
}
BreakTime(utc_time, tmpTime); BreakTime(utc_time, tmpTime);
RtcTime.year = tmpTime.year + 1970; RtcTime.year = tmpTime.year + 1970;
daylight_saving_time = RuleToTime(DaylightSavingTime, RtcTime.year); daylight_saving_time = RuleToTime(DaylightSavingTime, RtcTime.year);

View File

@ -1598,7 +1598,7 @@ void HandleInformation()
func += F(D_PROGRAM_VERSION "}2"); func += my_version; func += F(D_PROGRAM_VERSION "}2"); func += my_version;
func += F("}1" D_BUILD_DATE_AND_TIME "}2"); func += GetBuildDateAndTime(); func += F("}1" D_BUILD_DATE_AND_TIME "}2"); func += GetBuildDateAndTime();
func += F("}1" D_CORE_AND_SDK_VERSION "}2" ARDUINO_ESP8266_RELEASE "/"); func += String(ESP.getSdkVersion()); func += F("}1" D_CORE_AND_SDK_VERSION "}2" ARDUINO_ESP8266_RELEASE "/"); func += String(ESP.getSdkVersion());
func += F("}1" D_UPTIME "}2"); func += GetUptime(); func += F("}1" D_UPTIME "}2"); func += GetDateAndTime(DT_UPTIME);
snprintf_P(stopic, sizeof(stopic), PSTR(" at %X"), GetSettingsAddress()); snprintf_P(stopic, sizeof(stopic), PSTR(" at %X"), GetSettingsAddress());
func += F("}1" D_FLASH_WRITE_COUNT "}2"); func += String(Settings.save_flag); func += stopic; func += F("}1" D_FLASH_WRITE_COUNT "}2"); func += String(Settings.save_flag); func += stopic;
func += F("}1" D_BOOT_COUNT "}2"); func += String(Settings.bootcount); func += F("}1" D_BOOT_COUNT "}2"); func += String(Settings.bootcount);

View File

@ -748,7 +748,7 @@ void EnergyMarginCheck()
void EnergyMqttShow() void EnergyMqttShow()
{ {
// {"Time":"2017-12-16T11:48:55","ENERGY":{"Total":0.212,"Yesterday":0.000,"Today":0.014,"Period":2.0,"Power":22.0,"Factor":1.00,"Voltage":213.6,"Current":0.100}} // {"Time":"2017-12-16T11:48:55","ENERGY":{"Total":0.212,"Yesterday":0.000,"Today":0.014,"Period":2.0,"Power":22.0,"Factor":1.00,"Voltage":213.6,"Current":0.100}}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime().c_str()); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str());
EnergyShow(1); EnergyShow(1);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_ENERGY), Settings.flag.mqtt_sensor_retain); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_ENERGY), Settings.flag.mqtt_sensor_retain);

View File

@ -544,7 +544,7 @@ void HueConfigResponse(String *response)
response->replace("{ms", WiFi.subnetMask().toString()); response->replace("{ms", WiFi.subnetMask().toString());
response->replace("{gw", WiFi.gatewayIP().toString()); response->replace("{gw", WiFi.gatewayIP().toString());
response->replace("{br", HueBridgeId()); response->replace("{br", HueBridgeId());
response->replace("{dt", GetUtcDateAndTime()); response->replace("{dt", GetDateAndTime(DT_UTC));
response->replace("{id", GetHueUserId()); response->replace("{id", GetHueUserId());
} }

View File

@ -120,7 +120,7 @@ void SonoffScShow(boolean json)
dtostrfd(h, Settings.flag2.humidity_resolution, humidity); dtostrfd(h, Settings.flag2.humidity_resolution, humidity);
if (json) { if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s,\"" D_JSON_LIGHT "\":%d,\"" D_JSON_NOISE "\":%d,\"" D_JSON_AIRQUALITY "\":%d"), snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"SonoffSC\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s,\"" D_JSON_LIGHT "\":%d,\"" D_JSON_NOISE "\":%d,\"" D_JSON_AIRQUALITY "\":%d}"),
mqtt_data, temperature, humidity, sc_value[2], sc_value[3], sc_value[4]); mqtt_data, temperature, humidity, sc_value[2], sc_value[3], sc_value[4]);
#ifdef USE_DOMOTICZ #ifdef USE_DOMOTICZ
DomoticzTempHumSensor(temperature, humidity); DomoticzTempHumSensor(temperature, humidity);