Closed janakj closed 1 year ago
I've been wanting this too, for setting the time on an hardware RTC from "network time"
What accuracy are you looking to obtain? Second-level accuracy is relatively simple. Anything better may require support from the LoRaWAN network.
-Jan
Second-level accuracy is more than adequate adequate for my purposes
Hi @vicatcu,
I just committed the first version of time synchronization support based on the DeviceTimeReq
LoRaWAN MAC command. See this wiki page for more information. This method should be accurate to +- 100 milliseconds.
There is a new AT command called AT$DEVTIME
which triggers time synchronization in the modem. You will eventually get the current time via an +ANS
notification:
AT$DEVTIME
+OK
+EVENT=2,1
+ANS=13,1369371195,200
Number 13 in the +ANS
notification identifies a time synchronization response. The second parameter is GPS time, i.e., the number of seconds since the GPS epoch (January 6, 1980 UTC). The third parameter represents a fraction of a second (in milliseconds).
Converting GPS time to UTC, e.g., if you want to display current date and time to the user, generally requires a leap second table. At the moment, you can convert the value to GPS by adding 315964800 (difference between GPS and UTC epochs) and subtracting 18 (18 leap seconds have been inserted since GPS epoch).
This method requires LoRaWAN 1.0.3 or higher. I have tested it with the The Things Network where it seems to work well.
This feature will eventually be released as part of version 1.5.0. If you know how to build your own firmware binary the source code, feel free to give it a try now.
-Jan
This feature is now implemented in the firmware, in the companion Python library, and documented in the wiki.
The LoRaWAN protocol provides a couple of mechanisms that could be used to synchronize the clock on the device. Design an ATCI protocol through which LoRaWAN-based time synchronization could be extended all the way to the main MCU on the Core module. With that, we could synchronize the wall clock time in the RTC via LoRa without the need to have a GPS receiver on the device.
This could be useful in devices such as the LoRa tester where the time could be displayed on the LCD.