diff --git a/include/timesync.h b/include/timesync.h index 0cfe5571..f6d8fe80 100644 --- a/include/timesync.h +++ b/include/timesync.h @@ -11,6 +11,7 @@ #define TIME_SYNC_TIMEOUT 120 // timeout seconds waiting for timeserver answer #define TIME_SYNC_TRIGGER 100 // time deviation in millisec triggering a sync #define TIME_SYNC_FRAME_LENGTH 0x06 // timeserver answer frame length +#define TIME_SYNC_FIXUP 0 // calibration millisec to fixup processing time void send_timesync_req(void); int recv_timesync_ans(uint8_t buf[], uint8_t buf_len); diff --git a/src/timesync.cpp b/src/timesync.cpp index 514a5ea3..3e62a9fb 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -124,6 +124,8 @@ void process_timesync_req(void *taskparameter) { // calculate absolute time offset with millisecond precision using time base // of LMIC os, since we use LMIC's ostime_t txEnd as tx timestamp time_offset += milliseconds(osticks2ms(os_getTime())); + // apply calibration factor for processing time + time_offset += milliseconds(TIME_SYNC_FIXUP); // convert to seconds time_to_set = static_cast(myClock_secTick(time_offset).count()); // calculate fraction milliseconds @@ -138,9 +140,9 @@ void process_timesync_req(void *taskparameter) { TIME_SYNC_TRIGGER) { // milliseconds threshold // wait until top of second - ESP_LOGD(TAG, "[%0.3f] waiting %d ms", millis() / 1000.0, - 1000 - time_to_set_fraction_msec); - vTaskDelay(pdMS_TO_TICKS(1000 - time_to_set_fraction_msec)); + uint16_t const wait_ms = 1000 - time_to_set_fraction_msec; + ESP_LOGD(TAG, "[%0.3f] waiting %d ms", millis() / 1000.0, wait_ms); + vTaskDelay(pdMS_TO_TICKS(wait_ms)); // sync timer pps to top of second if (ppsIRQ) {