NTP_DELTA in ntptime module is deprecated? #11047
dusan-zervan
started this conversation in
General
Replies: 2 comments 3 replies
-
I have realized that setting RTC to local time zone is not ideal, better way is to correct time zone (especially summer / winter time) each time when displaying actual time. 🤔 However, this code is working both in old and new MicroPython: from time import mktime, gmtime
from machine import RTC
import ntptime
try:
ntptime.host = "sk.pool.ntp.org"
ntptime.timeout = 5
teraz = ntptime.time()
except:
return False
rok = gmtime(teraz)[0]
letny = list(gmtime(mktime((rok, 3, 31, 1, 0, 0, 0, 0))))
letny[2] -= (letny[6] + 1) % 7
letny = mktime(letny)
zimny = list(gmtime(mktime((rok, 10, 31, 1, 0, 0, 0, 0))))
zimny[2] -= (zimny[6] + 1) % 7
zimny = mktime(zimny)
if (letny < teraz and teraz < zimny):
teraz += 7200
else:
teraz += 3600
t = gmtime(teraz)
RTC().datetime((t[0], t[1], t[2], None, t[3], t[4], t[5], 1))
return True |
Beta Was this translation helpful? Give feedback.
0 replies
-
Well, as far as I understood, def localtime(sec = None):
from time import time, mktime, gmtime
if sec == None: sec = time()
year = gmtime(sec)[0]
# summer - from last Sunday of March
summer = list(gmtime(mktime((year, 3, 31, 1, 0, 0, None, None))))
summer[2] -= (summer[6] + 1) % 7
# winter - from last Sunday of October
winter = list(gmtime(mktime((year, 10, 31, 1, 0, 0, None, None))))
winter[2] -= (winter[6] + 1) % 7
summer[6:8] = winter[6:8] = (None, None)
sec += 3600 # UTC+1
if (mktime(summer) < sec and sec < mktime(winter)):
sec += 3600
return gmtime(sec) So I will set RTC just to UTC from NTP now. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using NTP_DELTA to switch between summer and winter time:
It was working for long time, but now I have flashed the latest nightly build of MicroPython and it seems like NTP_DELTA was removed? It has no effect when I set it to any value.
Beta Was this translation helpful? Give feedback.
All reactions