Eliminating call sntp_get_real_time

Change display of some date and time messages from "Wed Feb 19 10:45:12 2020" to "2020-02-19T10:45:12"
This commit is contained in:
Theo Arends 2020-02-19 15:23:59 +01:00
parent df34417861
commit 6a84899e10
6 changed files with 28 additions and 34 deletions

View File

@ -61,6 +61,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
- Change wifi connectivity stability (#7602) - Change wifi connectivity stability (#7602)
- Change some wifi code to attempt faster connection (#7621) - Change some wifi code to attempt faster connection (#7621)
- Change MQTT message size with additional 200 characters - Change MQTT message size with additional 200 characters
- Change display of some date and time messages from "Wed Feb 19 10:45:12 2020" to "2020-02-19T10:45:12"
- Fix Sonoff Bridge, Sc, L1, iFan03 and CSE7766 serial interface to forced speed, config and disable logging - Fix Sonoff Bridge, Sc, L1, iFan03 and CSE7766 serial interface to forced speed, config and disable logging
- Fix commands ``Display`` and ``Counter`` from overruling command processing (#7322) - Fix commands ``Display`` and ``Counter`` from overruling command processing (#7322)
- Fix ``White`` added to light status (#7142) - Fix ``White`` added to light status (#7142)

View File

@ -4,6 +4,7 @@
- Change MQTT message size with additional 200 characters - Change MQTT message size with additional 200 characters
- Change some wifi code to attempt faster connection (#7621) - Change some wifi code to attempt faster connection (#7621)
- Change display of some date and time messages from "Wed Feb 19 10:45:12 2020" to "2020-02-19T10:45:12"
- Add another new DHT driver based on ESPEasy. The old driver can still be used using define USE_DHT_OLD. The previous new driver can be used with define USE_DHT_V2 (#7717) - Add another new DHT driver based on ESPEasy. The old driver can still be used using define USE_DHT_OLD. The previous new driver can be used with define USE_DHT_V2 (#7717)
### 8.1.0.7 20200210 ### 8.1.0.7 20200210

View File

@ -449,13 +449,13 @@ void CmndStatus(void)
#if defined(USE_TIMERS) && defined(USE_SUNRISE) #if defined(USE_TIMERS) && defined(USE_SUNRISE)
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS7_TIME "\":{\"" D_JSON_UTC_TIME "\":\"%s\",\"" D_JSON_LOCAL_TIME "\":\"%s\",\"" D_JSON_STARTDST "\":\"%s\",\"" Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS7_TIME "\":{\"" D_JSON_UTC_TIME "\":\"%s\",\"" D_JSON_LOCAL_TIME "\":\"%s\",\"" D_JSON_STARTDST "\":\"%s\",\""
D_JSON_ENDDST "\":\"%s\",\"" D_CMND_TIMEZONE "\":%s,\"" D_JSON_SUNRISE "\":\"%s\",\"" D_JSON_SUNSET "\":\"%s\"}}"), D_JSON_ENDDST "\":\"%s\",\"" D_CMND_TIMEZONE "\":%s,\"" D_JSON_SUNRISE "\":\"%s\",\"" D_JSON_SUNSET "\":\"%s\"}}"),
GetTime(0).c_str(), GetTime(1).c_str(), GetTime(2).c_str(), GetDateAndTime(DT_UTC).c_str(), GetDateAndTime(DT_LOCALNOTZ).c_str(), GetDateAndTime(DT_DST).c_str(),
GetTime(3).c_str(), stemp, GetSun(0).c_str(), GetSun(1).c_str()); GetDateAndTime(DT_STD).c_str(), stemp, GetSun(0).c_str(), GetSun(1).c_str());
#else #else
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS7_TIME "\":{\"" D_JSON_UTC_TIME "\":\"%s\",\"" D_JSON_LOCAL_TIME "\":\"%s\",\"" D_JSON_STARTDST "\":\"%s\",\"" Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS7_TIME "\":{\"" D_JSON_UTC_TIME "\":\"%s\",\"" D_JSON_LOCAL_TIME "\":\"%s\",\"" D_JSON_STARTDST "\":\"%s\",\""
D_JSON_ENDDST "\":\"%s\",\"" D_CMND_TIMEZONE "\":%s}}"), D_JSON_ENDDST "\":\"%s\",\"" D_CMND_TIMEZONE "\":%s}}"),
GetTime(0).c_str(), GetTime(1).c_str(), GetTime(2).c_str(), GetDateAndTime(DT_UTC).c_str(), GetDateAndTime(DT_LOCALNOTZ).c_str(), GetDateAndTime(DT_DST).c_str(),
GetTime(3).c_str(), stemp); GetDateAndTime(DT_STD).c_str(), stemp);
#endif // USE_TIMERS and USE_SUNRISE #endif // USE_TIMERS and USE_SUNRISE
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "7")); MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "7"));
} }

