micropython / micropython-esp32

Old port of MicroPython to the ESP32 -- new port is at https://github.com/micropython/micropython
MIT License
678 stars 218 forks source link

Setting the time on an esp32 #87

Closed saltydog101 closed 7 years ago

saltydog101 commented 7 years ago

I've worked with the ESP8266, and there I would set the time on bootup via ntp. I was able to call the RTC class from machine and also, use utime.localtime to help calculate the delta. Then I would call RTC().datetime to set the time accordingly. In the ESP32 port, there is neither an RTC class or a localtime function from utime, I'd be glad to look at adding it, but I wanted to make sure I'm not duplicating the same functionality elsewhere. Is someone already working on something similar?

dpgeorge commented 7 years ago

I wanted to make sure I'm not duplicating the same functionality elsewhere. Is someone already working on something similar?

Not to my knowledge, so feel free to go for it.

mcauser commented 7 years ago

Some work on machine.RTC here: https://github.com/micropython/micropython-esp32/pull/85

saltydog101 commented 7 years ago

Thanks mcauser! I'll just add the localtime method to utime to complete setting the time.

nickzoic commented 7 years ago

Cool, I should add a call to machine.RTC().init() to mpy-utils as well ...

MrSurly commented 7 years ago

Actually, I did implement datetime() in https://github.com/micropython/micropython-esp32/pull/85

Though, I need to update it to make a bit more sense, since I screwed up the year / month thing (1900 and 0-11) Edit 1: Fixed, pushed, matches implementation from the documentation.

Edit 2: Also, implemented using subseconds (255-0) instead of µseconds ... probably not the right thing to do for machine.RTC (as opposed to pyb.RTC)

Edit 3: Implemented RTC().init(()), and replaced subseconds with microseconds

vandys commented 7 years ago

Has anybody wired in the SNTP code form the SDK? Seems like it'd be a nice fit.

saltydog101 commented 7 years ago

Thanks @MrSurly, that's what I needed to set the time from ntp.