diff options
author | Glenn Moloney <glenn.moloney@gmail.com> | 2024-06-30 22:01:32 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-08-12 16:13:21 +1000 |
commit | 868d311a2361c9125d70833b8757a859a539e8cc (patch) | |
tree | 3458c61ddd3b06872f190b20decc53b83bba8690 | |
parent | 91f4a6b9e902c066c98bda3799e01c8c6c0783ea (diff) |
esp32/network_lan: Make LAN.active(state) succeed if already in state.
This PR ensures that `network.LAN.active(True/False)` will succeed if the
LAN is already in the desired state.
Currently, `lan.active(True)` will raise an `OSError` exception if the LAN
is already in the desired state. This is inconsistent with
`network.WLAN.active(True/False)` and causes `lan.active(True)` to raise an
exception after a soft reset (causing common network startup scripts to
fail for LAN interfaces).
Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
-rw-r--r-- | ports/esp32/network_lan.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/ports/esp32/network_lan.c b/ports/esp32/network_lan.c index 7e7ebcc92..b957c5f89 100644 --- a/ports/esp32/network_lan.c +++ b/ports/esp32/network_lan.c @@ -312,13 +312,14 @@ static mp_obj_t lan_active(size_t n_args, const mp_obj_t *args) { lan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args > 1) { - if (mp_obj_is_true(args[1])) { + bool make_active = mp_obj_is_true(args[1]); + if (make_active && !self->base.active) { esp_netif_set_hostname(self->base.netif, mod_network_hostname_data); self->base.active = (esp_eth_start(self->eth_handle) == ESP_OK); if (!self->base.active) { mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("ethernet enable failed")); } - } else { + } else if (!make_active && self->base.active) { self->base.active = !(esp_eth_stop(self->eth_handle) == ESP_OK); if (self->base.active) { mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("ethernet disable failed")); |