@@ -33,17 +33,39 @@ def __init__(self):
33
33
self .FUNCTION_SUFFIX = "endfunction"
34
34
self .display_arrows = False
35
35
36
- def start_network (self , robot_id :int ):
36
+ def start_network (self , ssid : str = None , robot_id :int = None , password : str = None ):
37
37
"""
38
- Open an access point from the XRP board to be used as a captive host. The network password is "remote.xrp"
38
+ Open an access point from the XRP board to be used as a captive host. The default network information can be set in secrets.json
39
+
40
+ :param ssid: The ssid of the access point, defaults to value from secrets.json
41
+ :type ssid: str, optional
42
+ :param robot_id: Replaces "{robot_id}" in ssid, defaults to value from secrets.json
43
+ :type robot_id: int, optional
44
+ :param password: The password of the access point, defaults to value from secrets.json
45
+ :type password: str, optional
39
46
"""
40
- self .access_point = access_point (f"XRP_{ robot_id } " , "remote.xrp" )
47
+ if ssid is None :
48
+ with open ("../secrets.json" ) as secrets_file :
49
+ secrets = json .load (secrets_file )
50
+ ssid = secrets ["ap_ssid" ]
51
+ password = secrets ["ap_password" ]
52
+ if robot_id is None :
53
+ robot_id = secrets ["robot_id" ]
54
+ ssid .replace ("{robot_id}" , robot_id )
55
+ self .access_point = access_point (ssid , password )
41
56
self .ip = network .WLAN (network .AP_IF ).ifconfig ()[0 ]
42
57
43
58
def connect_to_network (self , ssid :str = None , password :str = None , timeout = 10 ):
44
59
"""
45
60
Connect to a wifi network with the given ssid and password.
46
61
If the connection fails, the board will disconnect from the network and return.
62
+
63
+ :param ssid: The ssid of the network, defaults to value from secrets.json
64
+ :type ssid: str, optional
65
+ :param password: The password of the network, defaults to value from secrets.json
66
+ :type password: str, optional
67
+ :param timeout: The amount of time to wait for the connection to succeed, defaults to 10
68
+ :type timeout: int, optional
47
69
"""
48
70
self .wlan = network .WLAN (network .STA_IF )
49
71
self .wlan .active (True ) # configure board to connect to wifi
0 commit comments