diff -r bf84513859ca -r 45a9177c8e77 src/eric7/MicroPython/Devices/CircuitPythonDevices.py --- a/src/eric7/MicroPython/Devices/CircuitPythonDevices.py Sun Jul 30 17:33:54 2023 +0200 +++ b/src/eric7/MicroPython/Devices/CircuitPythonDevices.py Sun Jul 30 17:50:38 2023 +0200 @@ -911,8 +911,6 @@ result = json.loads(out.decode("utf-8").strip()) error = "" if result["connected"] else result["status"] - self._networkConnected = result["connected"] - return result["connected"], error def disconnectWifi(self): @@ -944,11 +942,54 @@ if err: return False, err - self._networkConnected = False - result = json.loads(out.decode("utf-8").strip()) return result["success"], result["status"] + def isWifiClientConnected(self): + """ + Public method to check the WiFi connection status as client. + + @return flag indicating the WiFi connection status + @rtype bool + """ + command = """ +def wifi_connected(): + import wifi + + r = wifi.radio + print(r.ipv4_address is not None) + +wifi_connected() +del wifi_connected +""" + + out, err = self.executeCommands(command, mode=self._submitMode) + if err: + return False + + return out.strip() == b"True" + + def isWifiApConnected(self): + """ + Public method to check the WiFi connection status as access point. + + @return flag indicating the WiFi connection status + @rtype bool + """ + command = """ +def wifi_connected(): + import wifi + + r = wifi.radio + print(r.ipv4_address_ap is not None) +""" + + out, err = self.executeCommands(command, mode=self._submitMode) + if err: + return False + + return out.strip() == b"True" + def writeCredentials(self, ssid, password): """ Public method to write the given credentials to the connected device and modify @@ -1398,8 +1439,6 @@ if err: return False, err - self._networkConnected = True - return out.strip() == b"True", "" def disconnectFromLan(self): @@ -1432,9 +1471,32 @@ if err: return False, err - self._networkConnected = False + return out.strip() == b"True", "" + + def isLanConnected(self): + """ + Public method to check the LAN connection status. + + @return flag indicating that the device is connected to the LAN + @rtype bool + """ + command = """{0} +def is_connected(): + w5x00_init() - return out.strip() == b"True", "" + print(nic.link_status == 1 and nic.ifconfig[0] != b'\x00\x00\x00\x00') + +is_connected() +del is_connected, w5x00_init +""".format( + WiznetUtilities.cpyWiznetInit(), + ) + + out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000) + if err: + return False + + return out.strip() == b"True" def checkInternetViaLan(self): """