From ced7f21f19c2d8cb878b31c3bf18d9023f979478 Mon Sep 17 00:00:00 2001 From: nemik Date: Fri, 22 Jul 2016 13:10:12 -0500 Subject: [PATCH] enable firmware flashing from the web UI --- esp-link/cgi.c | 3 ++- html/flash.html | 44 ++++++++++++++++++++++++++++++++++++++++++++ html/flash.js | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 html/flash.html create mode 100644 html/flash.js 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..9b283d7 --- /dev/null +++ b/html/flash.html @@ -0,0 +1,44 @@ +
+
+

Upgrade Firmware

+
+ +
+
+
+
+

Upgrade Firmware +
+

+ +
+
+
+
+
+ + + + + + diff --git a/html/flash.js b/html/flash.js new file mode 100644 index 0000000..25ae8f4 --- /dev/null +++ b/html/flash.js @@ -0,0 +1,40 @@ +//===== 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 ..."); + + nanoajax.ajax({url: '/flash/upload', method: 'POST', body: fw_data}, function (code, responseText, request) { + if(""+code == "200") + { + 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"); + }); + } + }) +} + +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; } + } + ); +} + +function setMqtt(name, v) { + +}