From 9c244134fb4db921f721737763f81cd9300c2e86 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 19 Oct 2023 15:05:59 +0200 Subject: [PATCH] esp32/network_lan: Fix LAN.isconnected(). nic.isconnected() returns now "True", if a) the physical link is up and b) an IP address is assigned. The latter happens often by DHCP, in which case an active connection can be assumed. If the IP address is set manually, nic.isconnected() would report "True" as well, if at least the physical link is up. This matches WLAN behaviour which returns "True" when the WLAN has an IP address. Before, the behaviour of nic.isconneceted() was erratic, returning "True" sometimes even without a Ethernet cable attached. Fixes issue #12741. Signed-off-by: robert-hh --- ports/esp32/network_lan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32/network_lan.c b/ports/esp32/network_lan.c index 0e42f403c..15a5110b1 100644 --- a/ports/esp32/network_lan.c +++ b/ports/esp32/network_lan.c @@ -325,7 +325,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(lan_status_obj, lan_status); STATIC mp_obj_t lan_isconnected(mp_obj_t self_in) { lan_if_obj_t *self = MP_OBJ_TO_PTR(self_in); - return self->base.active ? mp_obj_new_bool(self->phy->get_link(self->phy) == ETH_LINK_UP) : mp_const_false; + return mp_obj_new_bool(self->base.active && (eth_status == ETH_GOT_IP)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(lan_isconnected_obj, lan_isconnected);