diff -r 210bf87ae5c7 -r 8d3c7c991085 src/eric7/MicroPython/Devices/RP2040Devices.py --- a/src/eric7/MicroPython/Devices/RP2040Devices.py Sat Feb 18 18:12:32 2023 +0100 +++ b/src/eric7/MicroPython/Devices/RP2040Devices.py Sun Feb 19 14:45:16 2023 +0100 @@ -13,7 +13,7 @@ from PyQt6.QtCore import QUrl, pyqtSlot from PyQt6.QtNetwork import QNetworkRequest -from PyQt6.QtWidgets import QMenu +from PyQt6.QtWidgets import QDialog, QMenu from eric7 import Globals, Preferences from eric7.EricGui.EricOverrideCursor import EricOverrideCursor @@ -360,9 +360,21 @@ """ ################################################################## - ## Methods below implement network related methods + ## Methods below implement WiFi related methods ################################################################## + def addDeviceWifiEntries(self, menu): + """ + Public method to add device specific entries to the given menu. + + @param menu reference to the context menu + @type QMenu + """ + menu.addSeparator() + menu.addAction(self.tr("Set Country"), self.__setCountry).setEnabled( + self._deviceData["wifi_type"] == "picow" + ) + def hasWifi(self): """ Public method to check the availability of WiFi. @@ -410,6 +422,7 @@ import ubinascii import ujson import network + import rp2 wifi = network.WLAN(network.STA_IF) station = { @@ -420,6 +433,7 @@ 'mac': ubinascii.hexlify(wifi.config('mac'), ':').decode(), 'channel': wifi.config('channel'), 'txpower': wifi.config('txpower'), + 'country': rp2.country(), } print(ujson.dumps(station)) @@ -433,6 +447,7 @@ 'channel': wifi.config('channel'), 'txpower': wifi.config('txpower'), 'essid': wifi.config('essid'), + 'country': rp2.country(), } print(ujson.dumps(ap)) @@ -478,17 +493,21 @@ @rtype tuple of (bool, str) """ if self._deviceData["wifi_type"] == "picow": + country = Preferences.getMicroPython("WifiCountry").upper() command = """ def connect_wifi(ssid, password): import network + import rp2 + import ujson from time import sleep - import ujson + + rp2.country({2}) wifi = network.WLAN(network.STA_IF) wifi.active(False) wifi.active(True) wifi.connect(ssid, password) - max_wait = 100 + max_wait = 140 while max_wait: if wifi.status() < 0 or wifi.status() >= 3: break @@ -499,7 +518,11 @@ connect_wifi({0}, {1}) del connect_wifi -""".format(repr(ssid), repr(password if password else "")) +""".format( + repr(ssid), + repr(password if password else ""), + repr(country if country else "XX"), + ) elif self._deviceData["wifi_type"] == "pimoroni": # TODO: not yet implemented pass @@ -558,6 +581,30 @@ return out.decode("utf-8").strip() == "True", "" + @pyqtSlot() + def __setCountry(self): + """ + Private slot to configure the country of the connected RP2040 device. + + The country is the two letter country code. + """ + from ..WifiDialogs.WifiCountryDialog import WifiCountryDialog + + dlg = WifiCountryDialog() + if dlg.exec() == QDialog.DialogCode.Accepted: + country, remember = dlg.getCountry() + if remember: + Preferences.setMicroPython("WifiCountry", country) + + command = """ +import rp2 +rp2.country({0}) +""".format(repr(country)) + + out, err = self._interface.execute(command) + if err: + self._showError("rp2.country()", err) + def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber): """