Skip to content

Commit bdd8547

Browse files
committed
secrets.json for hiding wifi credentials
1 parent 593f75c commit bdd8547

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

XRPLib/webserver.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import gc
55
import network
66
import time
7+
import json
78

89
logging.log_file = "webserverLog.txt"
910

@@ -39,13 +40,18 @@ def start_network(self, robot_id:int):
3940
self.access_point = access_point(f"XRP_{robot_id}", "remote.xrp")
4041
self.ip = network.WLAN(network.AP_IF).ifconfig()[0]
4142

42-
def connect_to_network(self, ssid:str, password:str, timeout = 10):
43+
def connect_to_network(self, ssid:str=None, password:str=None, timeout = 10):
4344
"""
4445
Connect to a wifi network with the given ssid and password.
4546
If the connection fails, the board will disconnect from the network and return.
4647
"""
4748
self.wlan = network.WLAN(network.STA_IF)
4849
self.wlan.active(True) # configure board to connect to wifi
50+
if ssid is None:
51+
with open("../secrets.json") as secrets_file:
52+
secrets = json.load(secrets_file)
53+
ssid = secrets["wifi_ssid"]
54+
password = secrets["wifi_password"]
4955
self.wlan.connect(ssid,password)
5056
start_time = time.time()
5157
while not self.wlan.isconnected():

secrets.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"wifi_ssid": "YOUR_WIFI_SSID",
3+
"wifi_password": "YOUR_WIFI_PASSWORD"
4+
}

0 commit comments

Comments
 (0)