Get sunrise/sunset (#1030)

* Get the next sunset or sunrise values as TimerSeconds to allow setting a light's initial sate.

* Fix BL602 & W600 builds, and add some self test asserts for get sunrise/sunset

* Clock based self tests fail if they are not run in Europe time zone.

Update all usages of localtime to be gmtime. On windows local time is has the timezone applied on top of the sourceTime parameter, OpenBK app manages its own timezone and applies it to g_ntpTime appropriately, so gmtime will avoid the additional timezone application on windows machines.

* Simplify sample autoexec to avoid functionality that has not been implemented yet.

* Update docs

* Small fix in autoexe file

No brackets allowed, multiplications before addition appears to work
This commit is contained in:
Imre Lengyel
2024-01-20 23:50:40 +11:00
committed by GitHub
parent 4695b1c093
commit 87868f2559
14 changed files with 159 additions and 45 deletions

View File

@ -330,7 +330,7 @@ static int http_tasmota_json_status_SNS(void* request, jsonCb_t printer, bool bA
printer(request, "{");
time_t localTime = (time_t)NTP_GetCurrentTime();
strftime(buff, sizeof(buff), "%Y-%m-%dT%H:%M:%S", localtime(&localTime));
strftime(buff, sizeof(buff), "%Y-%m-%dT%H:%M:%S", gmtime(&localTime));
JSON_PrintKeyValue_String(request, printer, "Time", buff, false);
#ifndef OBK_DISABLE_ALL_DRIVERS
@ -411,7 +411,7 @@ static int http_tasmota_json_status_STS(void* request, jsonCb_t printer, bool bA
printer(request, "\"StatusSTS\":");
}
printer(request, "{");
strftime(buff, sizeof(buff), "%Y-%m-%dT%H:%M:%S", localtime(&localTime));
strftime(buff, sizeof(buff), "%Y-%m-%dT%H:%M:%S", gmtime(&localTime));
JSON_PrintKeyValue_String(request, printer, "Time", buff, true);
format_time(g_secondsElapsed, buff, sizeof(buff));
JSON_PrintKeyValue_String(request, printer, "Uptime", buff, true);
@ -449,9 +449,9 @@ static int http_tasmota_json_status_TIM(void* request, jsonCb_t printer) {
time_t localTime = (time_t)NTP_GetCurrentTime();
time_t localUTC = (time_t)NTP_GetCurrentTimeWithoutOffset();
printer(request, "\"StatusTIM\":{");
strftime(buff, sizeof(buff), "%Y-%m-%dT%H:%M:%S", localtime(&localUTC));
strftime(buff, sizeof(buff), "%Y-%m-%dT%H:%M:%S", gmtime(&localUTC));
JSON_PrintKeyValue_String(request, printer, "UTC", buff, true);
strftime(buff, sizeof(buff), "%Y-%m-%dT%H:%M:%S", localtime(&localTime));
strftime(buff, sizeof(buff), "%Y-%m-%dT%H:%M:%S", gmtime(&localTime));
JSON_PrintKeyValue_String(request, printer, "Local", buff, true);
JSON_PrintKeyValue_String(request, printer, "StartDST", "2022-03-27T02:00:00", true);
JSON_PrintKeyValue_String(request, printer, "EndDST", "2022-10-30T03:00:00", true);
@ -663,7 +663,7 @@ static int http_tasmota_json_status_generic(void* request, jsonCb_t printer) {
JSON_PrintKeyValue_Int(request, printer, "Uptime", g_secondsElapsed, true);
struct tm* ltm;
int ntpTime = NTP_GetCurrentTime() - g_secondsElapsed;
ltm = localtime((time_t*)&ntpTime);
ltm = gmtime((time_t*)&ntpTime);
if (ltm != 0) {
printer(request, "\"StartupUTC\":\"%04d-%02d-%02dT%02d:%02d:%02d\",", ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec);