gmtime

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
retep.relleum
Posts: 5
Joined: Sat Apr 18, 2020 6:22 am

gmtime

Post by retep.relleum » Sun Sep 27, 2020 6:58 am

I tried to set the time on my ESP32 with the version "MicroPython v1.13 on 2020-09-02; ESP32 module (spiram) with ESP32" with ntptime. This doesn't work. This leads to an OSError 202 when using the ntptime module. :twisted:
After a long search, I found that utime.gmtime() is not available. :geek: Why ? :?:

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: gmtime

Post by davef » Sun Sep 27, 2020 8:51 am

https://github.com/micropython/micropyt ... ntptime.pyevidently gets you gmtime() on a ESP8266. Hopefully, it works for the ESP32 as I want to use it as well.

retep.relleum
Posts: 5
Joined: Sat Apr 18, 2020 6:22 am

Re: gmtime

Post by retep.relleum » Sun Sep 27, 2020 9:17 am

no it work not

Code: Select all

>>> import utime

>>> utime.gmtime()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'gmtime'
>>> utime.localtime()

(2000, 1, 1, 2, 0, 44, 5, 1)
>>> 

esp32 use instead of utime.gmtime ()
the function utime.localtime () :D

But thank you anyway for your good modules :!:

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: gmtime

Post by davef » Sun Sep 27, 2020 10:03 am

What I am going to try is:
- place that version of ntptime.py on the ESP32
- write a small test program which imports ntptime

My understanding is that that will only get you UTC so you need to make your own correction for your timezone.

I have only started using Micropython on the ESP32 so maybe I have got this all wrong.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: gmtime

Post by pythoncoder » Mon Sep 28, 2020 5:12 am

I think on the ESP32 you need to replace gmtime with localtime. @davef is correct, these names reference a function which returns UTC. MicroPython has no timezone support.
Peter Hinch
Index to my micropython libraries.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: gmtime

Post by davef » Tue Sep 29, 2020 9:26 am

retep.rellleum,

Found this viewtopic.php?f=16&t=3675&start=10, especially the post by kwtf and after modifying it for NZ time seems to work fine.

Post Reply