src/eric7/MicroPython/Devices/EspDevices.py

branch
eric7
changeset 10144
45a9177c8e77
parent 10138
56614cf9d03c
child 10153
ffe7432f716b
--- a/src/eric7/MicroPython/Devices/EspDevices.py	Sun Jul 30 17:33:54 2023 +0200
+++ b/src/eric7/MicroPython/Devices/EspDevices.py	Sun Jul 30 17:50:38 2023 +0200
@@ -760,8 +760,6 @@
             except KeyError:
                 error = str(result["status"])
 
-        self._networkConnected = result["connected"]
-
         return result["connected"], error
 
     def disconnectWifi(self):
@@ -793,9 +791,61 @@
         if err:
             return False, err
 
-        self._networkConnected = False
+        return out.decode("utf-8").strip() == "True", ""
+
+    def isWifiClientConnected(self):
+        """
+        Public method to check the WiFi connection status as client.
+
+        @return flag indicating the WiFi connection status
+        @rtype bool
+        """
+        if self.hasCircuitPython():
+            return self.__cpyDevice.isWifiClientConnected()
+
+        command = """
+def wifi_connected():
+    import network
+
+    wifi = network.WLAN(network.STA_IF)
+    print(wifi.isconnected())
+
+wifi_connected()
+del wifi_connected
+"""
+
+        out, err = self.executeCommands(command, mode=self._submitMode)
+        if err:
+            return False
 
-        return out.decode("utf-8").strip() == "True", ""
+        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
+        """
+        if self.hasCircuitPython():
+            return self.__cpyDevice.isWifiApConnected()
+
+        command = """
+def wifi_connected():
+    import network
+
+    wifi = network.WLAN(network.AP_IF)
+    print(wifi.isconnected())
+
+wifi_connected()
+del wifi_connected
+"""
+
+        out, err = self.executeCommands(command, mode=self._submitMode)
+        if err:
+            return False
+
+        return out.strip() == b"True"
 
     def writeCredentials(self, ssid, password):
         """

eric ide

mercurial