--- a/src/eric7/MicroPython/Devices/EspDevices.py Tue May 06 11:09:21 2025 +0200 +++ b/src/eric7/MicroPython/Devices/EspDevices.py Tue May 06 15:32:29 2025 +0200 @@ -57,7 +57,7 @@ 200: self.tr("beacon timeout"), 201: self.tr("no matching access point found"), 202: self.tr("authentication failed"), - 203: self.tr("association failed"), + 203: self.tr("connection failed"), 204: self.tr("handshake timeout"), 210: self.tr("no access point with compatible security found"), 211: self.tr("no access point with suitable authentication mode found"), @@ -839,7 +839,7 @@ ap["ap_security"] = self.tr("unknown ({0})").format(ap["ap_security"]) 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. @@ -849,18 +849,27 @@ @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.hasCircuitPython(): - return self.__cpyDevice.connectWifi(ssid, password, hostname) + return self.__cpyDevice.connectWifi(ssid, password, hostname, country) + if not country: + country = Preferences.getMicroPython("WifiCountry").upper() command = """ -def connect_wifi(ssid, password, hostname): +def connect_wifi(ssid, password, hostname, country): import network import ujson from time import sleep + try: + network.country(country) + except AttributeError: + pass + if hostname: try: network.hostname(hostname) @@ -872,18 +881,19 @@ wifi.active(True) wifi.connect(ssid, password) max_wait = 140 - while max_wait and wifi.status() == network.STAT_CONNECTING: + while max_wait and wifi.status() != network.STAT_GOT_IP: max_wait -= 1 sleep(0.1) status = wifi.status() print(ujson.dumps({{'connected': wifi.isconnected(), 'status': status}})) -connect_wifi({0}, {1}, {2}) +connect_wifi({0}, {1}, {2}, {3}) del connect_wifi """.format( repr(ssid), repr(password if password else ""), repr(hostname), + repr(country if country else "XX"), ) with EricOverrideCursor():