src/eric7/MicroPython/Devices/RP2Devices.py

branch
eric7
changeset 11270
0e220c26e60e
parent 11266
97311a9616e3
--- a/src/eric7/MicroPython/Devices/RP2Devices.py	Tue May 06 11:09:21 2025 +0200
+++ b/src/eric7/MicroPython/Devices/RP2Devices.py	Tue May 06 15:32:29 2025 +0200
@@ -795,7 +795,7 @@
 
         return station, ap, overall
 
-    def connectWifi(self, ssid, password, hostname):
+    def connectWifi(self, ssid, password, hostname, country=""):
         """
         Public method to connect a device to a WiFi network.
 
@@ -805,19 +805,25 @@
         @type str
         @param hostname host name of the device
         @type str
+        @param country WiFi country code
+        @type str
         @return tuple containing the connection status and an error string
         @rtype tuple of (bool, str)
         """
         if self._deviceData["wifi_type"] == "picow":
-            country = Preferences.getMicroPython("WifiCountry").upper()
+            if not country:
+                country = Preferences.getMicroPython("WifiCountry").upper()
             command = """
 def connect_wifi(ssid, password, hostname, country):
     import network
-    import rp2
     import ujson
     from time import sleep
 
-    rp2.country(country)
+    try:
+        network.country(country)
+    except AttributeError:
+        import rp2
+        rp2.country(country)
 
     if hostname:
         try:
@@ -830,9 +836,7 @@
     wifi.active(True)
     wifi.connect(ssid, password)
     max_wait = 140
-    while max_wait:
-        if wifi.status() < 0 or wifi.status() >= 3:
-            break
+    while max_wait and wifi.status() != network.STAT_GOT_IP:
         max_wait -= 1
         sleep(0.1)
     status = wifi.status()
@@ -1946,7 +1950,7 @@
                 ethStatus["hostname"] if ethStatus["hostname"] else self.tr("unknown"),
             ),
             (self.tr("MAC-Address"), ethStatus["mac"]),
-            (self.tr("Preferred IP Version"), str(ethStatus["prefer"]))
+            (self.tr("Preferred IP Version"), str(ethStatus["prefer"])),
         ]
         addressInfo = {
             "ipv4": ethStatus["ipv4_addr"],
@@ -1984,9 +1988,7 @@
     nic.active(True)
     nic.ifconfig(config)
     max_wait = 140
-    while max_wait:
-        if nic.isconnected():
-            break
+    while max_wait and not nic.isconnected():
         max_wait -= 1
         time.sleep(0.1)
     print(nic.isconnected())

eric ide

mercurial