View File

@ -170,8 +170,8 @@ String GetDT(uint32_t time)
/* /*
* timestamps in https://en.wikipedia.org/wiki/ISO_8601 format * timestamps in https://en.wikipedia.org/wiki/ISO_8601 format
* *
* DT_UTC - current data and time in Greenwich, England (aka GMT) * DT_UTC - current data and time in Greenwich, England (aka GMT)
* DT_LOCAL - current date and time taking timezone into account * DT_LOCAL - current date and time taking timezone into account
* DT_RESTART - the date and time this device last started, in local timezone * DT_RESTART - the date and time this device last started, in local timezone
* *
* Format: * Format:
@ -184,21 +184,30 @@ String GetDateAndTime(uint8_t time_type)
uint32_t time = Rtc.local_time; uint32_t time = Rtc.local_time;
switch (time_type) { switch (time_type) {
case DT_BOOTCOUNT:
time = Settings.bootcount_reset_time;
break;
case DT_ENERGY:
time = Settings.energy_kWhtotal_time;
break;
case DT_UTC: case DT_UTC:
time = Rtc.utc_time; time = Rtc.utc_time;
break; break;
// case DT_LOCALNOTZ: // Is default anyway but allows for not appendig timezone
// time = Rtc.local_time;
// break;
case DT_DST:
time = Rtc.daylight_saving_time;
break;
case DT_STD:
time = Rtc.standard_time;
break;
case DT_RESTART: case DT_RESTART:
if (Rtc.restart_time == 0) { if (Rtc.restart_time == 0) {
return ""; return "";
} }
time = Rtc.restart_time; time = Rtc.restart_time;
break; break;
case DT_ENERGY:
time = Settings.energy_kWhtotal_time;
break;
case DT_BOOTCOUNT:
time = Settings.bootcount_reset_time;
break;
} }
String dt = GetDT(time); // 2017-03-07T11:08:02 String dt = GetDT(time); // 2017-03-07T11:08:02
if (Settings.flag3.time_append_timezone && (DT_LOCAL == time_type)) { // SetOption52 - Append timezone to JSON time if (Settings.flag3.time_append_timezone && (DT_LOCAL == time_type)) { // SetOption52 - Append timezone to JSON time
@ -207,23 +216,6 @@ String GetDateAndTime(uint8_t time_type)
return dt; // 2017-03-07T11:08:02-07:00 return dt; // 2017-03-07T11:08:02-07:00
} }
String GetTime(int type)
{
/* type 1 - Local time
* type 2 - Daylight Savings time
* type 3 - Standard time
*/
char stime[25]; // Skip newline
uint32_t time = Rtc.utc_time;
if (1 == type) time = Rtc.local_time;
if (2 == type) time = Rtc.daylight_saving_time;
if (3 == type) time = Rtc.standard_time;
snprintf_P(stime, sizeof(stime), sntp_get_real_time(time));
return String(stime); // Thu Nov 01 11:41:02 2018
}
uint32_t UpTime(void) uint32_t UpTime(void)
{ {
if (Rtc.restart_time) { if (Rtc.restart_time) {
@ -400,8 +392,8 @@ void RtcSecond(void)
Rtc.standard_time = RuleToTime(Settings.tflag[0], RtcTime.year); Rtc.standard_time = RuleToTime(Settings.tflag[0], RtcTime.year);
// Do not use AddLog_P2 here (interrupt routine) if syslog or mqttlog is enabled. UDP/TCP will force exception 9 // Do not use AddLog_P2 here (interrupt routine) if syslog or mqttlog is enabled. UDP/TCP will force exception 9
PrepLog_P2(LOG_LEVEL_DEBUG, PSTR("NTP: Drift %d, (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), PrepLog_P2(LOG_LEVEL_DEBUG, PSTR("NTP: Drift %d, (" D_UTC_TIME ")%s, (" D_DST_TIME ")%s, (" D_STD_TIME ")%s"),
DriftTime(), GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); DriftTime(), GetDateAndTime(DT_UTC).c_str(), GetDateAndTime(DT_DST).c_str(), GetDateAndTime(DT_STD).c_str());
if (Rtc.local_time < START_VALID_TIME) { // 2016-01-01 if (Rtc.local_time < START_VALID_TIME) { // 2016-01-01
rules_flag.time_init = 1; rules_flag.time_init = 1;

View File

@ -226,7 +226,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_ENERGY, DT_BOOTCOUNT }; enum GetDateAndTimeOptions { DT_LOCAL, DT_UTC, DT_LOCALNOTZ, DT_DST, DT_STD, DT_RESTART, DT_ENERGY, DT_BOOTCOUNT };
enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE}; enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE};

View File

@ -143,7 +143,7 @@ void DS3231EverySecond(void)
Rtc.daylight_saving_time = RuleToTime(Settings.tflag[1], RtcTime.year); Rtc.daylight_saving_time = RuleToTime(Settings.tflag[1], RtcTime.year);
Rtc.standard_time = RuleToTime(Settings.tflag[0], RtcTime.year); Rtc.standard_time = RuleToTime(Settings.tflag[0], RtcTime.year);
AddLog_P2(LOG_LEVEL_INFO, PSTR("Set time from DS3231 to RTC (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), AddLog_P2(LOG_LEVEL_INFO, PSTR("Set time from DS3231 to RTC (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"),
GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); GetDateAndTime(DT_UTC).c_str(), GetDateAndTime(DT_DST).c_str(), GetDateAndTime(DT_STD).c_str());
if (Rtc.local_time < START_VALID_TIME) { // 2016-01-01 if (Rtc.local_time < START_VALID_TIME) { // 2016-01-01
rules_flag.time_init = 1; rules_flag.time_init = 1;
} else { } else {
@ -152,7 +152,7 @@ void DS3231EverySecond(void)
} }
else if (!ds3231WriteStatus && Rtc.utc_time > START_VALID_TIME && abs(Rtc.utc_time - ReadFromDS3231()) > 60) {//if time is valid and is drift from RTC in more that 60 second else if (!ds3231WriteStatus && Rtc.utc_time > START_VALID_TIME && abs(Rtc.utc_time - ReadFromDS3231()) > 60) {//if time is valid and is drift from RTC in more that 60 second
AddLog_P2(LOG_LEVEL_INFO, PSTR("Write Time TO DS3231 from NTP (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), AddLog_P2(LOG_LEVEL_INFO, PSTR("Write Time TO DS3231 from NTP (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"),
GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); GetDateAndTime(DT_UTC).c_str(), GetDateAndTime(DT_DST).c_str(), GetDateAndTime(DT_STD).c_str());
SetDS3231Time (Rtc.utc_time); //update the DS3231 time SetDS3231Time (Rtc.utc_time); //update the DS3231 time
ds3231WriteStatus = true; ds3231WriteStatus = true;
} }