mirror of
https://github.com/micropython/micropython.git
synced 2025-09-04 08:50:27 +02:00
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>
This commit is contained in:
committed by
Damien George
parent
91f4a6b9e9
commit
868d311a23
@@ -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"));
|
||||
|
Reference in New Issue
Block a user