Question

I am writing some data collection software (in python) that will transmit data to the cloud. I am including a timestamp (using the standard datetime module included with python) in the data record so that the time is documented in the cloud datastore. It will run on an embedded linux device.

I am between a few architectural ideas for how to handle the timezone of the devices and the accuracy of the timestamps.

My thoughts are that I will use an NTP server to obtain the UTC time for the linux distribution which will provide an accurate time for all the applications running on the device. However I am unsure what I should set the timezone to on the device itself.

My concern is that if I set the timezone to the local time and it happens to be wrong, then not only will the local time be wrong, but when my application gets the UTC time from system time it will also be incorrect, even though it was negotiated previously by the NTP server. The timezone may be set incorrectly by whomever installs the deivce. I could mitigate this by including a GPS module in the device which can negotiate the GPS time to configure the system time, but this seems like extra hardware that would be unnecessary.

The other idea would be to have all devices timezone set to UTC and not change based on the location of the device. Then I can be sure that the UTC timestamps I send to the cloud are accurate, but I lose information about the local time unless I also send location info to the cloud database.

I'm not sure if there is a preferred method for setting system time on IoT devices such as this, but I would like some guidance.

Was it helpful?

Solution

You outline two distinct problems

  1. Find out (on the device) the correct time

    If you are logging data with a timestamp you will want to use the correct UTC datetime. As you note this can be discovered via a NTP server.

  2. Find the local timezone for the device

    Its less clear why you need this information. But it's next to impossible to retrieve as it is in some ways a user preference.

    In theory with a non-movable device, if you can locate the device with enough accuracy you can look up the timezone that applies to that location at that time.

    Since the only real need for local time is to present it to a user, I would simply ask them to choose a timezone.

OTHER TIPS

IGNORE THE TIMEZONE OF THE DEVICE

Report your answers in UTC.

In almost ANY situation where you are displaying or reporting on time based data, the timezone of interest will NOT be the timezone where the data was collected, but rather the timezone of the VIEWER of the GUI or REPORT.

This is especially obvious and critical if you are collecting data from devices that maybe in different timezones.

It's hard to guarantee the timezone of the device will be set correctly, because typically its NOT (because nobody cares). Only if it generates human viewable data about dates would it need to know a timezone.

Licensed under: CC-BY-SA with attribution
scroll top