fixed error in Lorawan network timesync
This commit is contained in:
parent
4d5417cd6f
commit
8dde6bb13b
@ -45,7 +45,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I
|
||||
|
||||
[common]
|
||||
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
|
||||
release_version = 1.9.971
|
||||
release_version = 1.9.972
|
||||
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
|
||||
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
|
||||
debug_level = 3
|
||||
@ -65,7 +65,7 @@ lib_deps_display =
|
||||
lib_deps_matrix_display =
|
||||
Ultrathin_LED_Matrix@>=1.0.0
|
||||
lib_deps_rgbled =
|
||||
SmartLeds@>=1.1.6
|
||||
SmartLeds@>=1.2.0
|
||||
lib_deps_gps =
|
||||
1655@>=1.0.2 ; #1655 TinyGPSPlus by Mikal Hart
|
||||
lib_deps_sensors =
|
||||
|
@ -226,20 +226,15 @@ void IRAM_ATTR timesync_serverAnswer(void *pUserData, int flag) {
|
||||
// pUserData: contains pointer to SeqNo (not needed here)
|
||||
// flag: indicates if we got a recent time from the network
|
||||
|
||||
uint32_t delay_msec;
|
||||
lmic_time_reference_t lmicTime;
|
||||
|
||||
if (flag != 1) {
|
||||
ESP_LOGW(TAG, "[%0.3f] Network did not answer time request",
|
||||
millis() / 1000.0);
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
// A struct that will be populated by LMIC_getNetworkTimeReference.
|
||||
// It contains the following fields:
|
||||
// - tLocal: the value returned by os_GetTime() when the time
|
||||
// request was sent to the gateway, and
|
||||
// - tNetwork: the seconds between the GPS epoch and the time
|
||||
// the gateway received the time request
|
||||
lmic_time_reference_t lmicTime;
|
||||
|
||||
// Populate lmic_time_reference
|
||||
if ((LMIC_getNetworkTimeReference(&lmicTime)) != 1) {
|
||||
ESP_LOGW(TAG, "[%0.3f] Network time request failed", millis() / 1000.0);
|
||||
@ -247,10 +242,14 @@ void IRAM_ATTR timesync_serverAnswer(void *pUserData, int flag) {
|
||||
}
|
||||
|
||||
// Calculate UTCTime, considering the difference between GPS and UTC time
|
||||
// epoch, and the leap seconds
|
||||
timestamp_sec = lmicTime.tNetwork + GPS_UTC_DIFF;
|
||||
// Add delay between the instant the time was received on the gateway and the
|
||||
// current time on the node
|
||||
timestamp_msec = rxTime - lmicTime.tLocal;
|
||||
|
||||
// Add the delay between the instant the time was transmitted and
|
||||
// the current time
|
||||
delay_msec = osticks2ms(os_getTime() - lmicTime.tLocal);
|
||||
timestamp_sec += delay_msec / 1000;
|
||||
timestamp_msec += delay_msec % 1000;
|
||||
|
||||
goto Finish;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user