I found the module utime on the internet.
if you import utime, you can get the actual time and date with the command utime.localtime()
In the Netherlands it’s now summertime and the time is now correct with the command localtime(), but wil give this command also the right time in the winter?
I couldn’t find anything on the internet for arduino that give the right time summer and winter. Is this an advantage of micropython?
Hi Eric.
I’m not sure I understood your question.
I think the localtime() should give the correct winter and summer time, but I’m not sure.
As for the Arduino, we have these guides about time:
- https://randomnerdtutorials.com/epoch-unix-time-esp32-arduino/
- https://randomnerdtutorials.com/esp32-date-time-ntp-client-server-arduino/
There are functions to adjust daylight offset as well as time zone in this last tutorial.
I hope this helps.
Regards,
Sara
Sara, i couldn’t get the codes running on a esp8266, but i found on the internet this example, based on your website.
https://opencircuit.nl/Blog/WiFi-klok-met-de-ESP32-OLED/Code
in the file config.h is a rule: const int daylightOffset_sec = 0; // Daylight savings 0|3600
Here you have to change manually the summer and wintertime. That’s not what i want and what MicroPyhton does, that gives automatically the correct time.
Hi.
I’m sorry. I thought you were using an ESP32. For the ESP8266, we have these guides (similar to the previous ones – not automatic correct date and time, you need to set the parameters or do some calculations):
- https://randomnerdtutorials.com/epoch-unix-time-esp8266-nodemcu-arduino/
- https://randomnerdtutorials.com/esp8266-nodemcu-date-time-ntp-client-server-arduino/
Regards,
Sara
Thanks Sara, that’s what i needed to know.
So you have to change your sketch twice a year with arduino and you don’t have change it with MicroPython
Oh wow, that is just what i needed.
Many thanks Steve!!!!
I it works is a mystery to me, but who cares.