426 """ |
426 """ |
427 menu.addSeparator() |
427 menu.addSeparator() |
428 menu.addAction(self.tr("Set Country"), self.__setCountry).setEnabled( |
428 menu.addAction(self.tr("Set Country"), self.__setCountry).setEnabled( |
429 self._deviceData["wifi_type"] == "picow" |
429 self._deviceData["wifi_type"] == "picow" |
430 ) |
430 ) |
|
431 menu.addAction(self.tr("Reset Country"), self.__resetCountry).setEnabled( |
|
432 self._deviceData["wifi_type"] == "picow" |
|
433 ) |
431 |
434 |
432 def hasWifi(self): |
435 def hasWifi(self): |
433 """ |
436 """ |
434 Public method to check the availability of WiFi. |
437 Public method to check the availability of WiFi. |
435 |
438 |
471 else: |
474 else: |
472 # pimoroni firmware loaded but no pico wireless present |
475 # pimoroni firmware loaded but no pico wireless present |
473 return False, "" |
476 return False, "" |
474 return ast.literal_eval(out.decode("utf-8")) |
477 return ast.literal_eval(out.decode("utf-8")) |
475 |
478 |
|
479 def hasWifiCountry(self): |
|
480 """ |
|
481 Public method to check, if the device has support to set the WiFi country. |
|
482 |
|
483 @return flag indicating the support of WiFi country |
|
484 @rtype bool |
|
485 """ |
|
486 return self._deviceData["wifi_type"] == "picow" |
|
487 |
476 def getWifiData(self): |
488 def getWifiData(self): |
477 """ |
489 """ |
478 Public method to get data related to the current WiFi status. |
490 Public method to get data related to the current WiFi status. |
479 |
491 |
480 @return tuple of three dictionaries containing the WiFi status data |
492 @return tuple of three dictionaries containing the WiFi status data |
497 'status': wifi.status(), |
509 'status': wifi.status(), |
498 'ifconfig': wifi.ifconfig(), |
510 'ifconfig': wifi.ifconfig(), |
499 'mac': ubinascii.hexlify(wifi.config('mac'), ':').decode(), |
511 'mac': ubinascii.hexlify(wifi.config('mac'), ':').decode(), |
500 'channel': wifi.config('channel'), |
512 'channel': wifi.config('channel'), |
501 'txpower': wifi.config('txpower'), |
513 'txpower': wifi.config('txpower'), |
502 'country': rp2.country(), |
|
503 } |
514 } |
504 print(ujson.dumps(station)) |
515 print(ujson.dumps(station)) |
505 |
516 |
506 wifi = network.WLAN(network.AP_IF) |
517 wifi = network.WLAN(network.AP_IF) |
507 ap = { |
518 ap = { |
511 'ifconfig': wifi.ifconfig(), |
522 'ifconfig': wifi.ifconfig(), |
512 'mac': ubinascii.hexlify(wifi.config('mac'), ':').decode(), |
523 'mac': ubinascii.hexlify(wifi.config('mac'), ':').decode(), |
513 'channel': wifi.config('channel'), |
524 'channel': wifi.config('channel'), |
514 'txpower': wifi.config('txpower'), |
525 'txpower': wifi.config('txpower'), |
515 'essid': wifi.config('essid'), |
526 'essid': wifi.config('essid'), |
516 'country': rp2.country(), |
|
517 } |
527 } |
518 print(ujson.dumps(ap)) |
528 print(ujson.dumps(ap)) |
519 |
529 |
520 overall = { |
530 overall = { |
521 'active': station['active'] or ap['active'] |
531 'active': station['active'] or ap['active'] |
522 } |
532 } |
|
533 try: |
|
534 overall['country'] = network.country() |
|
535 except AttributeError: |
|
536 overall['country'] = rp2.country() |
|
537 try: |
|
538 overall['hostname'] = network.hostname() |
|
539 except AttributeError: |
|
540 pass |
523 print(ujson.dumps(overall)) |
541 print(ujson.dumps(overall)) |
524 |
542 |
525 wifi_status() |
543 wifi_status() |
526 del wifi_status |
544 del wifi_status |
527 """ |
545 """ |
617 station["ap_security"] = self.tr("unknown ({0})").format( |
635 station["ap_security"] = self.tr("unknown ({0})").format( |
618 station["ap_security"] |
636 station["ap_security"] |
619 ) |
637 ) |
620 return station, ap, overall |
638 return station, ap, overall |
621 |
639 |
622 def connectWifi(self, ssid, password): |
640 def connectWifi(self, ssid, password, hostname): |
623 """ |
641 """ |
624 Public method to connect a device to a WiFi network. |
642 Public method to connect a device to a WiFi network. |
625 |
643 |
626 @param ssid name (SSID) of the WiFi network |
644 @param ssid name (SSID) of the WiFi network |
627 @type str |
645 @type str |
628 @param password password needed to connect |
646 @param password password needed to connect |
629 @type str |
647 @type str |
|
648 @param hostname host name of the device |
|
649 @type str |
630 @return tuple containing the connection status and an error string |
650 @return tuple containing the connection status and an error string |
631 @rtype tuple of (bool, str) |
651 @rtype tuple of (bool, str) |
632 """ |
652 """ |
633 if self._deviceData["wifi_type"] == "picow": |
653 if self._deviceData["wifi_type"] == "picow": |
634 country = Preferences.getMicroPython("WifiCountry").upper() |
654 country = Preferences.getMicroPython("WifiCountry").upper() |
635 command = """ |
655 command = """ |
636 def connect_wifi(ssid, password, country): |
656 def connect_wifi(ssid, password, hostname, country): |
637 import network |
657 import network |
638 import rp2 |
658 import rp2 |
639 import ujson |
659 import ujson |
640 from time import sleep |
660 from time import sleep |
641 |
661 |
642 rp2.country(country) |
662 rp2.country(country) |
|
663 |
|
664 if hostname: |
|
665 try: |
|
666 network.hostname(hostname) |
|
667 except AttributeError: |
|
668 pass |
643 |
669 |
644 wifi = network.WLAN(network.STA_IF) |
670 wifi = network.WLAN(network.STA_IF) |
645 wifi.active(False) |
671 wifi.active(False) |
646 wifi.active(True) |
672 wifi.active(True) |
647 wifi.connect(ssid, password) |
673 wifi.connect(ssid, password) |
652 max_wait -= 1 |
678 max_wait -= 1 |
653 sleep(0.1) |
679 sleep(0.1) |
654 status = wifi.status() |
680 status = wifi.status() |
655 print(ujson.dumps({{'connected': wifi.isconnected(), 'status': status}})) |
681 print(ujson.dumps({{'connected': wifi.isconnected(), 'status': status}})) |
656 |
682 |
657 connect_wifi({0}, {1}, {2}) |
683 connect_wifi({0}, {1}, {2}, {3}) |
658 del connect_wifi |
684 del connect_wifi |
659 """.format( |
685 """.format( |
660 repr(ssid), |
686 repr(ssid), |
661 repr(password if password else ""), |
687 repr(password if password else ""), |
|
688 repr(hostname), |
662 repr(country if country else "XX"), |
689 repr(country if country else "XX"), |
663 ) |
690 ) |
664 elif self._deviceData["wifi_type"] == "picowireless": |
691 elif self._deviceData["wifi_type"] == "picowireless": |
665 command = """ |
692 command = """ |
666 def connect_wifi(ssid, password): |
693 def connect_wifi(ssid, password): |
692 """.format( |
719 """.format( |
693 repr(ssid), |
720 repr(ssid), |
694 repr(password if password else ""), |
721 repr(password if password else ""), |
695 ) |
722 ) |
696 else: |
723 else: |
697 return super().connectWifi(ssid, password) |
724 return super().connectWifi(ssid, password, hostname) |
698 |
725 |
699 with EricOverrideCursor(): |
726 with EricOverrideCursor(): |
700 out, err = self.executeCommands( |
727 out, err = self.executeCommands( |
701 command, mode=self._submitMode, timeout=15000 |
728 command, mode=self._submitMode, timeout=15000 |
702 ) |
729 ) |
833 if err: |
860 if err: |
834 return False |
861 return False |
835 |
862 |
836 return out.strip() == b"True" |
863 return out.strip() == b"True" |
837 |
864 |
838 def writeCredentials(self, ssid, password): |
865 def writeCredentials(self, ssid, password, hostname, country): |
839 """ |
866 """ |
840 Public method to write the given credentials to the connected device and modify |
867 Public method to write the given credentials to the connected device and modify |
841 the start script to connect automatically. |
868 the start script to connect automatically. |
842 |
869 |
843 @param ssid SSID of the network to connect to |
870 @param ssid SSID of the network to connect to |
844 @type str |
871 @type str |
845 @param password password needed to authenticate |
872 @param password password needed to authenticate |
|
873 @type str |
|
874 @param hostname host name of the device |
|
875 @type str |
|
876 @param country WiFi country code |
846 @type str |
877 @type str |
847 @return tuple containing a flag indicating success and an error message |
878 @return tuple containing a flag indicating success and an error message |
848 @rtype tuple of (bool, str) |
879 @rtype tuple of (bool, str) |
849 """ |
880 """ |
850 command = """ |
881 command = """ |
866 modify_boot() |
897 modify_boot() |
867 del modify_boot |
898 del modify_boot |
868 """ |
899 """ |
869 |
900 |
870 if self._deviceData["wifi_type"] == "picow": |
901 if self._deviceData["wifi_type"] == "picow": |
871 country = Preferences.getMicroPython("WifiCountry").upper() |
902 secrets = ( |
872 secrets = "WIFI_SSID = {0}\nWIFI_KEY = {1}\nWIFI_COUNTRY={2}".format( |
903 "WIFI_SSID = {0}\nWIFI_KEY = {1}\nWIFI_COUNTRY={2}\n" |
|
904 "WIFI_HOSTNAME = {3}\n" |
|
905 ).format( |
873 repr(ssid), |
906 repr(ssid), |
874 repr(password) if password else '""', |
907 repr(password) if password else '""', |
875 repr(country) if country else '""', |
908 repr(country.upper()) if country else '""', |
|
909 repr(hostname) if hostname else '""', |
876 ) |
910 ) |
877 wifiConnectFile = "picowWiFiConnect.py" |
911 wifiConnectFile = "picowWiFiConnect.py" |
878 else: |
912 else: |
879 secrets = "WIFI_SSID = {0}\nWIFI_KEY = {1}\n".format( |
913 secrets = "WIFI_SSID = {0}\nWIFI_KEY = {1}\n".format( |
880 repr(ssid), |
914 repr(ssid), |
881 repr(password) if password else '""', |
915 repr(password) if password else '""', |
882 ) |
916 ) |
883 if self._deviceData["wifi_type"] == "picowireless": |
917 if self._deviceData["wifi_type"] == "picowireless": |
884 wifiConnectFile = "pimoroniWiFiConnect.py" |
918 wifiConnectFile = "pimoroniWiFiConnect.py" |
885 else: |
919 else: |
|
920 secrets += "WIFI_HOSTNAME = {0}\n".format( |
|
921 repr(hostname if hostname else '""') |
|
922 ) |
886 wifiConnectFile = "mpyWiFiConnect.py" |
923 wifiConnectFile = "mpyWiFiConnect.py" |
887 try: |
924 try: |
888 # write secrets file |
925 # write secrets file |
889 self.putData("/secrets.py", secrets.encode("utf-8")) |
926 self.putData("/secrets.py", secrets.encode("utf-8")) |
890 # copy auto-connect file |
927 # copy auto-connect file |
1104 if err: |
1141 if err: |
1105 return False, err |
1142 return False, err |
1106 else: |
1143 else: |
1107 return out.decode("utf-8").strip() == "True", "" |
1144 return out.decode("utf-8").strip() == "True", "" |
1108 |
1145 |
1109 def startAccessPoint(self, ssid, security=None, password=None, ifconfig=None): |
1146 def startAccessPoint( |
|
1147 self, |
|
1148 ssid, |
|
1149 security=None, |
|
1150 password=None, |
|
1151 hostname=None, |
|
1152 ifconfig=None, |
|
1153 ): |
1110 """ |
1154 """ |
1111 Public method to start the access point interface. |
1155 Public method to start the access point interface. |
1112 |
1156 |
1113 @param ssid SSID of the access point |
1157 @param ssid SSID of the access point |
1114 @type str |
1158 @type str |
1115 @param security security method (defaults to None) |
1159 @param security security method (defaults to None) |
1116 @type int (optional) |
1160 @type int (optional) |
1117 @param password password (defaults to None) |
1161 @param password password (defaults to None) |
1118 @type str (optional) |
1162 @type str (optional) |
|
1163 @param hostname host name of the device (defaults to None) |
|
1164 @type str (optional) |
1119 @param ifconfig IPv4 configuration for the access point if not default |
1165 @param ifconfig IPv4 configuration for the access point if not default |
1120 (IPv4 address, netmask, gateway address, DNS server address) |
1166 (IPv4 address, netmask, gateway address, DNS server address) |
1121 @type tuple of (str, str, str, str) |
1167 @type tuple of (str, str, str, str) |
1122 @return tuple containing a flag indicating success and an error message |
1168 @return tuple containing a flag indicating success and an error message |
1123 @rtype tuple of (bool, str) |
1169 @rtype tuple of (bool, str) |
1129 if self._deviceData["wifi_type"] == "picow": |
1175 if self._deviceData["wifi_type"] == "picow": |
1130 country = Preferences.getMicroPython("WifiCountry").upper() |
1176 country = Preferences.getMicroPython("WifiCountry").upper() |
1131 if security: |
1177 if security: |
1132 security = 4 # Pico W supports just WPA/WPA2 |
1178 security = 4 # Pico W supports just WPA/WPA2 |
1133 command = """ |
1179 command = """ |
1134 def start_ap(ssid, security, password, ifconfig, country): |
1180 def start_ap(ssid, security, password, hostname, ifconfig, country): |
1135 import network |
1181 import network |
1136 import rp2 |
1182 import rp2 |
1137 from time import sleep |
1183 from time import sleep |
1138 |
1184 |
1139 rp2.country(country) |
1185 rp2.country(country) |
|
1186 |
|
1187 if hostname: |
|
1188 try: |
|
1189 network.hostname(hostname) |
|
1190 except AttributeError: |
|
1191 pass |
1140 |
1192 |
1141 ap = network.WLAN(network.AP_IF) |
1193 ap = network.WLAN(network.AP_IF) |
1142 ap.active(True) |
1194 ap.active(True) |
1143 if ifconfig: |
1195 if ifconfig: |
1144 ap.ifconfig(ifconfig) |
1196 ap.ifconfig(ifconfig) |
1145 ap.config(ssid=ssid, security=security, password=password) |
1197 ap.config(ssid=ssid, security=security, password=password) |
1146 sleep(0.1) |
1198 sleep(0.1) |
1147 print(ap.isconnected()) |
1199 print(ap.isconnected()) |
1148 |
1200 |
1149 start_ap({0}, {1}, {2}, {3}, {4}) |
1201 start_ap({0}, {1}, {2}, {3}, {4}, {5}) |
1150 del start_ap |
1202 del start_ap |
1151 """.format( |
1203 """.format( |
1152 repr(ssid), |
1204 repr(ssid), |
1153 security, |
1205 security, |
1154 repr(password), |
1206 repr(password), |
|
1207 repr(hostname), |
1155 ifconfig, |
1208 ifconfig, |
1156 repr(country if country else "XX"), |
1209 repr(country if country else "XX"), |
1157 ) |
1210 ) |
1158 elif self._deviceData["wifi_type"] == "picowireless": |
1211 elif self._deviceData["wifi_type"] == "picowireless": |
1159 if ifconfig: |
1212 if ifconfig: |
1187 """.format( |
1240 """.format( |
1188 repr(ssid), |
1241 repr(ssid), |
1189 repr(password if password else ""), |
1242 repr(password if password else ""), |
1190 ) |
1243 ) |
1191 else: |
1244 else: |
1192 return super().startAccessPoint(ssid, security=security, password=password) |
1245 return super().startAccessPoint( |
|
1246 ssid, |
|
1247 security=security, |
|
1248 password=password, |
|
1249 hostname=hostname, |
|
1250 ifconfig=ifconfig, |
|
1251 ) |
1193 |
1252 |
1194 out, err = self.executeCommands(command, mode=self._submitMode, timeout=15000) |
1253 out, err = self.executeCommands(command, mode=self._submitMode, timeout=15000) |
1195 if err: |
1254 if err: |
1196 return False, err |
1255 return False, err |
1197 else: |
1256 else: |
1336 out, err = self.executeCommands(command, mode=self._submitMode) |
1395 out, err = self.executeCommands(command, mode=self._submitMode) |
1337 if err: |
1396 if err: |
1338 return False, err |
1397 return False, err |
1339 |
1398 |
1340 return out.decode("utf-8").strip() == "True", "" |
1399 return out.decode("utf-8").strip() == "True", "" |
|
1400 |
|
1401 @pyqtSlot() |
|
1402 def __setCountry(self): |
|
1403 """ |
|
1404 Private slot to configure the country of the connected RP2040 device. |
|
1405 |
|
1406 The country is the two-letter ISO 3166-1 Alpha-2 country code. |
|
1407 """ |
|
1408 from ..WifiDialogs.WifiCountryDialog import WifiCountryDialog |
|
1409 |
|
1410 dlg = WifiCountryDialog() |
|
1411 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
1412 country, remember = dlg.getCountry() |
|
1413 if remember: |
|
1414 Preferences.setMicroPython("WifiCountry", country) |
|
1415 |
|
1416 command = """ |
|
1417 try: |
|
1418 import network |
|
1419 network.country({0}) |
|
1420 except AttributeError: |
|
1421 import rp2 |
|
1422 rp2.country({0}) |
|
1423 """.format( |
|
1424 repr(country) |
|
1425 ) |
|
1426 |
|
1427 out, err = self.executeCommands(command, mode=self._submitMode) |
|
1428 if err: |
|
1429 self.microPython.showError("country()", err) |
|
1430 |
|
1431 @pyqtSlot() |
|
1432 def __resetCountry(self): |
|
1433 """ |
|
1434 Private slot to reset the country of the connected ESP32 device. |
|
1435 |
|
1436 The country is the two-letter ISO 3166-1 Alpha-2 country code. This method |
|
1437 resets it to the default code 'XX' representing the "worldwide" region. |
|
1438 """ |
|
1439 command = """ |
|
1440 try: |
|
1441 import network |
|
1442 network.country('XX') |
|
1443 except AttributeError: |
|
1444 pass |
|
1445 """ |
|
1446 |
|
1447 out, err = self.executeCommands(command, mode=self._submitMode) |
|
1448 if err: |
|
1449 self.microPython.showError("country()", err) |
1341 |
1450 |
1342 ################################################################## |
1451 ################################################################## |
1343 ## Methods below implement Bluetooth related methods |
1452 ## Methods below implement Bluetooth related methods |
1344 ################################################################## |
1453 ################################################################## |
1345 |
1454 |
1608 'active': nic.active(), |
1717 'active': nic.active(), |
1609 'connected': nic.isconnected(), |
1718 'connected': nic.isconnected(), |
1610 'status': nic.status(), |
1719 'status': nic.status(), |
1611 'ifconfig': nic.ifconfig(), |
1720 'ifconfig': nic.ifconfig(), |
1612 'mac': ubinascii.hexlify(nic.config('mac'), ':').decode(), |
1721 'mac': ubinascii.hexlify(nic.config('mac'), ':').decode(), |
1613 'hostname': network.hostname(), |
|
1614 }} |
1722 }} |
|
1723 try: |
|
1724 res['hostname'] = network.hostname() |
|
1725 except AttributeError: |
|
1726 res['hostname'] = '' |
1615 print(ujson.dumps(res)) |
1727 print(ujson.dumps(res)) |
1616 |
1728 |
1617 ethernet_status() |
1729 ethernet_status() |
1618 del ethernet_status, w5x00_init |
1730 del ethernet_status, w5x00_init |
1619 """.format( |
1731 """.format( |
1632 ( |
1744 ( |
1633 self.tr("Status"), |
1745 self.tr("Status"), |
1634 self.__statusTranslations["picowiz"][ethStatus["status"]], |
1746 self.__statusTranslations["picowiz"][ethStatus["status"]], |
1635 ) |
1747 ) |
1636 ) |
1748 ) |
1637 status.append((self.tr("Hostname"), ethStatus["hostname"])) |
1749 status.append( |
|
1750 ( |
|
1751 self.tr("Hostname"), |
|
1752 ethStatus["hostname"] if ethStatus["hostname"] else self.tr("unknown"), |
|
1753 ) |
|
1754 ) |
1638 status.append((self.tr("IPv4 Address"), ethStatus["ifconfig"][0])) |
1755 status.append((self.tr("IPv4 Address"), ethStatus["ifconfig"][0])) |
1639 status.append((self.tr("Netmask"), ethStatus["ifconfig"][1])) |
1756 status.append((self.tr("Netmask"), ethStatus["ifconfig"][1])) |
1640 status.append((self.tr("Gateway"), ethStatus["ifconfig"][2])) |
1757 status.append((self.tr("Gateway"), ethStatus["ifconfig"][2])) |
1641 status.append((self.tr("DNS"), ethStatus["ifconfig"][3])) |
1758 status.append((self.tr("DNS"), ethStatus["ifconfig"][3])) |
1642 status.append((self.tr("MAC-Address"), ethStatus["mac"])) |
1759 status.append((self.tr("MAC-Address"), ethStatus["mac"])) |
1643 |
1760 |
1644 return status |
1761 return status |
1645 |
1762 |
1646 def connectToLan(self, config): |
1763 def connectToLan(self, config, hostname): |
1647 """ |
1764 """ |
1648 Public method to connect the connected device to the LAN. |
1765 Public method to connect the connected device to the LAN. |
1649 |
1766 |
1650 @param config configuration for the connection (either the string 'dhcp' |
1767 @param config configuration for the connection (either the string 'dhcp' |
1651 for a dynamic address or a tuple of four strings with the IPv4 parameters. |
1768 for a dynamic address or a tuple of four strings with the IPv4 parameters. |
1652 @type str or tuple of (str, str, str, str) |
1769 @type str or tuple of (str, str, str, str) |
|
1770 @param hostname host name of the device |
|
1771 @type str |
1653 @return tuple containing a flag indicating success and an error message |
1772 @return tuple containing a flag indicating success and an error message |
1654 @rtype tuple of (bool, str) |
1773 @rtype tuple of (bool, str) |
1655 """ |
1774 """ |
1656 command = """{0} |
1775 command = """{0} |
1657 def connect_lan(config): |
1776 def connect_lan(config, hostname): |
|
1777 import network |
1658 import time |
1778 import time |
|
1779 |
|
1780 if hostname: |
|
1781 try: |
|
1782 network.hostname(hostname) |
|
1783 except AttributeError: |
|
1784 pass |
1659 |
1785 |
1660 w5x00_init() |
1786 w5x00_init() |
1661 |
1787 |
1662 nic.active(False) |
1788 nic.active(False) |
1663 nic.active(True) |
1789 nic.active(True) |
1668 break |
1794 break |
1669 max_wait -= 1 |
1795 max_wait -= 1 |
1670 time.sleep(0.1) |
1796 time.sleep(0.1) |
1671 print(nic.isconnected()) |
1797 print(nic.isconnected()) |
1672 |
1798 |
1673 connect_lan({1}) |
1799 connect_lan({1}, {2}) |
1674 del connect_lan, w5x00_init |
1800 del connect_lan, w5x00_init |
1675 """.format( |
1801 """.format( |
1676 WiznetUtilities.mpyWiznetInit(), "'dhcp'" if config == "dhcp" else config |
1802 WiznetUtilities.mpyWiznetInit(), |
|
1803 "'dhcp'" if config == "dhcp" else config, |
|
1804 repr(hostname) if hostname else "''", |
1677 ) |
1805 ) |
1678 |
1806 |
1679 with EricOverrideCursor(): |
1807 with EricOverrideCursor(): |
1680 out, err = self.executeCommands( |
1808 out, err = self.executeCommands( |
1681 command, mode=self._submitMode, timeout=15000 |
1809 command, mode=self._submitMode, timeout=15000 |
1791 # The WIZnet 5x00 interface cannot be switched off explicitly. That means, |
1919 # The WIZnet 5x00 interface cannot be switched off explicitly. That means, |
1792 # disconnect from the LAN is all we can do. |
1920 # disconnect from the LAN is all we can do. |
1793 |
1921 |
1794 return self.disconnectFromLan() |
1922 return self.disconnectFromLan() |
1795 |
1923 |
1796 def writeLanAutoConnect(self, config): |
1924 def writeLanAutoConnect(self, config, hostname): |
1797 """ |
1925 """ |
1798 Public method to generate a script and associated configuration to connect the |
1926 Public method to generate a script and associated configuration to connect the |
1799 device to the LAN during boot time. |
1927 device to the LAN during boot time. |
1800 |
1928 |
1801 @param config configuration for the connection (either the string 'dhcp' |
1929 @param config configuration for the connection (either the string 'dhcp' |
1802 for a dynamic address or a tuple of four strings with the IPv4 parameters. |
1930 for a dynamic address or a tuple of four strings with the IPv4 parameters. |
1803 @type str or tuple of (str, str, str, str) |
1931 @type str or tuple of (str, str, str, str) |
|
1932 @param hostname host name of the device |
|
1933 @type str |
1804 @return tuple containing a flag indicating success and an error message |
1934 @return tuple containing a flag indicating success and an error message |
1805 @rtype tuple of (bool, str) |
1935 @rtype tuple of (bool, str) |
1806 """ |
1936 """ |
1807 command = """ |
1937 command = """ |
1808 def modify_boot(): |
1938 def modify_boot(): |
1823 print(True) |
1953 print(True) |
1824 |
1954 |
1825 modify_boot() |
1955 modify_boot() |
1826 del modify_boot |
1956 del modify_boot |
1827 """ |
1957 """ |
1828 ifconfig = "ifconfig = {0}\n".format("'dhcp'" if config == "dhcp" else config) |
1958 devconfig = "ifconfig = {0}\nhostname = {1}".format( |
|
1959 "'dhcp'" if config == "dhcp" else config, |
|
1960 repr(hostname) if hostname else "''", |
|
1961 ) |
1829 try: |
1962 try: |
1830 # write secrets file |
1963 # write secrets file |
1831 self.putData("/wiznet_config.py", ifconfig.encode("utf-8")) |
1964 self.putData("/wiznet_config.py", devconfig.encode("utf-8")) |
1832 # copy auto-connect file |
1965 # copy auto-connect file |
1833 self.put( |
1966 self.put( |
1834 os.path.join( |
1967 os.path.join( |
1835 os.path.dirname(__file__), "MCUScripts", "picoWiznetConnect.py" |
1968 os.path.dirname(__file__), "MCUScripts", "picoWiznetConnect.py" |
1836 ), |
1969 ), |
1952 if err: |
2085 if err: |
1953 return False, err |
2086 return False, err |
1954 else: |
2087 else: |
1955 res = ast.literal_eval(out.decode("utf-8")) |
2088 res = ast.literal_eval(out.decode("utf-8")) |
1956 return res["result"], res["error"] |
2089 return res["result"], res["error"] |
1957 |
|
1958 ############################################################################ |
|
1959 ## RP2 only methods below |
|
1960 ############################################################################ |
|
1961 |
|
1962 @pyqtSlot() |
|
1963 def __setCountry(self): |
|
1964 """ |
|
1965 Private slot to configure the country of the connected RP2040 device. |
|
1966 |
|
1967 The country is the two letter country code. |
|
1968 """ |
|
1969 from ..WifiDialogs.WifiCountryDialog import WifiCountryDialog |
|
1970 |
|
1971 dlg = WifiCountryDialog() |
|
1972 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
1973 country, remember = dlg.getCountry() |
|
1974 if remember: |
|
1975 Preferences.setMicroPython("WifiCountry", country) |
|
1976 |
|
1977 command = """ |
|
1978 import rp2 |
|
1979 rp2.country({0}) |
|
1980 """.format( |
|
1981 repr(country) |
|
1982 ) |
|
1983 |
|
1984 out, err = self.executeCommands(command, mode=self._submitMode) |
|
1985 if err: |
|
1986 self.microPython.showError("rp2.country()", err) |
|
1987 |
2090 |
1988 |
2091 |
1989 def createDevice( |
2092 def createDevice( |
1990 microPythonWidget, deviceType, vid, pid, boardName, serialNumber # noqa: U100 |
2093 microPythonWidget, deviceType, vid, pid, boardName, serialNumber # noqa: U100 |
1991 ): |
2094 ): |