Does time management in the Azure RTOS IoT HUB sample cause a Year 2038 problem?

yoji sato 281 Reputation points
2022-01-26T05:51:41.897+00:00

Currently, we are evaluating the communication with IoT HUB of Azure with AzureRTOS
by referring to the following sample project.

Azure_RTOS_6.1_Renesas_RX65N_RSK_2MB_e2studio_CCRX_Sample_2021_11_19.zip
sample_azure_iot_embedded_sdk

In the above implementation, the system time is synchronized by SNTP, and it seems that
it operates based on the time in seconds acquired there, but the time information seems
to be 32 bits.

Won't this cause the Year 2038 problem?

Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
333 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,214 questions
{count} vote

Accepted answer
  1. Liya Du 446 Reputation points
    2022-01-28T19:18:23.213+00:00

    Hi @yoji sato san, we confirmed that this was a bug in the code that requires a fix. We have planned to fix that in our next release. Many thanks for reporting that. Also please let us know if this problem impacts on your project so that we can provide some patch code for you as an interim solution.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Bo Chen 596 Reputation points Microsoft Employee
    2022-04-21T09:28:31.35+00:00

    Hi @yoji sato As NTPv3 timestamps are represented as a 64-bit unsigned number in seconds relative to 00:00:00 UTC on 1 January 1900. The integer part is in the first 32bits (136 years), so the time for NTP will overflow in 2036 (1900 + 136). The time in middleware will overflow in 2106 (1970 + 136) since it uses Unix time.

    Two options for product.

    1. If you have another way to get/sync the time, you may use it instead of SNTP in sample.
    2. If your device has OTA feature, you are able to use SNTPv3 to sync the time for now, once we have the NTPv4 (I believe we will add NTPv4 in future), you may update the firmware to use NTPv4 to sync.

    Some information for reference as below:

    Unix time: it is the number of seconds that have elapsed since the Unix epoch, excluding leap seconds, the Unix epoch is 00:00:00 UTC on 1 January 1970.

    NTP time: it is the number of seconds elapsed since the Unix epoch (00:00:00 UTC on 1 January 1900).

    NTPv3 Timestamp Format : 32-bit for seconds, 32-bit for fraction,

    NTPv4 Data Types: There is a 128-bit date format, the 128-bit date format includes a 64-bit signed seconds field spanning 584 billion years and a 64-bit fraction field.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.