improve lora time sync accuracy
This commit is contained in:
parent
177ab88f84
commit
9e1c9c7f59
@ -6,7 +6,7 @@
|
|||||||
#include "timekeeper.h"
|
#include "timekeeper.h"
|
||||||
|
|
||||||
#define TIME_SYNC_FRAME_LENGTH 6 // timeserver answer frame length [bytes]
|
#define TIME_SYNC_FRAME_LENGTH 6 // timeserver answer frame length [bytes]
|
||||||
#define TIME_SYNC_FIXUP 16 // compensation for processing time [milliseconds]
|
#define TIME_SYNC_FIXUP 25 // compensation for processing time [milliseconds]
|
||||||
#define TIME_SYNC_MAX_SEQNO 0xfe // threshold for wrap around time_sync_seqNo
|
#define TIME_SYNC_MAX_SEQNO 0xfe // threshold for wrap around time_sync_seqNo
|
||||||
#define TIME_SYNC_END_FLAG (TIME_SYNC_MAX_SEQNO + 1) // end of handshake marker
|
#define TIME_SYNC_END_FLAG (TIME_SYNC_MAX_SEQNO + 1) // end of handshake marker
|
||||||
#define GPS_UTC_DIFF 315964800UL // seconds diff between gps and utc epoch
|
#define GPS_UTC_DIFF 315964800UL // seconds diff between gps and utc epoch
|
||||||
|
@ -131,17 +131,17 @@ void IRAM_ATTR timesync_processReq(void *taskparameter) {
|
|||||||
// calculate average time offset over the summed up difference
|
// calculate average time offset over the summed up difference
|
||||||
time_offset_ms /= TIME_SYNC_SAMPLES;
|
time_offset_ms /= TIME_SYNC_SAMPLES;
|
||||||
|
|
||||||
|
// add milliseconds from latest gateway time, and apply a compensation
|
||||||
|
// constant for processing times on node and gateway, strip full seconds
|
||||||
|
time_offset_ms += timesync_timestamp[sample_idx - 1][gwtime_msec];
|
||||||
|
time_offset_ms -= TIME_SYNC_FIXUP;
|
||||||
|
time_offset_ms %= 1000;
|
||||||
|
|
||||||
// take latest timestamp received from gateway
|
// take latest timestamp received from gateway
|
||||||
// and add time difference rounded to whole seconds
|
// and add time difference rounded to whole seconds
|
||||||
time_offset_sec = timesync_timestamp[sample_idx - 1][gwtime_sec];
|
time_offset_sec = timesync_timestamp[sample_idx - 1][gwtime_sec];
|
||||||
time_offset_sec += time_offset_ms / 1000;
|
time_offset_sec += time_offset_ms / 1000;
|
||||||
|
|
||||||
// add milliseconds from latest gateway time, and apply a compensation
|
|
||||||
// constant for processing times on node and gateway, strip full seconds
|
|
||||||
time_offset_ms += timesync_timestamp[sample_idx - 1][gwtime_msec];
|
|
||||||
time_offset_ms += TIME_SYNC_FIXUP;
|
|
||||||
time_offset_ms %= 1000;
|
|
||||||
|
|
||||||
ESP_LOGD(TAG, "LORA date/time: %s",
|
ESP_LOGD(TAG, "LORA date/time: %s",
|
||||||
myTZ.dateTime(time_offset_sec, "d.M Y H:i:s.v T").c_str());
|
myTZ.dateTime(time_offset_sec, "d.M Y H:i:s.v T").c_str());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user