Home/Support/Support Forum/XBC LTE Cat 1 Verizon Micropython UTC Time
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

XBC LTE Cat 1 Verizon Micropython UTC Time

0 votes
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%7C_____0 ) doesn't provide any specifics.


My question: Is it possible to configure micropython on the cell xbee to return actual UTC time?
asked May 13 in Python by tylerkoldenjtp New to the Community (7 points)

Please log in or register to answer this question.

2 Answers

+2 votes
 
Best answer
The XBee Cellular device gets the time reported by the cell tower. Most of the time this will be your local time. There currently isn't a way to explicitly ask for the UTC time.

From the uP docs:
"In CPython, this function returns number of seconds since Unix epoch, 1970-01-01 00:00 UTC, as a floating-point, usually having microsecond precision. With MicroPython, only Unix port uses the same Epoch"

https://docs.micropython.org/en/latest/library/utime.html#utime.time

Just a side note:
# 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)

is equivalent to:
utc_tuple = utime.localtime()
answered May 13 by DigiFan23 Seasoned Professional (193 points)
selected May 14 by tylerkoldenjtp
0 votes
Thank you for the helpful answer, DigiFan23!
answered May 14 by tylerkoldenjtp New to the Community (7 points)
You are welcome.
...