Skip to content

Commit

Permalink
Added feedback to the user when uploading OTA firmware. Block the use…
Browse files Browse the repository at this point in the history
…r from starting a second OTA upload when one is in progress but disabling the button.
  • Loading branch information
Brian Mathews authored and Brian Mathews committed Nov 26, 2024
1 parent 3a1df43 commit 69e0630
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion firmware/webtools/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SOTACAT for Elecraft KX2 and KX3",
"version": "2024-11-23_21:13-Release",
"version": "2024-11-25_18:51-Release",
"builds": [
{
"chipFamily": "ESP32-C3",
Expand Down
2 changes: 1 addition & 1 deletion include/build_info.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_DATE_TIME "241123:2113"
#define BUILD_DATE_TIME "241125:1851"
32 changes: 26 additions & 6 deletions src/web/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,19 @@ function updateButtonText() {
function uploadFirmware() {
const otaFileInput = document.getElementById('ota-file');
const otaStatus = document.getElementById('ota-status');
const uploadButton = document.getElementById('upload-button');
const file = otaFileInput.files[0];

if (!file) {
alert('Please select a firmware file to upload.');
return;
}

// Disable the button and update status to show upload is in progress
uploadButton.disabled = true;
uploadButton.textContent = 'Uploading firmware...';
otaStatus.innerHTML = 'Uploading firmware... Please wait and do not refresh the page.';

const blob = new Blob([file], { type: 'application/octet-stream' });

fetch('/api/v1/ota', {
Expand All @@ -145,13 +151,23 @@ function uploadFirmware() {
})
.then(response => {
if (response.ok) {
// Successful OTA upload, no content returned
otaStatus.innerHTML = 'Firmware upload successful. SOTAcat will now reboot.';
alert("Firmware upload successful.\nYour SOTAcat is rebooting with the new firmware.\nPlease restart your browser.");
return null; // No further processing needed
// Update status to show firmware is being applied
otaStatus.innerHTML = 'Firmware upload successful. Applying firmware update...';
uploadButton.textContent = 'Applying firmware...';

// Show final message and alert
setTimeout(() => {
otaStatus.innerHTML = 'Firmware upload successful. SOTAcat will now reboot.';
uploadButton.textContent = 'Upload Complete';
alert("Firmware upload successful.\nYour SOTAcat is rebooting with the new firmware.\nPlease restart your browser.");
}, 2000);
return null;
}
else {
// Error occurred, expecting a JSON error message in a "text/plain" content type
// Reset button state on error
uploadButton.disabled = false;
uploadButton.textContent = 'Upload Firmware';

return response.text().then(text => {
let errorData;
try {
Expand All @@ -167,7 +183,11 @@ function uploadFirmware() {
.catch(error => {
console.error('Firmware upload error:', error);
otaStatus.innerHTML = `Firmware upload failed: ${error.message}`;
alert(`Firmware upload failed: ${message.error}`);
alert(`Firmware upload failed: ${error.message}`);

// Reset button state
uploadButton.disabled = false;
uploadButton.textContent = 'Upload Firmware';
});
}

Expand Down

0 comments on commit 69e0630

Please sign in to comment.