File tree Expand file tree Collapse file tree 3 files changed +39
-4
lines changed
src/reachy_mini/daemon/app Expand file tree Collapse file tree 3 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,27 @@ const refreshStatus = () => {
2424 } ) ;
2525} ;
2626
27+ const scanAndListWifiNetworks = async ( ) => {
28+ await fetch ( '/wifi/scan_and_list' , { method : 'POST' } )
29+ . then ( response => response . json ( ) )
30+ . then ( data => {
31+ const ssidSelect = document . getElementById ( 'ssid' ) ;
32+ data . forEach ( ssid => {
33+ const option = document . createElement ( 'option' ) ;
34+ option . value = ssid ;
35+ option . textContent = ssid ;
36+ ssidSelect . appendChild ( option ) ;
37+ } ) ;
38+ } )
39+ . catch ( ( ) => {
40+ const ssidSelect = document . getElementById ( 'ssid' ) ;
41+ const option = document . createElement ( 'option' ) ;
42+ option . value = "" ;
43+ option . textContent = "Unable to load networks" ;
44+ ssidSelect . appendChild ( option ) ;
45+ } ) ;
46+ } ;
47+
2748const connectToWifi = ( _ ) => {
2849 const ssid = document . getElementById ( 'ssid' ) . value ;
2950 const password = document . getElementById ( 'password' ) . value ;
@@ -84,7 +105,8 @@ const handleStatus = (status) => {
84105 currentStatus = status ;
85106} ;
86107
87- window . addEventListener ( 'load' , ( ) => {
88- refreshStatus ( ) ;
108+ window . addEventListener ( 'load' , async ( ) => {
109+ await scanAndListWifiNetworks ( ) ;
110+ await refreshStatus ( ) ;
89111 setInterval ( refreshStatus , 1000 ) ;
90112} ) ;
Original file line number Diff line number Diff line change 33
44 < div class ="flex p-4 gap-4 ">
55 < div class ="wifi-status "> Current Status:</ div >
6- < div id ="wifi-status " class ="wifi-status-info "> Loading ...</ div >
6+ < div id ="wifi-status " class ="wifi-status-info "> Checking WiFi configuration ...</ div >
77 </ div >
88 < div id ="add-wifi " class ="hidden ">
99 < div class ="py-4 flex flex-col max-w-md ">
1313 < form id ="wifi-form " class ="max-w-md " onsubmit ="return false; ">
1414 < div class ="mb-4 ">
1515 < label for ="ssid " class ="block mb-2 text-sm "> SSID</ label >
16- < input type =" text " id ="ssid " name ="ssid "
16+ < select id ="ssid " name ="ssid "
1717 class ="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 "
1818 required >
19+ < option value ="" disabled selected > Select your WiFi network</ option >
20+ </ select >
1921 </ div >
2022 < div class ="mb-4 ">
2123 < label for ="password " class ="block mb-2 text-sm "> Password</ label >
Original file line number Diff line number Diff line change @@ -113,6 +113,17 @@ def connect() -> None:
113113 # TODO: wait for it to be really connected
114114
115115
116+ @router .post ("/scan_and_list" )
117+ def scan_wifi () -> list [str ]:
118+ """Scan for available WiFi networks ordered by signal power."""
119+ wifi = scan_available_wifi ()
120+
121+ seen = set ()
122+ ssids = [x .ssid for x in wifi if x .ssid not in seen and not seen .add (x .ssid )]
123+
124+ return ssids
125+
126+
116127# NMCLI WRAPPERS
117128def scan_available_wifi () -> list [nmcli .data .device .DeviceWifi ]:
118129 """Scan for available WiFi networks."""
You can’t perform that action at this time.
0 commit comments