network: status codes/constants not unified across ports
Working with latest builds (20230422-unstable-v1.19.1-1019) of micropython I found some discrepancies:
ESP32 generic does not have STAT_CONNECT_FAIL in network module.
I noticed that status code value for connecting is 1 in rp2w and 1001 in ESP32.
If we should use constants from documentation then they should be implemented in all ports (please).
Some examples use codes (which is bad) that means they do not work correctly over ports
esp32: Add missing network.STAT_CONNECT_FAIL constant.
Summary
The esp32 port had network.STAT_ASSOC_FAIL for the same purpose, but this is undocumented and different to all other ports which use the documented STAT_CONNECT_FAIL. This PR deprecates STAT_ASSOC_FAIL for removal in MicroPython 2.0.
Closes #13167
This work was funded through GitHub Sponsors.
Testing
Flashed ESP32 port, checked that both constants exist and have the same numeric value.
Trade-offs and Alternatives
Having two STAT_ constants with the same numeric value might break someone's code if they're building a lookup table with reflection (for example), but I think this is preferable to either having to document port-specific statuses, or removing STAT_ASSOC_FAIL which will definitely break someone's code.
Future work
I see that a bunch of ESP32-specific constants have been added (STAT_NO_AP_FOUND_IN_RSSI_THRESHOLD, STAT_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD, etc.) These are undocumented and make it hard to write portable code using the WLAN interface.
Suggest in a future PR to remove these (return STAT_NO_AP_FOUND for these cases), and add a wlan.status('verbose') or similar that can return additional port-specific details like this as a short string.