diff --git a/esp-link/cgi.c b/esp-link/cgi.c index 96c03e9..d0f7fb6 100644 --- a/esp-link/cgi.c +++ b/esp-link/cgi.c @@ -213,7 +213,8 @@ int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) { #ifdef MQTT "\"REST/MQTT\", \"/mqtt.html\", " #endif - "\"Debug log\", \"/log.html\"" + "\"Debug log\", \"/log.html\"," + "\"Upgrade Firmware\", \"/flash.html\"" " ], " "\"version\": \"%s\", " "\"name\": \"%s\"" diff --git a/html/flash.html b/html/flash.html new file mode 100644 index 0000000..2de096a --- /dev/null +++ b/html/flash.html @@ -0,0 +1,43 @@ +
+
+

Upgrade Firmware

+
+ +
+
+
+
+

Upgrade Firmware +
+

+ +
+
+
+
+
+ + + + + diff --git a/html/flash.js b/html/flash.js new file mode 100644 index 0000000..ca3d6ef --- /dev/null +++ b/html/flash.js @@ -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; } + } + ); +} diff --git a/html/ui.js b/html/ui.js index aa66f69..67361c9 100644 --- a/html/ui.js +++ b/html/ui.js @@ -151,7 +151,7 @@ function toggleClass(el, cl) { //===== AJAX -function ajaxReq(method, url, ok_cb, err_cb) { +function ajaxReq(method, url, ok_cb, err_cb, data) { var xhr = j(); xhr.open(method, url, true); var timeout = setTimeout(function() { @@ -173,7 +173,7 @@ function ajaxReq(method, url, ok_cb, err_cb) { } // console.log("XHR send:", method, url); try { - xhr.send(); + xhr.send(data); } catch(err) { console.log("XHR EXC :", method, url, "->", err); err_cb(599, err);