-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #260 from somakeit/241-can-we-find-a-way-to-apply-…
…new-firmware-over-the-air 241 can we find a way to apply new firmware over the air
- Loading branch information
Showing
11 changed files
with
519 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
const version = '0.0.28'; | ||
|
||
document.getElementById('add_file_form').addEventListener('submit', function(event) { | ||
console.log('File staging update form submitted.'); | ||
event.preventDefault(); | ||
|
||
var request_body = JSON.stringify({"action": "add", "url": document.getElementById('url').value}); | ||
|
||
fetch('/api/firmware_files', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: request_body | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok ' + response.statusText); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
console.log('Request data returned:', data); | ||
if (data === true) { | ||
var result_message = "Firmware staging list updated successfully"; | ||
} | ||
|
||
else { | ||
var result_message = "Error updating firmware staging list. API return:", data; | ||
} | ||
|
||
document.getElementById('result').innerText = result_message; | ||
|
||
fetchURLs(); | ||
}) | ||
.catch(error => { | ||
console.error('Error encountered updating firmware staging list:', error); | ||
document.getElementById('result').innerText = "Error updating firmware staging list: " + error.message; | ||
}); | ||
|
||
}); | ||
|
||
document.getElementById('remove_file_form').addEventListener('submit', function(event) { | ||
console.log('File staging update form submitted.'); | ||
event.preventDefault(); | ||
|
||
var selectedUrl = document.querySelector('input[name="url"]:checked').value; | ||
|
||
var request_body = JSON.stringify({"action": "remove", "url": selectedUrl}); | ||
|
||
fetch('/api/firmware_files', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: request_body | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok ' + response.statusText); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
console.log('Request data returned:', data); | ||
if (data === true) { | ||
var result_message = "Firmware staging list updated successfully"; | ||
} | ||
|
||
else { | ||
var result_message = "Error updating firmware staging list. API return:", data; | ||
} | ||
|
||
document.getElementById('result').innerText = result_message; | ||
|
||
fetchURLs(); | ||
}) | ||
.catch(error => { | ||
console.error('Error encountered updating firmware staging list:', error); | ||
document.getElementById('result').innerText = "Error updating firmware staging list: " + error.message; | ||
}); | ||
|
||
}); | ||
|
||
|
||
document.addEventListener("DOMContentLoaded", function() { | ||
function fetchURLs() { | ||
fetch('api/firmware_files') | ||
.then(response => response.json()) | ||
.then(data => { | ||
console.log(data); | ||
const urlList = document.getElementById('url-list'); | ||
console.log(urlList); | ||
urlList.innerHTML = ''; | ||
if (data && data.length > 0) { | ||
console.log('URLs returned and processing'); | ||
data.forEach((url, index) => { | ||
if (url != "") { | ||
console.log('Adding URL:', url); | ||
const listItem = document.createElement('li'); | ||
const radioInput = document.createElement('input'); | ||
radioInput.type = 'radio'; | ||
radioInput.name = 'url'; | ||
radioInput.value = url; | ||
radioInput.id = `${index + 1}`; | ||
|
||
const label = document.createElement('label'); | ||
label.htmlFor = `${index + 1}`; | ||
label.textContent = url; | ||
|
||
listItem.appendChild(radioInput); | ||
listItem.appendChild(label); | ||
urlList.appendChild(listItem); | ||
} | ||
}); | ||
} | ||
}) | ||
.catch(error => console.error('Error fetching URLs:', error)); | ||
} | ||
|
||
window.fetchURLs = fetchURLs; | ||
fetchURLs(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>SMIBHID - Update</title> | ||
<link rel="stylesheet" href="css/style.css"> | ||
</head> | ||
<body> | ||
<h1>SMIBHID - Firmware update</h1> | ||
<p>Firmware can be uploaded to SMIBHID over the air here and restarted to apply. | ||
</p> | ||
|
||
<h2>Update files</h2> | ||
|
||
<h3>Delete files pending update</h3> | ||
<button onclick="fetchURLs()">Refresh URLs</button> | ||
<form action="/api/firmware_files" method="post" enctype="application/x-www-form-urlencoded" id="remove_file_form"> | ||
<ul id="url-list"> | ||
</ul> | ||
<input type="submit" name="action" value="Remove" id="Remove"/> | ||
</form> | ||
|
||
<h3>Provide the URL for a new firmware file here:</h3> | ||
<form action="" id="add_file_form"> | ||
<label for="url">Enter file URL:</label> | ||
<input type="text" id="url" /> | ||
<input type="submit" value="Add" /> | ||
</form> | ||
|
||
<span id="result"></span> | ||
|
||
<h3>Restart SMIBHID</h3> | ||
<form action="/api/reset" method="post"> | ||
<input type="submit" name="action" value="Restart" id="Restart"/> | ||
</form> | ||
|
||
<p>Return to <a href="/">home</a></p> | ||
|
||
</body> | ||
<script type="module" src="js/update.js?v=0.0.28"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.