6
6
from common .wifi import check_wifi_status
7
7
from common .wifi import connect
8
8
from common .wifi import forget
9
+ from common .wifi import get_connection_id
9
10
from common .wifi import list_access_points
10
11
from dotenv import dotenv_values
11
12
from flask import request
@@ -50,12 +51,12 @@ def get(self):
50
51
51
52
class wifi_forget (Resource ):
52
53
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
-
57
54
# Check the all_networks boolean
58
55
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
+
59
60
forget_mode = False
60
61
else :
61
62
forget_mode = request .get_json ()["all_networks" ]
@@ -97,6 +98,23 @@ def post(self):
97
98
"db/.db" , "PWC_HOTSPOT_PASSWORD" , content ["password" ]
98
99
)
99
100
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
+
100
118
return {"message" : "ok" }, 200
101
119
102
120
@@ -110,6 +128,23 @@ def post(self):
110
128
else :
111
129
dotenv .set_key ("db/.db" , "PWC_HOTSPOT_SSID" , content ["ssid" ])
112
130
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
+
113
148
return {"message" : "ok" }, 200
114
149
115
150
0 commit comments