improve lora time sync accuracy

This commit is contained in:
cyberman54 2021-07-23 19:10:41 +02:00
parent 177ab88f84
commit 9e1c9c7f59
2 changed files with 7 additions and 7 deletions

View File

@ -6,7 +6,7 @@
#include "timekeeper.h"
#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_END_FLAG (TIME_SYNC_MAX_SEQNO + 1) // end of handshake marker
#define GPS_UTC_DIFF 315964800UL // seconds diff between gps and utc epoch

View File

@ -130,18 +130,18 @@ void IRAM_ATTR timesync_processReq(void *taskparameter) {
// calculate average time offset over the summed up difference
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
// and add time difference rounded to whole seconds
time_offset_sec = timesync_timestamp[sample_idx - 1][gwtime_sec];
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",
myTZ.dateTime(time_offset_sec, "d.M Y H:i:s.v T").c_str());