solutions
LoRa Basics Modem and LoRa Edge documentation
Component - Clock Synchronization¶
Introduction¶
Clock Synchronization is a Modem service that provides the time for user applications and some operations (for example, a GNSS assisted scan).
Compatibility¶
Prerequisites¶
Common:
The device must be joined to a LoRaWAN® network
The application server must forward messages on a configured Device Management FPort (199 by default) to
mgs.loracloud.com
.
Prerequisites for LoRa Basics™ Modem:
The device must have a Real Time Clock (RTC).
Prerequisites for LoRa Basics™ Modem-E:
32.768 kHz crystal or the externally supplied clock to the LR1110 chip.
Step-by-Step Procedure¶
Enable Clock Sync on the device. (Clock Sync is disabled by default).
Wait for the event
timeUpdatedClockSync
(with parameterstatus=1: time sync done
).When synced, the
getTime()
command fetches the time from the device in GPS epoch format: seconds elapsed since 00:00:00 January 6th 1980.If the device loses its time sync (that is, after six days without resynchronizing with the server) the
timeUpdateClockSync
event is triggered (with the parameterstatus=0: time sync lost
). The user must then wait for the clock to be synchronized again.
Note
The getTime()
command returns 0
when the time is not synchronized or has lost its synchronization. If the time is set with setTime()
, no event is generated. The time is considered not valid after six (6) days without a new call to the setTime()
command.
Sample Code¶
Embedded
#include "lr1110_modem_lorawan.h"
// Activate Clock Sync
lr1110_modem_set_alc_sync_mode( &context, LR1110_MODEM_ALC_SYNC_MODE_ENABLE );
// Get time since GPS epoch (elapsed seconds since 00:00:00 January 6th 1980)
uint32_t gps_time = 0;
lr1110_modem_get_gps_time( &context, &gps_time );
// Modem event call-back
customer_event_callback_alc_sync_time_update( lr1110_modem_alc_sync_state_t status ) {
if ( status == LR1110_MODEM_ALC_SYNC_DESYNCHRONIZED ) {
printf( "ALCSYNC - Lost time synchronization\n" );
} else { // status == 1
printf( "ALCSYNC - Acquired time synchronization\n" );
}
}
In-depth Behavior¶
This service assumes that there is little or no delay in the Clock Sync request from either the LoRa Basics™ Modem or LoRa Basics Modem-E. Any delay introduced on this request will create an offset in a Modem’s time. There is no requirement on downlink timing.
Note
As per the LoRaWAN specification, the LoRa Cloud™ Modem & Geolocation Services will answer only if the timing inaccuracy of the LoRa Basics Modem or LoRa Basics Modem-E is more than one (1) second when the bit AnsRequired
is not set.
The possible states are as follows.
Not Synchronized
Once enabled, the modem sends
Clock Sync
requests to the LoRa Cloud™ Modem & Geolocation Services for the initial time synchronization.The LoRa Cloud™ Modem & Geolocation Services asks the application server to queue a downlink with its answer.
Recent Synchronization (less than 3 days)
Every 36 hours the modem sends an
Clock Sync
request to the LoRa Cloud™ Modem & Geolocation Services.If the modem clock has drifted, the LoRa Cloud™ Modem & Geolocation Services asks the application server to queue a downlink with its answer.
No Recent Synchronization (more than 3 days)
Every 36 hours the modem sends an
Clock Sync
request to the LoRa Cloud™ Modem & Geolocation Services, asking for a mandatory answer.The LoRa Cloud™ Modem & Geolocation Services asks the application server to queue a downlink with its answer.
De-synchronized
If the modem gets no update after six (6) days it will consider its time not valid.
Used by¶
GNSS |
Troubleshooting¶
Time is never synchronized¶
The time request has probably not been delivered to the LoRa Cloud™ Modem & Geolocation Services, or the LoRa Cloud™ Modem & Geolocation Services’ answer has not reached the modem.
Determine whether uplinks are being correctly delivered to the LoRa Cloud™ Modem & Geolocation Services.
Determine whether the LoRa Cloud™ Modem & Geolocation Service is creating a downlink when it receives a
Clock Sync
request (a DM frame with first byte equal to0x18
).Ensure that the LoRa Cloud™ Modem & Geolocation Services’ downlinks are being sent to the modem.
Synchronized time has an offset of several minutes¶
There might be a delay between the Clock Sync uplink sent by the modem and its delivery to the LoRa Cloud™ Modem & Geolocation Services. To address this issue, review this recommendation.
References¶
LoRa Basics™ Modem-E API Reference Manual chapters 2.3.4, 6.8, 6.52 and 6.53.
LoRa Basics Modem and LoRa Edge documentation
Table of Contents
- Overview - LoRa Edge™ Asset Management Platform
- Use Case - Basic Asset Tracking
- Use Case - IR Image Upload on Detected Motion
- Scenario - GNSS Assisted Scan
- Scenario - GNSS Autonomous Scan
- Scenario - LoRa Basics™ Wi-Fi Passive Scan
- Scenario - GNSS Scan with ROSE
- Scenario - Wi-Fi Scan with ROSE
- Scenario - LoRa Cloud™ Join Server
- Scenario - Claiming a Device
- Scenario - Unclaiming a Device
- Scenario - Modem-E Initialization
- Scenario - LoRa Basics™ Almanac Update
- Scenario - User Loaded Almanac Update
- Scenario - Intermittent Network
- Component - Clock Synchronization
- Component - Large File Upload
- Component - Reliable Octet Stream Encoding
- Cryptographic Engine
- Glossary
ADDITIONAL RESOURCES - VIDEOS