My goal is print the UTC time since the custom epoch (2000-01-01 00:00:00 UTC) to the console using micropython. I want to use utime ( https://docs.micropython.org/en/latest/library/utime.html )
micropython script to print UTC time
required packages
import utime, network
obtain cell network connection
conn = network.Cellular()
notify user
print(“starting to connect to network…”)
wait until connected
while not conn.isconnected():
# notify user
print(“waiting for network connection…”)
# add delay
utime.sleep(4)
continual loop to print time
def print_time():
# loop forever
while True:
try:
# fetch number of seconds time since 2001-01-01 epoch in UTC
seconds_since_epoch = utime.time()
# convert seconds to date
utc_tuple = utime.localtime(seconds_since_epoch)
# print
print("Seconds since epoch: " + str(seconds_since_epoch))
print("Time tuple: " + str(utc_tuple))
except Exception as e:
# print failure
print("Failure: " + str(e))
# add delay
utime.sleep(5)
print time
print_time()
###############################################
When this script is run, the output is as follows:
Loading /flash/main.mpy…
Running bytecode…
starting to connect to network…
Seconds since epoch: 611048250
Time tuple: (2019, 5, 13, 7, 37, 30, 0, 133)
Using a epoch converter ( https://www.dcode.fr/timestamp-converter ), I convert the custom epoch to a date format and get the same value as displayed in the tuple.
The problem is that the utime.time() appears to return number of seconds since the epoch with with my current timezone offset (UTC-6) instead of no offset (UTC).
In order to get the actual UTC time since the custom epoch of 2000-01-01 00:00:00 UTC, I have to add my current location’s UTC offset to the total number of seconds. In my case, it is 60 seconds * 60 minutes * 6 hours = 21600 seconds.
The utime documentation ( https://docs.micropython.org/en/latest/library/utime.html ) refers to some variation in the time but the Digi Micropython documentation ( https://www.digi.com/resources/documentation/digidocs/90002219/default.htm#container/cont_examples_time.htm%3FTocPath%3DTime%2520module%2520example%253A%25C2%25A0get%2520the%2520current%2520time|_____0 ) doesn’t provide any specifics.
My question: Is it possible to configure micropython on the cell xbee to return actual UTC time?