811 if err: |
811 if err: |
812 return False, err |
812 return False, err |
813 else: |
813 else: |
814 return out.decode("utf-8").strip() == "True", "" |
814 return out.decode("utf-8").strip() == "True", "" |
815 |
815 |
816 def startAccessPoint(self, ssid, security=None, password=None): |
816 def startAccessPoint(self, ssid, security=None, password=None, ifconfig=None): |
817 """ |
817 """ |
818 Public method to start the access point interface. |
818 Public method to start the access point interface. |
819 |
819 |
820 @param ssid SSID of the access point |
820 @param ssid SSID of the access point |
821 @type str |
821 @type str |
822 @param security security method (defaults to None) |
822 @param security security method (defaults to None) |
823 @type int (optional) |
823 @type int (optional) |
824 @param password password (defaults to None) |
824 @param password password (defaults to None) |
825 @type str (optional) |
825 @type str (optional) |
|
826 @param ifconfig IPv4 configuration for the access point if not default |
|
827 (IPv4 address, netmask, gateway address, DNS server address) |
|
828 @type tuple of (str, str, str, str) |
826 @return tuple containing a flag indicating success and an error message |
829 @return tuple containing a flag indicating success and an error message |
827 @rtype tuple of (bool, str) |
830 @rtype tuple of (bool, str) |
828 """ |
831 """ |
829 if security is None or password is None: |
832 if security is None or password is None: |
830 security = 0 |
833 security = 0 |
833 if self._deviceData["wifi_type"] == "picow": |
836 if self._deviceData["wifi_type"] == "picow": |
834 country = Preferences.getMicroPython("WifiCountry").upper() |
837 country = Preferences.getMicroPython("WifiCountry").upper() |
835 if security: |
838 if security: |
836 security = 4 # Pico W supports just WPA/WPA2 |
839 security = 4 # Pico W supports just WPA/WPA2 |
837 command = """ |
840 command = """ |
838 def start_ap(): |
841 def start_ap(ssid, security, password, ifconfig, country): |
839 import network |
842 import network |
840 import rp2 |
843 import rp2 |
841 from time import sleep |
844 from time import sleep |
842 |
845 |
843 rp2.country({3}) |
846 rp2.country(country) |
844 |
847 |
845 ap = network.WLAN(network.AP_IF) |
848 ap = network.WLAN(network.AP_IF) |
846 ap.config(ssid={0}, security={1}, password={2}) |
|
847 ap.active(True) |
849 ap.active(True) |
|
850 if ifconfig: |
|
851 ap.ifconfig(ifconfig) |
|
852 ap.config(ssid=ssid, security=security, password=password) |
848 sleep(0.1) |
853 sleep(0.1) |
849 print(ap.isconnected()) |
854 print(ap.isconnected()) |
850 |
855 |
851 start_ap() |
856 start_ap({0}, {1}, {2}, {3}, {4}) |
852 del start_ap |
857 del start_ap |
853 """.format( |
858 """.format( |
854 repr(ssid), security, repr(password), repr(country if country else "XX") |
859 repr(ssid), |
|
860 security, |
|
861 repr(password), |
|
862 ifconfig, |
|
863 repr(country if country else "XX"), |
855 ) |
864 ) |
856 elif self._deviceData["wifi_type"] == "pimoroni": |
865 elif self._deviceData["wifi_type"] == "pimoroni": |
857 # TODO: not yet implemented |
866 # TODO: not yet implemented |
858 pass |
867 pass |
859 else: |
868 else: |