From 41cc74ea7b19931053480e9ab7c21ba525db6ac7 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 18 Oct 2019 09:31:59 +0200 Subject: [PATCH] Update xdrv_29_deepsleep.ino Added RESULT message before deepsleep to send via MQTT next Wakeup time in Local Time and UTC: 09:30:12 MQT: stat/sonoff/RESULT = {"Deepsleep":{"Time":"2019-10-18T09:35:00","Epoch":1571384100}} --- sonoff/xdrv_29_deepsleep.ino | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/sonoff/xdrv_29_deepsleep.ino b/sonoff/xdrv_29_deepsleep.ino index d48ffb31a..13706798b 100644 --- a/sonoff/xdrv_29_deepsleep.ino +++ b/sonoff/xdrv_29_deepsleep.ino @@ -66,9 +66,6 @@ void CheckForDeepsleep(void) // new function AFTER_TELEPERIOD can take some time therefore <2 if ((Settings.deepsleep > 10) && (Settings.deepsleep < 4294967295) && !disable_deepsleep_switch && (tele_period < 2) && prep_called) { SettingsSaveAll(); - Response_P(S_OFFLINE); - MqttPublishPrefixTopic_P(TELE, PSTR(D_LWT), true); // Offline or remove previous retained topic - yield(); // deepsleep_slip is ideally 10.000 == 100% // typically the device has up to 4% slip. Anything else is a wrong setting in the deepsleep_slip // therefore all values >110% or <90% will be resetted to 100% to avoid crazy sleep times. @@ -102,16 +99,17 @@ void CheckForDeepsleep(void) // ensure nextwakeup is at least in the future RtcSettings.nextwakeup += (((UtcTime() + MIN_DEEPSLEEP_TIME - RtcSettings.nextwakeup) / Settings.deepsleep) + 1) * Settings.deepsleep; } - Response_P(PSTR("%d"), RtcSettings.nextwakeup); - MqttPublishPrefixTopic_P(TELE, PSTR(D_DOMOTICZ_UPDATE_TIMER), false); // Offline or remove previous retained topic - yield(); - MqttDisconnect(); String dt = GetDT(RtcSettings.nextwakeup + LocalTime() - UtcTime()); // 2017-03-07T11:08:02 // AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("DSL: Next wakeup %s"), (char*)dt.c_str()); //limit sleeptime to MAX_DEEPSLEEP_CYCLE //uint32_t sleeptime = MAX_DEEPSLEEP_CYCLE < (RtcSettings.nextwakeup - UtcTime()) ? (uint32_t)MAX_DEEPSLEEP_CYCLE : RtcSettings.nextwakeup - UtcTime(); uint32_t sleeptime = tmin((uint32_t)MAX_DEEPSLEEP_CYCLE , RtcSettings.nextwakeup - UtcTime()); - + Response_P(PSTR("{\"" D_PRFX_DEEPSLEEP "\":{\"" D_JSON_TIME "\":\"%s\",\"Epoch\":%d}}"), (char*)dt.c_str(), RtcSettings.nextwakeup); + MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_STATUS "1"), false); + Response_P(S_OFFLINE); + MqttPublishPrefixTopic_P(TELE, PSTR(D_LWT), true); // Offline or remove previous retained topic + yield(); + MqttDisconnect(); RtcSettings.ultradeepsleep = RtcSettings.nextwakeup - UtcTime(); // AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("DSL: Sleeptime %d sec, deepsleep_slip %ld"), sleeptime, RtcSettings.deepsleep_slip); RtcSettingsSave(); @@ -157,4 +155,4 @@ bool Xdrv29(uint8_t function) return result; } -#endif //USE_DEEPSLEEP \ No newline at end of file +#endif //USE_DEEPSLEEP