Files
laadpaal/SmartEVSE-3/SmartEVSE-3/data/update2.html
2024-06-24 00:22:58 +02:00

174 lines
6.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>SmartEVSEv3</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
#container { margin-right: auto; margin-left: auto; max-width: 900px; }
#info { background: #e0f0f0; border-radius: .5em; padding: 2em; }
#wrapper { margin-top: 1em; }
</style>
<script>
let OWNER_FACT="SmartEVSE";
let REPO_FACT="SmartEVSE-3";
let OWNER_COMM="dingo35";
let REPO_COMM="SmartEVSE-3.5";
function update_comm() {
window.location.href = "/autoupdate?url=community&debug=0";
}
function update_fact() {
window.location.href = "/autoupdate?url=factory&debug=0";
}
function update_comm_debug() {
window.location.href = "/autoupdate?url=community&debug=1";
}
function update_fact_debug() {
window.location.href = "/autoupdate?url=factory&debug=1";
}
</script>
</head>
<body onload="loadData()">
<div id="container">
<div id="info">
Current version: <span id="version"></span>
=======================================================
DOWNLOADING
<br><br>
<table style='text-align: left'>
<tr>
<th>Distribution:</th>
<th>Status:</th>
<th>Github repo:</th>
<th>Latest version:</th>
<th>Flash:</th>
</tr>
<tr>
<td>Factory</td>
<td>stable</td>
<td><a href="https://github.com/"
onclick="location.href=this.href + OWNER_FACT + '/' + REPO_FACT + '/releases';return false;"><script>document.write(OWNER_FACT)</script></a></td>
<td><div id="latest_fact"></div></td>
<td><button onclick="update_fact()" style="width: 100px; display:inline-block;">Standard</button>
<td><button onclick="update_fact_debug()" style="width: 100px; display:inline-block;">Debug</button>
</tr>
<tr>
<td>Community&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</td>
<td>bleeding edge&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</td>
<td><a href="https://github.com/"
onclick="location.href=this.href + OWNER_COMM + '/' + REPO_COMM + '/releases';return false;"><script>document.write(OWNER_COMM)</script></a></td>
<td><div id="latest_comm"></div></td>
<td><button onclick="update_comm()" style="width: 100px; display:inline-block;">Standard</button>
<td><button onclick="update_comm_debug()" style="width: 100px; display:inline-block;">Debug</button>
</tr>
</table>
<br>
=======================================================
<br>
FLASHING
<br><br>
Flash one of:<ul>
<li>firmware.bin or firmware.signed.bin (to update the firmware);</li>
<li>firmware.debug.bin or firmware.debug.signed.bin (if you want to telnet to your SmartEVSE to see debug messages);</li>
<li>rfix.txt (if you want to bulk upload allowed NFC tags for the RFID reader);</li>
</ul>
You should only flash files with those exact names.<br>No need to flash spiffs.bin for versions 3.6.0-RC1 and newer!<br>No need to rename firmware.debug.bin anymore for versions 3.6.0-RC2 and newer!<br>Signed firmware is verified to be original and can be handled by versions 3.6.2 and newer.
</div>
<div id="wrapper">
<input type="file" id="el1" style="display: none"/>
<button id="el2">choose file...</button>
<div id="el3"></div>
</div>
</div>
</body>
<script type="module">
// Octokit.js
// https://github.com/octokit/core.js#readme
import { Octokit } from "https://esm.sh/@octokit/core";
window.loadData=loadData;
function loadData() {
document.getElementById("version").innerHTML = sessionStorage.getItem("version");
getLatestVersion(OWNER_FACT, REPO_FACT, 'latest_fact');
getLatestVersion(OWNER_COMM, REPO_COMM, 'latest_comm');
}
async function getLatestVersion(owner, repo, element) {
const octokit = new Octokit({
})
try {
const result = await octokit.request('GET /repos/{owner}/{repo}/releases/latest', {
owner: owner,
repo: repo,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
//asset_id=result.data.assets.filter(function(entry){ return entry.name==="firmware.signed.bin";})[0].id;
//console.log(asset_id);
//console.log(JSON.stringify(result.data.assets));
document.getElementById(element).innerHTML = result.data.tag_name;
} catch (error) {
console.error(error.message);
}
}
// Copyright (c) 2020 Cesanta Software Limited
// All rights reserved
// Helper function to display upload status
var setStatus = function(text) {
document.getElementById('el3').innerText = text;
};
// When user clicks on a button, trigger file selection dialog
var button = document.getElementById('el2');
button.onclick = function(ev) {
input.click();
};
// Send a large blob of data chunk by chunk
var sendFileData = function(name, data, chunkSize) {
var sendChunk = function(offset) {
var chunk = data.subarray(offset, offset + chunkSize) || '';
var opts = {method: 'POST', body: chunk};
var url = '/update?offset=' + offset + '&file=' + encodeURIComponent(name) + '&size=' + data.length;
var ok;
if (offset + chunk.length == data.length) {
setStatus('Upload of ' + name + ' finished, you can close this page.');
window.location.href = "/";
}
else
setStatus('Uploading ' + name + ', bytes ' + offset + '..' + (offset + chunk.length) + ' of ' + data.length);
fetch(url, opts)
.then(function(res) {
if (res.ok && chunk.length > 0) sendChunk(offset + chunk.length);
ok = res.ok;
return res.text();
})
.then(function(text) {
if (!ok) setStatus('Error: ' + text);
});
};
sendChunk(0);
};
// If user selected a file, read it into memory and trigger sendFileData()
var input = document.getElementById('el1');
input.onchange = function(ev) {
if (!ev.target.files[0]) return;
var f = ev.target.files[0], r = new FileReader();
r.readAsArrayBuffer(f);
r.onload = function() {
ev.target.value = '';
sendFileData(f.name, new Uint8Array(r.result), 20480);
};
};
</script>
</html>