Pretty much my experience though I'm not sure I have as many failures or the same analysis of why.Maybe it fails 10 times in a row, and then succeeds several times in a row, all within the span of 15 minutes or so. When it is successful, the back and forth comm seem to work well for at least an hour (the longest I have tested).
The ping behaviour you earlier described may be correct, as expected. From initially being plugged-in and powered-up, you won't get pings until it has done its first 'wlan.connect(...) and 'wlan.isconnected()' becomes True.
Then comes a hierarchy of states ...
Code:
Termination | Ctrl-C, program ends, exception, Thonny 'Stop'Soft Reset | Ctrl-D, machine.soft_reset(), Thonny 'Start'Hard Reset | Reset button, machine.reset(), watchdog, USB forced BOOTSELPower Off | Turned off, unplugged
A Hard Reset seems to put it into something like the initial state but how close I am not sure. It then requires the 'wlan.connect(...)' etc so I presume that will stop it responding to pings. I don't know when the driver firmware is loaded or re-loaded, if it is when it hasn't been powered off.
A Soft Reset and anything less won't affect the Wi-Fi chip so the network remains connected and it should respond to pings, continue to respond to do so until Hard Reset or Power Off..
As to 'wlan.disconnect()', 'wlan.deinit()' and 'network.deinit()'; I am not sure. They will probably close the network, prevent pings, but perhaps don't return the Wi-Fi chip to its initial state.
There's also 'LwIP', the Lightweight IP stack, which handles networking packets, responds to the ping. It starts immediately I think, but won't do anything, doesn't have anything to do, until the network is first established, when 'wlan.isconnected()' becomes True.
After that it keeps running, but won't have anything to do if the network is no longer connected. A Hard Reset or Power Off should put it back to its initial state. I don't believe anything less will.
I may be wrong but I believe my issues may be 'LwIP' related. I think it's getting confused; that there's a backlog of packets building up or dropped, through network errors, program exceptions, not closing sockets, not reading or sending exactly what one should. This confusion then leads to exceptions in MicroPython code which simply compounds its confusion and it keeps 'not working' after that. If lucky it shakes itself back into shape and then will keep working fine until something happens to confuse it again.
Program bugs seem to cause 'LwIP' to think things happened, or more likely did not happen, which sometimes gets it confused. Those bugs are exactly what should be expected during development, trying to figure out how to do things.
So, after any program bug, any socket error, any program termination even, the wisest course is to power-cycle both server and client before trying again. But that's not a great or agile way of working, developing, debugging; "Ain't nobody got time for that".
Statistics: Posted by hippy — Thu Mar 07, 2024 9:11 am