Skip to content

Commit 504d97f

Browse files
committed
Restart running hotspot on SSID or Password change
1 parent 3020130 commit 504d97f

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/common/wifi.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def auto_connect(ssid=None, username=None, password=None):
7171

7272
# Returns True when a connection to a router is made, or the Hotspot is live
7373
def check_device_state():
74-
# Save the wi-fi device object to a variable
7574
if get_device().State == Pnm.NM_DEVICE_STATE_ACTIVATED:
7675
return True
7776
else:

src/resources/wifi_routes.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from common.wifi import check_wifi_status
77
from common.wifi import connect
88
from common.wifi import forget
9+
from common.wifi import get_connection_id
910
from common.wifi import list_access_points
1011
from dotenv import dotenv_values
1112
from flask import request
@@ -50,12 +51,12 @@ def get(self):
5051

5152
class wifi_forget(Resource):
5253
def post(self):
53-
# If the device is not connected to a wifi network
54-
if not check_wifi_status():
55-
return {"message": "Device is already disconnected."}, 409
56-
5754
# Check the all_networks boolean
5855
if not request.get_json() or "all_networks" not in request.get_json():
56+
# If the device is not connected to a wifi network
57+
if not check_wifi_status():
58+
return {"message": "Device is already disconnected."}, 409
59+
5960
forget_mode = False
6061
else:
6162
forget_mode = request.get_json()["all_networks"]
@@ -97,6 +98,23 @@ def post(self):
9798
"db/.db", "PWC_HOTSPOT_PASSWORD", content["password"]
9899
)
99100

101+
# Set the new SSID to the global var
102+
config.hotspot_password = content["password"]
103+
104+
# Fetch ID of any current connection
105+
connection = get_connection_id()
106+
107+
# If there is a running hotspot, recreate it with the new details
108+
if (
109+
connection
110+
and connection.GetSettings()["802-11-wireless"]["mode"] == "ap"
111+
):
112+
wifi_forget_thread = threading.Thread(
113+
target=forget,
114+
kwargs={"create_new_hotspot": True},
115+
)
116+
wifi_forget_thread.start()
117+
100118
return {"message": "ok"}, 200
101119

102120

@@ -110,6 +128,23 @@ def post(self):
110128
else:
111129
dotenv.set_key("db/.db", "PWC_HOTSPOT_SSID", content["ssid"])
112130

131+
# Set the new SSID to the global var
132+
config.hotspot_ssid = content["ssid"]
133+
134+
# Fetch ID of any current connection
135+
connection = get_connection_id()
136+
137+
# If there is a running hotspot, recreate it with the new details
138+
if (
139+
connection
140+
and connection.GetSettings()["802-11-wireless"]["mode"] == "ap"
141+
):
142+
wifi_forget_thread = threading.Thread(
143+
target=forget,
144+
kwargs={"create_new_hotspot": True},
145+
)
146+
wifi_forget_thread.start()
147+
113148
return {"message": "ok"}, 200
114149

115150

0 commit comments

Comments
 (0)