Upgrade firmware from web interface (#174)

* enable firmware flashing from the web UI
* remove mqtt reference from flash JS
* remove dependency on nanoajax
pull/193/head
Nemanja Stefanovic 8 years ago committed by Thorsten von Eicken
parent c5513d063d
commit 8c4c4928b1
  1. 3
      esp-link/cgi.c
  2. 43
      html/flash.html
  3. 33
      html/flash.js
  4. 4
      html/ui.js

@ -213,7 +213,8 @@ int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) {
#ifdef MQTT #ifdef MQTT
"\"REST/MQTT\", \"/mqtt.html\", " "\"REST/MQTT\", \"/mqtt.html\", "
#endif #endif
"\"Debug log\", \"/log.html\"" "\"Debug log\", \"/log.html\","
"\"Upgrade Firmware\", \"/flash.html\""
" ], " " ], "
"\"version\": \"%s\", " "\"version\": \"%s\", "
"\"name\": \"%s\"" "\"name\": \"%s\""

@ -0,0 +1,43 @@
<div id="main">
<div class="header">
<h1>Upgrade Firmware</h1>
</div>
<div class="content">
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-2">
<div class="card">
<h1>Upgrade Firmware
<div id="fw-spinner" class="spinner spinner-small"></div>
</h1>
<form action="#" id="fw-form" class="pure-form" hidden>
<legend>Firmware Info</legend>
<p>
Current firmware: <span style="font-weight: bold;" id="current-fw"></span>
</p>
<div class="pure-form-stacked">
<p>
Make sure you upload the file called: <span style="font-weight: bold;" id="fw-slot"></span>
</p>
<label>Firmware File</label>
<input type="file" name="fw-file" id="fw-file"/>
</div>
<button id="fw-button" type="submit" class="pure-button button-primary">
Update the firmware
</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="flash.js"></script>
<script type="text/javascript">
onLoad(function() {
fetchFlash();
bnd($("#fw-form"), "submit", flashFirmware);
});
</script>
</body></html>

@ -0,0 +1,33 @@
//===== FLASH cards
function flashFirmware(e) {
e.preventDefault();
var fw_data = document.getElementById('fw-file').files[0];
$("#fw-form").setAttribute("hidden", "");
$("#fw-spinner").removeAttribute("hidden");
showNotification("Firmware is being updated ...");
ajaxReq("POST", "/flash/upload", function (resp) {
ajaxReq("GET", "/flash/reboot", function (resp) {
showNotification("Firmware has been successfully updated!");
setTimeout(function(){ window.location.reload()}, 4000);
$("#fw-spinner").setAttribute("hidden", "");
$("#fw-form").removeAttribute("hidden");
});
}, null, fw_data)
}
function fetchFlash() {
ajaxReq("GET", "/flash/next", function (resp) {
$("#fw-slot").innerHTML = resp;
$("#fw-spinner").setAttribute("hidden", "");
$("#fw-form").removeAttribute("hidden");
});
ajaxJson("GET", "/menu", function(data) {
var v = $("#current-fw");
if (v != null) { v.innerHTML = data.version; }
}
);
}

@ -151,7 +151,7 @@ function toggleClass(el, cl) {
//===== AJAX //===== AJAX
function ajaxReq(method, url, ok_cb, err_cb) { function ajaxReq(method, url, ok_cb, err_cb, data) {
var xhr = j(); var xhr = j();
xhr.open(method, url, true); xhr.open(method, url, true);
var timeout = setTimeout(function() { var timeout = setTimeout(function() {
@ -173,7 +173,7 @@ function ajaxReq(method, url, ok_cb, err_cb) {
} }
// console.log("XHR send:", method, url); // console.log("XHR send:", method, url);
try { try {
xhr.send(); xhr.send(data);
} catch(err) { } catch(err) {
console.log("XHR EXC :", method, url, "->", err); console.log("XHR EXC :", method, url, "->", err);
err_cb(599, err); err_cb(599, err);

Loading…
Cancel
Save