Commit 868d311a authored by Glenn Moloney's avatar Glenn Moloney Committed by Damien George

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: default avatarGlenn Moloney <glenn.moloney@gmail.com>
parent 91f4a6b9
......@@ -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"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment