src/eric7/MicroPython/Devices/RP2040Devices.py

branch
mpy_network
changeset 9838
d6b87ef03c13
parent 9836
902ec9a04ebe
child 9841
3c6118eee33e
equal deleted inserted replaced
9837:b1d925ecda15 9838:d6b87ef03c13
55 0: self.tr("idle"), 55 0: self.tr("idle"),
56 1: self.tr("connecting"), 56 1: self.tr("connecting"),
57 2: self.tr("connected, waiting for IP address"), 57 2: self.tr("connected, waiting for IP address"),
58 3: self.tr("connected"), 58 3: self.tr("connected"),
59 }, 59 },
60 "pimoroni": { 60 "picowireless": {
61 0: self.tr("idle"), 61 0: self.tr("idle"),
62 1: self.tr("no matching access point found"), 62 1: self.tr("no matching access point found"),
63 2: self.tr("network scan completed"), 63 2: self.tr("network scan completed"),
64 3: self.tr("connected"), 64 3: self.tr("connected"),
65 4: self.tr("connection failed"), 65 4: self.tr("connection failed"),
68 7: self.tr("AP listening"), 68 7: self.tr("AP listening"),
69 8: self.tr("AP connected"), 69 8: self.tr("AP connected"),
70 9: self.tr("AP failed"), 70 9: self.tr("AP failed"),
71 }, 71 },
72 } 72 }
73 # TODO: must be specific (picow, pimoroni) 73 # TODO: must be specific (picow, picowireless)
74 self.__securityTranslations = { 74 self.__securityTranslations = {
75 "picow": { 75 "picow": {
76 0: self.tr("open", "open WiFi network"), 76 0: self.tr("open", "open WiFi network"),
77 1: "WEP", 77 1: "WEP",
78 2: "WPA", 78 2: "WPA",
80 4: "WPA/WPA2", 80 4: "WPA/WPA2",
81 5: "WPA2 (CCMP)", 81 5: "WPA2 (CCMP)",
82 6: "WPA3", 82 6: "WPA3",
83 7: "WPA2/WPA3", 83 7: "WPA2/WPA3",
84 }, 84 },
85 "pimoroni": { 85 "picowireless": {
86 2: "WPA", 86 2: "WPA",
87 4: "WPA2 (CCMP)", 87 4: "WPA2 (CCMP)",
88 5: "WEP", 88 5: "WEP",
89 7: self.tr("open", "open WiFi network"), 89 7: self.tr("open", "open WiFi network"),
90 8: self.tr("automatic"), 90 8: self.tr("automatic"),
425 def hasWifi(self): 425 def hasWifi(self):
426 """ 426 """
427 Public method to check the availability of WiFi. 427 Public method to check the availability of WiFi.
428 428
429 @return tuple containing a flag indicating the availability of WiFi 429 @return tuple containing a flag indicating the availability of WiFi
430 and the WiFi type (picow or pimoroni) 430 and the WiFi type (picow or picowireless)
431 @rtype tuple of (bool, str) 431 @rtype tuple of (bool, str)
432 @exception OSError raised to indicate an issue with the device 432 @exception OSError raised to indicate an issue with the device
433 """ 433 """
434 # picowireless: 434 # picowireless:
435 # It seems to take up to 20 sec to detect, that no Pico Wireless Pack is 435 # It seems to take up to 20 sec to detect, that no Pico Wireless Pack is
443 except ImportError: 443 except ImportError:
444 try: 444 try:
445 import picowireless as pw 445 import picowireless as pw
446 try: 446 try:
447 if pw.get_fw_version() != '': 447 if pw.get_fw_version() != '':
448 return True, 'pimoroni' 448 return True, 'picowireless'
449 except RuntimeError: 449 except RuntimeError:
450 picowireless.init() 450 picowireless.init()
451 return True, 'pimoroni' 451 return True, 'picowireless'
452 except ImportError: 452 except ImportError:
453 pass 453 pass
454 454
455 return False, '' 455 return False, ''
456 456
517 print(ujson.dumps(overall)) 517 print(ujson.dumps(overall))
518 518
519 wifi_status() 519 wifi_status()
520 del wifi_status 520 del wifi_status
521 """ 521 """
522 elif self._deviceData["wifi_type"] == "pimoroni": 522 elif self._deviceData["wifi_type"] == "picowireless":
523 command = """ 523 command = """
524 def wifi_status(): 524 def wifi_status():
525 import picowireless as pw 525 import picowireless as pw
526 import ubinascii 526 import ubinascii
527 import ujson 527 import ujson
653 """.format( 653 """.format(
654 repr(ssid), 654 repr(ssid),
655 repr(password if password else ""), 655 repr(password if password else ""),
656 repr(country if country else "XX"), 656 repr(country if country else "XX"),
657 ) 657 )
658 elif self._deviceData["wifi_type"] == "pimoroni": 658 elif self._deviceData["wifi_type"] == "picowireless":
659 command = """ 659 command = """
660 def connect_wifi(ssid, password): 660 def connect_wifi(ssid, password):
661 import picowireless as pw 661 import picowireless as pw
662 import ujson 662 import ujson
663 from time import sleep 663 from time import sleep
730 print(not wifi.isconnected()) 730 print(not wifi.isconnected())
731 731
732 disconnect_wifi() 732 disconnect_wifi()
733 del disconnect_wifi 733 del disconnect_wifi
734 """ 734 """
735 elif self._deviceData["wifi_type"] == "pimoroni": 735 elif self._deviceData["wifi_type"] == "picowireless":
736 command = """ 736 command = """
737 def disconnect_wifi(): 737 def disconnect_wifi():
738 import picowireless as pw 738 import picowireless as pw
739 from time import sleep 739 from time import sleep
740 740
798 else: 798 else:
799 secrets = "WIFI_SSID = {0}\nWIFI_KEY = {1}\n".format( 799 secrets = "WIFI_SSID = {0}\nWIFI_KEY = {1}\n".format(
800 repr(ssid), 800 repr(ssid),
801 repr(password) if password else '""', 801 repr(password) if password else '""',
802 ) 802 )
803 if self._deviceData["wifi_type"] == "pimoroni": 803 if self._deviceData["wifi_type"] == "picowireless":
804 wifiConnectFile = "pimoroniWiFiConnect.py" 804 wifiConnectFile = "pimoroniWiFiConnect.py"
805 else: 805 else:
806 wifiConnectFile = "mpyWiFiConnect.py" 806 wifiConnectFile = "mpyWiFiConnect.py"
807 try: 807 try:
808 # write secrets file 808 # write secrets file
862 print(False) 862 print(False)
863 863
864 check_internet() 864 check_internet()
865 del check_internet 865 del check_internet
866 """ 866 """
867 elif self._deviceData["wifi_type"] == "pimoroni": 867 elif self._deviceData["wifi_type"] == "picowireless":
868 command = """ 868 command = """
869 def check_internet(): 869 def check_internet():
870 import picowireless as pw 870 import picowireless as pw
871 871
872 if pw.get_connection_status() == 3: 872 if pw.get_connection_status() == 3:
919 del scan_networks 919 del scan_networks
920 """.format( 920 """.format(
921 repr(country if country else "XX") 921 repr(country if country else "XX")
922 ) 922 )
923 923
924 elif self._deviceData["wifi_type"] == "pimoroni": 924 elif self._deviceData["wifi_type"] == "picowireless":
925 command = """ 925 command = """
926 def scan_networks(): 926 def scan_networks():
927 import picowireless as pw 927 import picowireless as pw
928 928
929 network_list = [] 929 network_list = []
1008 deactivate() 1008 deactivate()
1009 del deactivate 1009 del deactivate
1010 """.format( 1010 """.format(
1011 interface 1011 interface
1012 ) 1012 )
1013 elif self._deviceData["wifi_type"] == "pimoroni": 1013 elif self._deviceData["wifi_type"] == "picowireless":
1014 command = """ 1014 command = """
1015 def deactivate(): 1015 def deactivate():
1016 import picowireless as pw 1016 import picowireless as pw
1017 1017
1018 pw.init() 1018 pw.init()
1077 security, 1077 security,
1078 repr(password), 1078 repr(password),
1079 ifconfig, 1079 ifconfig,
1080 repr(country if country else "XX"), 1080 repr(country if country else "XX"),
1081 ) 1081 )
1082 elif self._deviceData["wifi_type"] == "pimoroni": 1082 elif self._deviceData["wifi_type"] == "picowireless":
1083 # AP is fixed at channel 6 1083 # AP is fixed at channel 6
1084 command = """ 1084 command = """
1085 def start_ap(ssid, password): 1085 def start_ap(ssid, password):
1086 import picowireless as pw 1086 import picowireless as pw
1087 1087
1119 Public method to stop the access point interface. 1119 Public method to stop the access point interface.
1120 1120
1121 @return tuple containg a flag indicating success and an error message 1121 @return tuple containg a flag indicating success and an error message
1122 @rtype tuple of (bool, str) 1122 @rtype tuple of (bool, str)
1123 """ 1123 """
1124 if self._deviceData["wifi_type"] in ("picow", "pimoroni"): 1124 if self._deviceData["wifi_type"] in ("picow", "picowireless"):
1125 return self.deactivateInterface("AP") 1125 return self.deactivateInterface("AP")
1126 else: 1126 else:
1127 return super().stopAccessPoint() 1127 return super().stopAccessPoint()
1128 1128
1129 def getConnectedClients(self): 1129 def getConnectedClients(self):
1144 print(stations) 1144 print(stations)
1145 1145
1146 get_stations() 1146 get_stations()
1147 del get_stations 1147 del get_stations
1148 """ 1148 """
1149 elif self._deviceData["wifi_type"] == "pimoroni": 1149 elif self._deviceData["wifi_type"] == "picowireless":
1150 return ( 1150 return (
1151 [], 1151 [],
1152 self.tr( 1152 self.tr(
1153 "Showing connected clients is not supported for 'pico wireless'." 1153 "Showing connected clients is not supported for 'pico wireless'."
1154 ), 1154 ),

eric ide

mercurial