Resolve #3913: Missing esp32 status() implementation#3942
Resolve #3913: Missing esp32 status() implementation#3942mitchins wants to merge 3 commits intomicropython:masterfrom
Conversation
Define success codes explicitly Re-use the ESP-IDF codes for errors
|
@dpgeorge apologies but GitHub created a new PR as the old one was closed. |
| if (self->if_id == WIFI_IF_STA) { | ||
| // Case of no arg is only for the STA interface | ||
| if (wifi_sta_connected) { | ||
| return MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP); |
There was a problem hiding this comment.
You want to return the number, like MP_OBJ_NEW_SMALL_INT(STAT_GOT_IP)
| if (wifi_sta_connected) { | ||
| return MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP); | ||
| } else if (wifi_sta_connect_requested) { | ||
| return MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING); |
There was a problem hiding this comment.
Same as above, return STAT_CONNECTING.
| } else if (wifi_sta_connect_requested) { | ||
| return MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING); | ||
| } else { | ||
| switch (wifi_sta_disconn_reason) { |
There was a problem hiding this comment.
And here you can just return MP_OBJ_NEW_SMALL_INT(wifi_sta_disconn_reason). Then you don't need any switch statement at all. That was the reason to reuse the constants from the IDF.
|
@dpgeorge updated, it seemed to have vanished into a stash. Thanks. |
There was a problem hiding this comment.
Atom keeps stripping the ' ' every time I sae the file.
c0e213e to
0ca94cd
Compare
| { MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(WIFI_REASON_AUTH_FAIL)}, | ||
| { MP_ROM_QSTR(MP_QSTR_STAT_ERROR_BEACON_TIMEOUT), MP_ROM_INT(WIFI_REASON_BEACON_TIMEOUT)}, | ||
| { MP_ROM_QSTR(MP_QSTR_STAT_ERROR_ASSOC_FAIL), MP_ROM_INT(WIFI_REASON_ASSOC_FAIL)}, | ||
| { MP_ROM_QSTR(MP_QSTR_STAT_ERROR_HANDSHAKE_TIMEOUT), MP_ROM_INT(WIFI_REASON_HANDSHAKE_TIMEOUT)}, |
There was a problem hiding this comment.
I think for these 3 constants the "ERROR" part is not needed. Simply STAT_ASSOC_FAIL would be enough, etc.
There was a problem hiding this comment.
Agreed, it's a little verbose and it's universally inferred to be an error. Will change
|
Thanks for updating. I squashed the commits and merged them in 385fa51. I changed indentation to match the existing code. |
Resubmit with cleaner rebase and diff'ing. (GitHub
closed the old one automatically)
Implements the default method (no args) which provides the link status for the STA_IF on ESP32 devices.
Implementation is inspired and consistent with ESP8266, success codes are named similarly, as are most error names. Error codes and names for wifi disconnect are otherwise taken (returned directly) from what the ESP-IDF gives us but are defined in the const dictionary where appropriate.
Success codes are number from 1000 upwards so as not to clash with the 8-bit error codes from ESP-IDF.
Tested connection. failure and success on Wemos R32 device, it seems to return as expected.
wifi_log.txt
Log attached