34. Lektion: NTP/RTC: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| Line 16: | Line 16: | ||
>>> | >>> | ||
</pre> | </pre> | ||
== NTP/RTC== | |||
<pre> | |||
# automatisches Stellen der RTC in Thonny wurde abgeschaltet. | |||
>>> import time | |||
>>> import wlantools as wl | |||
connecting to network... | |||
network config: ('192.168.5.120', '255.255.255.0', '192.168.5.1', '192.168.5.1') | |||
>>> time.localtime() | |||
(2021, 1, 1, 0, 0, 36, 4, 1) # Hier sind Datum und Uhrzeit falsch. | |||
>>> import ntptime | |||
>>> ntptime.settime() | |||
>>> time.localtime() | |||
(2024, 1, 10, 13, 33, 1, 2, 10) # Hier sind Datum und Uhrzeit richtig. | |||
>>> | |||
</pre> | |||
Die RTC des ESP32 soll sehr ungenau sein. | Die RTC des ESP32 soll sehr ungenau sein. | ||
| Line 93: | Line 113: | ||
>>> | >>> | ||
</pre> | </pre> | ||
==Navigation== | ==Navigation== | ||
Revision as of 14:39, 10 January 2024
Unix-Zeit
ACHTUNG ESP32 und Pico arbeiten mit unterschiedlichen Epochen:
MicroPython v1.20.0 on 2023-04-26; Raspberry Pi Pico W with RP2040 >>> import time >>> time.gmtime(0) (1970, 1, 1, 0, 0, 0, 3, 1) >>>
MicroPython v1.20.0 on 2023-04-26; ESP32 module with ESP32 >>> import time >>> time.gmtime(0) (2000, 1, 1, 0, 0, 0, 5, 1) >>>
NTP/RTC
# automatisches Stellen der RTC in Thonny wurde abgeschaltet.
>>> import time
>>> import wlantools as wl
connecting to network...
network config: ('192.168.5.120', '255.255.255.0', '192.168.5.1', '192.168.5.1')
>>> time.localtime()
(2021, 1, 1, 0, 0, 36, 4, 1) # Hier sind Datum und Uhrzeit falsch.
>>> import ntptime
>>> ntptime.settime()
>>> time.localtime()
(2024, 1, 10, 13, 33, 1, 2, 10) # Hier sind Datum und Uhrzeit richtig.
>>>
Die RTC des ESP32 soll sehr ungenau sein.
- https://www.az-delivery.de/blogs/azdelivery-blog-fur-arduino-und-raspberry-pi/rtc-und-ntp-in-micropython-mit-esp8266-und-esp32-teil-1
- https://www.az-delivery.de/blogs/azdelivery-blog-fur-arduino-und-raspberry-pi/rtc-und-ntp-in-micropython-mit-esp8266-und-esp32-teil-2-tiefschlaf?utm_source=90%20Day%20Engaged&utm_medium=email&utm_campaign=220523_Hydroponik%20-%20Pflanzen%20ohne%20Erde_Blog%20%2801H0SBCNDVZF5ZP2WDDDZXW24A%29&utm_content=RTC%20und%20NTP%20in%20MicroPython%20Teil%202&utm_term=Campaign&_kx=t6chfMYPTCmi3Q3FmsDDDGHlL3Kt6ctVyJh9Hkft9JU%3D.QVRJMi
MicroPython v1.20.0 on 2023-04-26; ESP32S3 module with ESP32S3
Type "help()" for more information.
>>> import network
>>> import ntptime
>>> from machine import RTC
# WLAN einrichten
>>> wlan = network.WLAN(network.STA_IF)
>>> wlan.active(True)
True
>>> wlan.connect('SSID', 'PW')
>>> wlan.isconnected()
False
>>> wlan.isconnected()
True
>>> wlan.ifconfig()
('192.168.5.109', '255.255.255.0', '192.168.5.1', '192.168.5.1')
# Die RTC mit NTP einstellen
>>> ntptime.settime()
# Die RTC einrichten
>>> rtc = RTC()
>>> rtc.datetime()
(2023, 9, 5, 1, 15, 39, 56, 427762)
>>> rtc.datetime()
(2023, 9, 5, 1, 16, 14, 5, 837765)
>>> rtc.datetime()
(2023, 9, 5, 1, 16, 21, 42, 597764)
>>> dir(ntptime)
['__class__', '__name__', '__dict__', '__file__', 'socket', 'struct', 'time', 'timeout', 'utime', '__version__', 'host', 'settime']
>>> ntptime.time()
747246194
>>> rtc.datetime()
(2023, 9, 5, 1, 16, 23, 49, 897771)
>>> ntptime.time()
747246234
>>> ntptime.utime
<module 'utime'>
>>> rtc.datetime()
(2023, 9, 5, 1, 16, 24, 29, 867765)
>>> ntptime.time()
747246276
>>> import time
>>> dir(time)
['__class__', '__name__', '__dict__', 'gmtime', 'localtime', 'mktime', 'sleep', 'sleep_ms', 'sleep_us', 'ticks_add', 'ticks_cpu', 'ticks_diff', 'ticks_ms', 'ticks_us', 'time', 'time_ns']
>>> time.gmtime()
(2023, 9, 5, 16, 25, 39, 1, 248)
>>> time.localtime()
(2023, 9, 5, 16, 25, 57, 1, 248)
>>> time.mktime(rtc.datetime())
747191787
>>> ntptime.time()
747246461
>>> time.mktime(rtc.datetime())
747191787
>>> ntptime.time()
747246472
>>> time.mktime(rtc.datetime())
747191788
>>> ntptime.time()
747246489
>>>
Zurück zur "Micropython Kurs 2023 Teil 2" Startseite
Zurück zur "Micropython Kurs 2023" Startseite
Zurück zur Programmieren Startseite
Zurück zur Wiki Startseite