refactor(ota): implement polling-based update system and fix API typo
Test project compilation / test (push) Successful in 3m52s

- Fix typo in OTA update status API endpoint (/ota_udpate_status → /ota_update_status)
- Replace WebSocket-based update progress with polling mechanism
- Add OTA lifecycle callbacks (started, finished, progress, error)
- Implement check_update_task with internet connectivity verification
- Add LittleFS/SPIFFS update support
- Simplify update progress page to use 90-second delay and polling instead of real-time WebSocket updates

This refactor improves reliability by checking internet connectivity before attempting updates and simplifies the frontend by removing WebSocket complexity in favor of a timeout-based polling approach.
This commit is contained in:
2026-05-12 19:09:05 +02:00
parent d337784faa
commit 8fbbfc90cd
12 changed files with 263 additions and 285 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ function fetchWaterData(gauge) {
}
function fetchUpdateData(gauge) {
const apiUrl = '/ota_udpate_status';
const apiUrl = '/ota_update_status';
// Fetching data from the API
fetch(apiUrl)
.then(response => response.json())
+26 -38
View File
@@ -15,44 +15,32 @@
</div>
</div>
</div>
</body>
<script>
const webSocket = new WebSocket('webSocket://' + window.location.host + '/webSocket');
<script>
// Wait 90 seconds after page load, then start checking if server is up
window.addEventListener('load', function() {
setTimeout(checkServerAndRedirect, 90000); // 90 seconds = 90000 ms
});
webSocket.onopen = function() {
console.log('WebSocket connection opened.');
};
webSocket.onmessage = function(event) {
console.log('Progress:', event.data);
// Update the progress bar
let progress = parseInt(event.data);
if (progress == -1) {
document.getElementById('progress').textContent = "Upgrade Done, wait for reboot...";
const checkStatus = setInterval(() => {
fetch('/ota_udpate_status')
.then(response => {
if (response.ok) {
clearInterval(checkStatus);
window.location.href = '/';
}
function checkServerAndRedirect() {
// Try to fetch the home page to check if server is up
fetch('/', {
method: 'GET',
cache: 'no-cache'
})
.catch(error => console.error('Error checking OTA update status:', error));
}, 1000);
} else {
document.getElementById('progress').textContent = progress + '%';
}
};
webSocket.onerror = function(error) {
console.error('WebSocket error:', error);
};
webSocket.onclose = function() {
console.log('WebSocket connection closed.');
};
</script>
.then(response => {
// If we get a response (server is up), redirect to home page
if (response.ok) {
window.location.href = '/';
} else {
// Server responded but with an error, wait and retry
setTimeout(checkServerAndRedirect, 5000); // 5 seconds = 5000 ms
}
})
.catch(error => {
// Fetch failed (server not up yet), wait and retry
setTimeout(checkServerAndRedirect, 5000); // 5 seconds = 5000 ms
});
}
</script>
</body>