src/eric7/MicroPython/Devices/EspDevices.py

branch
eric7
changeset 11236
75c26fe1d1c7
parent 11167
a3f5af773bc7
diff -r b984f0085bed -r 75c26fe1d1c7 src/eric7/MicroPython/Devices/EspDevices.py
--- a/src/eric7/MicroPython/Devices/EspDevices.py	Fri Apr 25 16:22:02 2025 +0200
+++ b/src/eric7/MicroPython/Devices/EspDevices.py	Fri Apr 25 16:23:02 2025 +0200
@@ -76,6 +76,24 @@
             6: "WPA3",
             7: "WPA2/WPA3",
         }
+        self.__securityMapping = {
+            "SEC_DPP": "DPP",
+            "SEC_OPEN": self.tr("Open"),
+            "SEC_OWE": "OWE",
+            "SEC_WAPI": "WAPI",
+            "SEC_WEP": "WEP",
+            "SEC_WPA": "WPA",
+            "SEC_WPA_WPA2": "WPA/WPA2",
+            "SEC_WPA2": "WPA2",
+            "SEC_WPA2_ENT": "WPA2 Enterprise",
+            "SEC_WPA2_WPA3": "WPA2/WPA3",
+            "SEC_WPA2_WPA3_ENT": "WPA2/WPA3 Enterprise",
+            "SEC_WPA3": "WPA3",
+            "SEC_WPA3_ENT": "WPA3 Enterprise",
+            "SEC_WPA3_ENT_192": "WPA3 Enterprise (192-bit)",
+            "SEC_WPA3_EXT_PSK": "WPA3 Extended",
+            "SEC_WPA3_EXT_PSK_MIXED_MODE": "WPA3 Extended, Mixed Mode",
+        }
 
     def __createCpyDevice(self):
         """
@@ -718,6 +736,12 @@
     import ujson
     import network
 
+    def security_str(mode):
+        for sm in [e for e in dir(network.WLAN) if e.startswith('SEC_')]:
+            if getattr(network.WLAN, sm, 0) == mode:
+                return sm
+        return ""
+
     wifi = network.WLAN(network.STA_IF)
     station = {
         'active': wifi.active(),
@@ -742,6 +766,7 @@
         'mac': ubinascii.hexlify(wifi.config('mac'), ':').decode(),
         'channel': wifi.config('channel'),
         'essid': wifi.config('essid'),
+        'ap_security': security_str(wifi.config('security')),
     }
     if wifi.active():
         try:
@@ -783,6 +808,11 @@
             ap["status"] = self.__statusTranslations[ap["status"]]
         except KeyError:
             ap["status"] = str(ap["status"])
+        if "ap_security" in ap:
+            try:
+                ap["ap_security"] = self.__securityMapping[ap["ap_security"]]
+            except KeyError:
+                ap["ap_security"] = self.tr("unknown ({0})").format(ap["ap_security"])
         return station, ap, overall
 
     def connectWifi(self, ssid, password, hostname):
@@ -1188,8 +1218,8 @@
 
         @param ssid SSID of the access point
         @type str
-        @param security security method (defaults to None)
-        @type int (optional)
+        @param security security mode (defaults to None) (unused)
+        @type str (optional)
         @param password password (defaults to None)
         @type str (optional)
         @param hostname host name of the device (defaults to None)
@@ -1210,13 +1240,11 @@
             )
 
         if security is None or password is None:
-            security = 0
+            security = "SEC_OPEN"
             password = ""  # secok
-        if security > 4:
-            security = 4  # security >4 cause an error thrown by the ESP32
 
         command = """
-def start_ap(ssid, authmode, password, hostname, ifconfig):
+def start_ap(ssid, password, hostname, ifconfig):
     import network
 
     if hostname:
@@ -1231,14 +1259,14 @@
         ap.ifconfig(ifconfig)
     ap.active(True)
     try:
-        ap.config(ssid=ssid, authmode=authmode, password=password)
+        ap.config(ssid=ssid, authmode=network.WLAN.{4}, password=password)
     except:
-        ap.config(essid=ssid, authmode=authmode, password=password)
+        ap.config(essid=ssid, authmode=network.WLAN.{4}, password=password)
 
-start_ap({0}, {1}, {2}, {3}, {4})
+start_ap({0}, {1}, {2}, {3})
 del start_ap
 """.format(
-            repr(ssid), security, repr(password), repr(hostname), ifconfig
+            repr(ssid), repr(password), repr(hostname), ifconfig, security
         )
 
         out, err = self.executeCommands(command, mode=self._submitMode, timeout=15000)

eric ide

mercurial