37 lines
878 B
Lua
37 lines
878 B
Lua
-- Scripts pour régler l'horloge quand on est connecté en WIFI
|
|
-- Permet aussi de 'compresser' le unix time afin de prendre moins de place dans les strings
|
|
|
|
print("\n set_time.lua zf191030.2026 \n")
|
|
|
|
--source: https://www.freeformatter.com/epoch-timestamp-to-date-converter.html
|
|
|
|
ztime2019 = 1546300800 -- Unix time pour le 1.1.2019
|
|
|
|
function set_time()
|
|
sntp.sync(nil, nil, nil, 1)
|
|
end
|
|
|
|
function ztime_compress(ztime_long)
|
|
return ztime_long - ztime2019
|
|
end
|
|
|
|
function ztime_uncompress(ztime_short)
|
|
return ztime_short + ztime2019
|
|
end
|
|
|
|
function ztime_format(ztime)
|
|
local tm = rtctime.epoch2cal(ztime + 3600)
|
|
return(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))
|
|
end
|
|
|
|
set_time()
|
|
|
|
tmr.create():alarm(2*1000, tmr.ALARM_SINGLE, function()
|
|
print(ztime_format(rtctime.get()))
|
|
end)
|
|
|
|
|
|
|
|
|
|
|