no one using sntp?
Am 18.07.2018 um 18:54 schrieb Jan Clement:
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
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?
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
any ideas?
regards
j