sntp.sync must perform sync successfully after Internet connection is established.
Here are the specific steps to reproduce:
sntp.sync must fail on 1st attempt)sntp.sync in auto-repeat modesntp.syncsntp.sync still keeps on failing with error code 4Note: the pattern of errors: error code 1 (DNS lookup failed) followed by many 4(Timeout, no NTP response received) is necessary to reproduce the problem.
Providing a Minimal, Complete, and Verifiable example which will reproduce the problem.
NodeMCU custom build by frightanic.com
branch: master
commit: 5073c199c01d4d7bbbcd0ae1f761ecc4687f7217
SSL: false
modules: file,gpio,net,node,rtctime,sntp,tmr,uart,wifi
build built on: 2018-02-26 00:15
powered by Lua 5.1.4 on SDK 2.1.0(116b762)
lua: cannot open init.lua
> =wifi.setmode(wifi.STATION)==wifi.STATION
true
> =wifi.sta.getip()
nil
> =wifi.sta.config({ssid="<ssid>", pwd="<password>"})
true
> =wifi.sta.connect()
> =wifi.sta.getip()
10.10.10.1 255.255.255.0 10.10.10.254
> sntp.sync(nil, function(sec) print(sec) end, function(err_code, err_desc) print(err_code, err_desc) end, 1)
> 1 0.nodemcu.pool.ntp.org
4 nil
4 nil
4 nil
4 nil
Note: after ESP printed 1, 4, 4; the Internet connection was re-established and sntp.sync kept on failing with same error code.
Branch: master
Revision: 5073c199c01d4d7bbbcd0ae1f761ecc4687f7217 (latest)
NodeMCU version 2 Amica
The autorepeat fails because of the initial DNS lookup failure. The current implementation will not try to recover from this automatically. So it will not retry a failed DNS lookup. After the initial attempt it assumes it correctly got a valid IP address.
There are several workarounds for this:
Or we can have a look to fix this in the firmware, by applying the autorepeat also to the DNS lookup.
I'll take a look at this and fix it it properly.
I have a fix, but it needs more testing.... Hope to get a PR up in the next couple of days.
The current code is in https://github.com/pjsg/nodemcu-firmware/tree/fix-sntp-lookup
Most helpful comment
I'll take a look at this and fix it it properly.