From 90d3cd45c4c6043bff73b06d02fd0144528e57f5 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 25 May 2020 11:44:17 +0200 Subject: [PATCH] Add command ``Time 4`` Add command ``Time 4`` to display timestamp using milliseconds (#8537) --- RELEASENOTES.md | 1 + tasmota/CHANGELOG.md | 3 ++- tasmota/support.ino | 3 +++ tasmota/support_command.ino | 4 ++-- tasmota/support_rtc.ino | 7 +++++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index f376168d1..f78f518d5 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -59,6 +59,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Change Energy JSON Total field from ``"Total":[33.736,11.717,16.978]`` to ``"Total":33.736,"TotalTariff":[11.717,16.978]`` - Change Energy JSON ExportActive field from ``"ExportActive":[33.736,11.717,16.978]`` to ``"ExportActive":33.736,"ExportTariff":[11.717,16.978]`` - Add command ``Rule0`` to change global rule parameters +- Add command ``Time 4`` to display timestamp using milliseconds (#8537) - Add commands ``LedPwmOn 0..255``, ``LedPwmOff 0..255`` and ``LedPwmMode1 0/1`` to control led brightness by George (#8491) - Add more functionality to ``Switchmode`` 11 and 12 (#8450) - Add wildcard pattern ``?`` for JSON matching in rules diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 472cb9ffa..91ddbf196 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -5,8 +5,9 @@ - Change Energy JSON Total field from ``"Total":[33.736,11.717,16.978]`` to ``"Total":33.736,"TotalTariff":[11.717,16.978]`` - Change Energy JSON ExportActive field from ``"ExportActive":[33.736,11.717,16.978]`` to ``"ExportActive":33.736,"ExportTariff":[11.717,16.978]`` - Change Adafruit_SGP30 library from v1.0.3 to v1.2.0 (#8519) -- Add Three Phase Export Active Energy to SDM630 driver +- Add command ``Time 4`` to display timestamp using milliseconds (#8537) - Add commands ``LedPwmOn 0..255``, ``LedPwmOff 0..255`` and ``LedPwmMode1 0/1`` to control led brightness by George (#8491) +- Add Three Phase Export Active Energy to SDM630 driver - Add wildcard pattern ``?`` for JSON matching in rules ### 8.3.1.1 20200518 diff --git a/tasmota/support.ino b/tasmota/support.ino index c5006cf6c..21d79b510 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -996,6 +996,9 @@ char* ResponseGetTime(uint32_t format, char* time_str) case 2: snprintf_P(time_str, TIMESZ, PSTR("{\"" D_JSON_TIME "\":%u"), UtcTime()); break; + case 3: + snprintf_P(time_str, TIMESZ, PSTR("{\"" D_JSON_TIME "\":\"%s.%d\""), GetDateAndTime(DT_LOCAL).c_str(), RtcMillis()); + break; default: snprintf_P(time_str, TIMESZ, PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str()); } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 9851a5654..9d9fbfa19 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1641,12 +1641,12 @@ void CmndTime(void) // payload 1 = Time format {"Time":"2019-09-04T14:31:29"} // payload 2 = Time format {"Time":"2019-09-04T14:31:29","Epoch":1567600289} // payload 3 = Time format {"Time":1567600289} -// payload 4 = reserved +// payload 4 = Time format {"Time":"2019-09-04T14:31:29.123"} // payload 1451602800 - disable NTP and set time to epoch uint32_t format = Settings.flag2.time_format; if (XdrvMailbox.data_len > 0) { - if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 4)) { + if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 5)) { Settings.flag2.time_format = XdrvMailbox.payload -1; format = Settings.flag2.time_format; } else { diff --git a/tasmota/support_rtc.ino b/tasmota/support_rtc.ino index 0b2249ec2..44e7dad29 100644 --- a/tasmota/support_rtc.ino +++ b/tasmota/support_rtc.ino @@ -47,6 +47,7 @@ struct RTC { uint32_t ntp_time = 0; uint32_t midnight = 0; uint32_t restart_time = 0; + uint32_t millis = 0; int32_t time_timezone = 0; uint8_t ntp_sync_minute = 0; bool midnight_now = false; @@ -239,6 +240,10 @@ uint32_t MinutesPastMidnight(void) return minutes; } +uint32_t RtcMillis(void) { + return (millis() - Rtc.millis) % 1000; +} + void BreakTime(uint32_t time_input, TIME_T &tm) { // break the given time_input into time components @@ -362,6 +367,8 @@ void RtcSecond(void) { TIME_T tmpTime; + Rtc.millis = millis(); + if (!Rtc.user_time_entry && !global_state.wifi_down) { uint8_t uptime_minute = (uptime / 60) % 60; // 0 .. 59 if ((Rtc.ntp_sync_minute > 59) && (uptime_minute > 2)) {