Skip to content

Commit bbc2240

Browse files
Merge pull request #379 from pollen-robotics/373-bis-debug-wifi
373 Improve wifi settings
2 parents 1d300ba + 9565591 commit bbc2240

20 files changed

+3292
-53
lines changed

src/reachy_mini/daemon/app/dashboard/static/css/app.css

Lines changed: 1301 additions & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/reachy_mini/daemon/app/dashboard/static/js/update.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ const updateManager = {
33
preRelease: false,
44

55
isUpdateAvailable: async () => {
6-
fetch('/update/available?pre_release=' + updateManager.preRelease)
7-
.then(response => response.json())
8-
.then(data => {
6+
await fetch('/update/available?pre_release=' + updateManager.preRelease)
7+
.then(async response => {
8+
if (!response.ok) {
9+
return false;
10+
}
11+
const data = await response.json();
912
return data.update.reachy_mini;
1013
}).catch(error => {
1114
console.error('Error checking for updates:', error);
Lines changed: 109 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11

2-
const refreshStatus = () => {
3-
fetch('/wifi/status')
2+
const getStatus = async () => {
3+
return await fetch('/wifi/status')
44
.then(response => response.json())
5-
.then(data => {
6-
handleStatus(data);
7-
})
85
.catch(error => {
96
console.error('Error fetching WiFi status:', error);
10-
handleStatus('error');
7+
return { mode: 'error' };
118
});
9+
};
1210

13-
fetch('/wifi/error')
11+
const refreshStatus = async () => {
12+
const status = await getStatus();
13+
handleStatus(status);
14+
15+
await fetch('/wifi/error')
1416
.then(response => response.json())
1517
.then(data => {
1618
if (data.error !== null) {
@@ -24,6 +26,27 @@ const refreshStatus = () => {
2426
});
2527
};
2628

29+
const scanAndListWifiNetworks = async () => {
30+
await fetch('/wifi/scan_and_list', { method: 'POST' })
31+
.then(response => response.json())
32+
.then(data => {
33+
const ssidSelect = document.getElementById('ssid');
34+
data.forEach(ssid => {
35+
const option = document.createElement('option');
36+
option.value = ssid;
37+
option.textContent = ssid;
38+
ssidSelect.appendChild(option);
39+
});
40+
})
41+
.catch(() => {
42+
const ssidSelect = document.getElementById('ssid');
43+
const option = document.createElement('option');
44+
option.value = "";
45+
option.textContent = "Unable to load networks";
46+
ssidSelect.appendChild(option);
47+
});
48+
};
49+
2750
const connectToWifi = (_) => {
2851
const ssid = document.getElementById('ssid').value;
2952
const password = document.getElementById('password').value;
@@ -45,11 +68,15 @@ const connectToWifi = (_) => {
4568
throw new Error(errData.detail || 'Failed to connect to WiFi');
4669
});
4770
}
71+
72+
// Clear the form fields
73+
document.getElementById('ssid').value = '';
74+
document.getElementById('password').value = '';
75+
4876
return response.json();
4977
})
5078
.then(data => {
51-
console.log('Connection response:', data);
52-
handleStatus('busy');
79+
handleStatus({ mode: 'busy' });
5380
})
5481
.catch(error => {
5582
console.error('Error connecting to WiFi:', error);
@@ -58,33 +85,92 @@ const connectToWifi = (_) => {
5885
return false; // Prevent form submission
5986
};
6087

88+
let currentMode = null;
89+
6190
const handleStatus = (status) => {
6291
const statusDiv = document.getElementById('wifi-status');
63-
const addWifiDiv = document.getElementById('add-wifi');
64-
const busyDiv = document.getElementById('busy');
6592

66-
addWifiDiv.classList = 'hidden';
93+
const knownNetworksDiv = document.getElementById('known-networks');
94+
const knownNetworksList = document.getElementById('known-networks-list');
95+
knownNetworksDiv.classList.remove('hidden');
96+
97+
const mode = status.mode;
98+
99+
knownNetworksList.innerHTML = '';
100+
if (status.known_networks !== undefined && Array.isArray(status.known_networks)) {
101+
status.known_networks.forEach((network) => {
102+
const li = document.createElement('li');
103+
li.classList = 'flex flex-row items-center mb-1 gap-4 justify-left';
104+
105+
const nameSpan = document.createElement('span');
106+
nameSpan.innerText = network;
107+
li.appendChild(nameSpan);
108+
109+
// const removeBtn = document.createElement('span');
110+
// removeBtn.innerText = ' (remove ❌)';
111+
// removeBtn.style.cursor = 'pointer';
112+
// removeBtn.title = 'Remove network';
113+
// removeBtn.onclick = async () => {
114+
// if (confirm(`Remove network '${network}'?`)) {
115+
// removeNetwork(network);
116+
// }
117+
// };
118+
// li.appendChild(removeBtn);
67119

68-
if (status == 'hotspot') {
120+
knownNetworksList.appendChild(li);
121+
});
122+
}
123+
124+
if (mode == 'hotspot') {
69125
statusDiv.innerText = 'Hotspot mode active. 🔌';
70-
addWifiDiv.classList.remove('hidden');
71-
} else if (status == 'wlan') {
72-
statusDiv.innerText = 'Connected to WiFi. 📶';
73-
} else if (status == 'disconnected') {
126+
127+
} else if (mode == 'wlan') {
128+
if (currentMode !== null && currentMode !== 'wlan') {
129+
alert(`Successfully connected to WiFi network: ${status.connected_network} ✅`);
130+
}
131+
132+
statusDiv.innerText = `Connected to WiFi (SSID: ${status.connected_network}). 📶`;
133+
134+
} else if (mode == 'disconnected') {
74135
statusDiv.innerText = 'WiFi disconnected. ❌';
75-
} else if (status == 'busy') {
136+
} else if (mode == 'busy') {
76137
statusDiv.innerText = 'Changing your WiFi configuration... Please wait ⏳';
77-
busyDiv.hidden = false;
78-
} else if (status == 'error') {
138+
} else if (mode == 'error') {
79139
statusDiv.innerText = 'Error connecting to WiFi. ⚠️';
80140
} else {
81141
console.warn(`Unknown status: ${status}`);
82142
}
83143

84-
currentStatus = status;
144+
currentMode = mode;
145+
};
146+
147+
const removeNetwork = async (ssid) => {
148+
const status = await getStatus();
149+
150+
// TODO:
151+
// if ssid !== status.connected_network:
152+
// remove connection
153+
// else:
154+
// refresh nmcli? go back to hotspot if needed?
155+
};
156+
157+
const cleanAndRefresh = async () => {
158+
const statusDiv = document.getElementById('wifi-status');
159+
statusDiv.innerText = 'Checking WiFi configuration...';
160+
161+
const knownNetworksDiv = document.getElementById('known-networks');
162+
knownNetworksDiv.classList.add('hidden');
163+
164+
const addWifi = document.getElementById('add-wifi');
165+
addWifi.classList.add('hidden');
166+
167+
await scanAndListWifiNetworks();
168+
await refreshStatus();
169+
170+
addWifi.classList.remove('hidden');
85171
};
86172

87-
window.addEventListener('load', () => {
88-
refreshStatus();
173+
window.addEventListener('load', async () => {
174+
await cleanAndRefresh();
89175
setInterval(refreshStatus, 1000);
90176
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Generate static Tailwind CSS
2+
3+
## Requirements
4+
5+
(From this folder)
6+
7+
```bash
8+
pnpm install -D tailwindcss @tailwindcss/cli
9+
```
10+
11+
## Generate CSS
12+
13+
```bash
14+
npx @tailwindcss/cli -i ./styles/app.css -o ../static/css/app.css
15+
```

0 commit comments

Comments
 (0)