Hi Jan, On Wed, Jul 18, 2018 at 06:54:01PM +0200, Jan Clement wrote: > Hello All, > > i tried to get sntp client from lwip stack up and running today and > stumbled over some little problems and questions i would like to share > with you: > > To start the sntp service I wrote: > > sntp_setoperatingmode(SNTP_OPMODE_POLL); > ip_addr_t ntp_server; > IP4_ADDR(&ntp_server.u_addr.ip4, 94, 16, 116, 137);//0.de.pool.ntp.org > sntp_setserver(0, &ntp_server); > sntp_init(); > > But the callback function, called by the stack upon receive of the > packet is defined as follows in lwip/apps/sntp_ops.h: > > #if !defined SNTP_SET_SYSTEM_TIME || defined __DOXYGEN__ > #define SNTP_SET_SYSTEM_TIME(sec) LWIP_UNUSED_ARG(sec) > #endif
It looks like lwIP expects this macro to be defined by the OS (as you probably inferred!). > And nothing happens. > > So I commented this out, and added > extern void SNTP_SET_SYSTEM_TIME(uint32_t t); > to sntp.c. > > in my code i defined > void SNTP_SET_SYSTEM_TIME(uint32_t t) { > > ntptime.tv_sec = t * 1000; > ntptime.tv_usec = 0; > console_printf("SNTP time from server: %ld \r\n", t); > os_settimeofday(&ntptime, NULL); > } > > And this works as expected and I get the correct ntp time stamp! > > What would be a good and proper way to implement the callback function? I think your implementation is fine! I would just turn that into a function (with a lower-case name), and define `SNTP_SET_SYSTEM_TIME` to call your function. > > Another problem is, that os_gettimeofday(&daytime, NULL); gives weird > results: > > 005104 Time = 21474836480 > 006104 Time = 25769803776 > 007104 Time = 30064771072 > 008104 Time = 34359738368 > 009104 Time = 38654705664 > 010104 Time = 42949672960 > 010134 SNTP time from server: 1531932280 > (** syncronization happened) > 010136 Date: 18.6.2018 16:44:40 > > after the sync this is the ouput: > 011104 Time = 6579599043818647160 > 012104 Time = 6579599048113614456 > 013104 Time = 6579599052408581752 > 014104 Time = 6579599056703549048 Hmm, that's odd. How are you printing the `struct os_timeval` value that `os_gettimeofday` fills in? Chris