Has anyone made progress on this issue?
I've encountered similar flakiness with ntptime.py (borrowed as above from the ESP8266 port) using MicroPython v1.18 on a PYBD-SF2W.
However, a hard reboot to reset the wifi seems at this point unnecessary.
I've set
Code: Select all
s.settimeout(10)
#s.settimeout(1)
in ntptime.py. Using test code
Code: Select all
from network import WLAN, STA_IF, AP_IF
from time import sleep_ms
import ntptime
ap = WLAN(AP_IF) # create access-point interface
ap.active(False) # deactivate the interface
sleep_interval = 500
stats = [0,0,0,0]
success = [0,0]
wlan = WLAN(STA_IF)
sleep_ms(sleep_interval)
wlan.active(True)
sleep_ms(sleep_interval)
wlan.connect(ssid, passwd)
sleep_ms(sleep_interval)
for i in range(100):
try:
status_before = wlan.status()
t=ntptime.time()
status_after = wlan.status()
print(i,status_before,status_after,t)
success[1] += 1
except Exception as ex:
status_after = wlan.status()
print(i,status_before,status_after,'ntptime error:',ex)
success[0] += 1
finally:
stats[status_after] += 1
sleep_ms(sleep_interval)
wlan.disconnect()
wlan.deinit()
print('\n\nSuccess results:')
print(success)
print('Status results:')
print(stats)
gives results like
Code: Select all
0 1 1 ntptime error: [Errno 113] EHOSTUNREACH
1 1 1 ntptime error: [Errno 113] EHOSTUNREACH
2 1 1 ntptime error: [Errno 113] EHOSTUNREACH
3 1 1 ntptime error: [Errno 113] EHOSTUNREACH
4 1 1 ntptime error: [Errno 113] EHOSTUNREACH
5 2 2 ntptime error: [Errno 113] EHOSTUNREACH
6 3 3 ntptime error: [Errno 110] ETIMEDOUT
7 3 3 706373344
8 3 3 706373345
9 3 3 706373345
10 3 3 706373346
11 3 3 706373347
12 3 3 706373347
13 3 3 706373348
14 3 3 ntptime error: [Errno 110] ETIMEDOUT
15 3 3 706373359
16 3 3 706373360
and
Code: Select all
Success results:
[21, 79]
Status results:
[0, 5, 1, 94]
The EHOSTUNREACH errors almost always occur at the start, with wlan.status<3, so this error could be easily circumvented.
ETIMEDOUT errors do not seem predictable from wlan.status.
Does anyone have insight into the root cause of these errors? If not, error handling like the above may be adequate for my application at least.