-->
Page 5 of 7

Re: [CODE SNIPPET] How I connect to an AP

PostPosted: Sun Apr 14, 2019 7:27 am
by davydnorris
Yes - you could easily instrument my snippet here. The event callback is fired at all the right points. I'll do that once I finally finish this release I'm working on (I just had a week vacation).

I know the SNTP association takes a while because I had to do that with timers and sometimes it takes ages to connect.

Re: [CODE SNIPPET] How I connect to an AP

PostPosted: Sun Apr 14, 2019 8:44 am
by eriksl
BTW do you need real NTP or is SNTP sufficient? Because you're talking of an "association" and SNTP doesn't have a notion of an association. Yesterday I finished my own SNTP implementation. It's about 100 lines of code (or even less) and just works. I send the packet to the NTP server (48 bytes, only a few bits need to be set) and receive a similar packet back containing the current time on the sever, set it, done. I start sending the first packet after the "ip address obtained" callback has arrived, then repeat it every 5 seconds until the first reply arrives. After that, repeat it with a much longer interval of 10 minutes. After re-association or change to the NTP paramters, restart the whole sequence.

Re: [CODE SNIPPET] How I connect to an AP

PostPosted: Sun Apr 14, 2019 9:45 am
by davydnorris
It's actually the DNS lookup that's a large part of the SNTP sync, and the TTL on the public servers means it has to be done every wake. Once the IP address has been found, the actual sync is fast.

Re: [CODE SNIPPET] How I connect to an AP

PostPosted: Sun Apr 14, 2019 12:40 pm
by eriksl
Yeah, understandable.

Can't you use one specific server and skip the DNS lookup? I guess you're using something like 0.pool.ntp.org?

OTOH I made the use of an explicit IP address for SNTP mandatory (which is perfectly fine for an indoors environment, I think), which made (LWIP) DNS and MDNS support no longer a requirement, which in turn saved me one or two kilobytes of DRAM.

Is it a requirement to have a quick time sync after boot? Or is it because you want to have actively powered on as short as possible? Otherwise I guess it wouldn't hurt to wait a few seconds for the time to sync?