@@ -31,15 +31,35 @@ def __init__(self):
3131 self .FUNCTION_SUFFIX = "endfunction"
3232 self .display_arrows = False
3333
34- def start_server (self , robot_number :int ):
34+ def start_network (self , robot_number :int ):
3535 """
36- Start the webserver. The network password is "remote.xrp"
37-
38- :param robot_number: The number of the robot, used to generate the access point name
39- :type robot_number: int
36+ Open an access point from the XRP board to be used as a captive host. The network password is "remote.xrp"
4037 """
4138 self .access_point = access_point (f"XRP_{ robot_number } " , "remote.xrp" )
4239 self .ip = network .WLAN (network .AP_IF ).ifconfig ()[0 ]
40+
41+ def connect_to_network (self , ssid :str , password :str , timeout = 10 ):
42+ """
43+ Connect to a wifi network with the given ssid and password.
44+ If the connection fails, the board will disconnect from the network and return.
45+ """
46+ self .wlan = network .WLAN (network .STA_IF )
47+ self .wlan .active (True ) # configure board to connect to wifi
48+ self .wlan .connect (ssid ,password )
49+ start_time = time .time ()
50+ while not self .wlan .isconnected ():
51+ print ("Connecting to network, may take a second" )
52+ if time .time () > start_time + timeout :
53+ print ("Failed to connect to network, please try again" )
54+ self .wlan .disconnect ()
55+ return False
56+ time .sleep (0.25 )
57+ self .ip = self .wlan .ifconfig ()[0 ]
58+
59+ def start_server (self ):
60+ """
61+ Begin the webserver on whatever network is configured, at the ip 'remote.xrp'
62+ """
4363 logging .info (f"Starting DNS Server at { self .ip } " )
4464 dns .run_catchall (self .ip )
4565 server .run ()
0 commit comments