Unexpected behaviour from sntp library

aaandro
Posts: 4
Joined: Tue Mar 09, 2021 1:06 pm

Unexpected behaviour from sntp library

Postby aaandro » Thu Mar 25, 2021 3:08 pm

Hi all

I was testing sntp time synchronization on multiple esp32s and noticed small time difference on all.
It got worse, when network quality went down.

Started looking into it and in the 48 byte request packet sent out, only the first byte has value 0x23, rest 0x00.
Essentially missing the "origin timestamp", t0. Therefore making it not very accurate, unless the library has it's own system keeping timestamps of packets sent out?

From wiki
Round trip calculation for delay.
Image

t0 is the client's timestamp of the request packet transmission,
t1 is the server's timestamp of the request packet reception,
t2 is the server's timestamp of the response packet transmission and
t3 is the client's timestamp of the response packet reception.

library used:
esp_sntp.h
https://docs.espressif.com/projects/esp ... ronization

There should be case when t0 is set to 0 when, time has not been synced before, but seems it's always 0s.


Can anyone else confirm this or is this expected?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Unexpected behaviour from sntp library

Postby WiFive » Thu Mar 25, 2021 5:25 pm


aaandro
Posts: 4
Joined: Tue Mar 09, 2021 1:06 pm

Re: Unexpected behaviour from sntp library

Postby aaandro » Fri Mar 26, 2021 1:56 pm

I see, thanks for the direction!

There might be an easier way to do this:

Code: Select all

#define SNTP_CHECK_RESPONSE 0
#define SNTP_COMP_ROUNDTRIP 0
to

Code: Select all

#define SNTP_CHECK_RESPONSE 2
#define SNTP_COMP_ROUNDTRIP 1
in https://github.com/espressif/esp-lwip/b ... h#L96-L136
in order to get origin timestamps moving.



Slightly more difficult in Arduino world, where basically liblwip.a needs recompiling.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Unexpected behaviour from sntp library

Postby WiFive » Fri Mar 26, 2021 4:27 pm

Yes you're right I think probably here https://github.com/espressif/esp-idf/bl ... ts.h#L1007

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 71 guests