From 099661690735e39da05df0e3faf46c178f446955 Mon Sep 17 00:00:00 2001 From: rob040 Date: Mon, 8 Jan 2024 15:06:40 +0100 Subject: [PATCH 1/3] on setup page, fix missing save icon on Update tab, save configuration button, and align "Store wifi credentials" switch to left and look same as other input fields. app.js: duplicate svg-save ref to svg-save2, hide save button when no-dhcp is disabled; other deltas are whithespace/tabs setup.htm: duplicate svg-save ref to svg-save2, --- built-in-webpages/setup/app.js | 56 +++++++++++++++---------------- built-in-webpages/setup/setup.htm | 4 +-- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/built-in-webpages/setup/app.js b/built-in-webpages/setup/app.js index adb42314..fd57a501 100644 --- a/built-in-webpages/setup/app.js +++ b/built-in-webpages/setup/app.js @@ -18,7 +18,7 @@ var lastBox; // Simple JQuery-like selector var $ = function(el) { - return document.getElementById(el); + return document.getElementById(el); }; function newEl(element, attribute) { @@ -71,13 +71,13 @@ function selectWifi(row) { function listWifiNetworks(elems) { const list = document.querySelector('#wifi-list'); list.innerHTML = ""; - elems.forEach((elem, idx) => { + elems.forEach((elem, idx) => { // Create a single row with all columns var row = newEl('tr'); var id = 'wifi-' + idx; row.id = id; row.addEventListener('click', selectWifi); - row.innerHTML = ``; + row.innerHTML = ``; row.innerHTML += `${elem.ssid}`; row.innerHTML += '' + elem.strength + ' dBm'; row.innerHTML += (elem.security) ? '' + svgLock + '' : '' + svgUnlock + ''; @@ -156,7 +156,7 @@ function addOptionsElement(opt) { obj[key] = opt[key]; return obj; }, {}); - + if (Object.entries(bools).length !== 0) { var d = newEl('div', {'class': 'row-wrapper'}); Object.entries(bools).forEach(([key, value]) => { @@ -174,20 +174,20 @@ function addOptionsElement(opt) { }); lastBox.appendChild(d); } - + const others = Object.keys(opt) .filter(key => typeof(opt[key]) !== "boolean") .reduce((obj, key) => { obj[key] = opt[key]; return obj; }, {}); - + Object.entries(others).forEach(([key, value]) => { let lbl = newEl('label', {'class': 'input-label', 'label-for': key}); lbl.textContent = key; let el = newEl('input', {'class': 'opt-input', 'type': 'text', 'id': key}); el.value = value; - + if (typeof(value) === "number") el.setAttribute('type', 'number'); if (typeof(value) === "object" ) { @@ -223,7 +223,7 @@ function addOptionsElement(opt) { el.classList.add('hide'); } }); - + } @@ -233,7 +233,7 @@ function createNewBox(cont, lbl) { h.innerHTML = lbl; box.appendChild(h); $('main-box').appendChild(box); - + // Add new voice in menu and relatvie listener var lnk = newEl('a', {'class': 'a-link', 'id': 'set-opt'+cont, 'data-box': 'option-box'+cont}); lnk.innerHTML = lbl; @@ -245,8 +245,8 @@ function createNewBox(cont, lbl) { async function createOptionsBox(raw) { var nest = {}; var boxId = 'wifi-box'; - lastBox = $(boxId); - + lastBox = $(boxId); + Object.entries(raw).forEach(([key, value], index) => { if (boxId === 'wifi-box') { $('no-dhcp').checked = raw.dhcp; @@ -300,7 +300,7 @@ async function createOptionsBox(raw) { } } }); - + // Add last items if (Object.entries(nest).length !== 0) { addOptionsElement(nest); @@ -351,7 +351,7 @@ function addInputListener(item) { function insertKey(key,value,obj,pos){ return Object.keys(obj).reduce((ac,a,i) => { if(i === pos) ac[key] = value; - ac[a] = obj[a]; + ac[a] = obj[a]; return ac; },{}); } @@ -360,13 +360,13 @@ function saveParameters() { // Backward compatibility if(Object.keys(options)[0].startsWith('param-box')) { if(Object.keys(options)[0] === 'param-box0') { - options['param-box-0'] = options['wifi-box']; + options['param-box-0'] = options['wifi-box']; options = {'dhcp': false, ...options}; } else options = {'wifi-box': '', 'dhcp': false, ...options}; } - + options.dhcp = $('no-dhcp').checked; if ($('no-dhcp').checked) { options = insertKey('ip_address', $('ip').value, options, 2); @@ -376,7 +376,7 @@ function saveParameters() { options["gateway"] = $('gateway').value; options["subnet"] = $('subnet').value; } - + var myblob = new Blob([JSON.stringify(options, null, 2)], { type: 'application/json' }); @@ -417,7 +417,7 @@ function doConnection(e, f) { body: formdata, redirect: 'follow' }; - + $('loader').classList.remove('hide'); var s; fetch('/connect', requestOptions) @@ -434,13 +434,13 @@ function doConnection(e, f) { else openModalMessage('Connect to WiFi', data, restartESP); } - else + else openModalMessage('Error!', data); $('loader').classList.add('hide'); }) .catch((error) => { openModalMessage('Connect to WiFi', error); - $('loader').classList.add('hide'); + $('loader').classList.add('hide'); }); } @@ -463,15 +463,13 @@ function switchPage(el) { if(el.target.id != 'set-wifi') { var fragment = document.createDocumentFragment(); fragment.appendChild($('btn-hr')); - fragment.appendChild($('btn-box')); - const box = $(el.target.getAttribute("data-box")); - box.appendChild(fragment); - - document.querySelectorAll('.raw-html').forEach(function(el) { - if (el.getAttribute("data-box") === box.id) + fragment.appendChild($('btn-box')); + const box = $(el.target.getAttribute("data-box")); + box.appendChild(fragment); + document.querySelectorAll('.raw-html').forEach(function(el) { + if (el.getAttribute("data-box") === box.id) box.insertBefore(el, $('btn-hr')); }); - $('btn-box').classList.remove('hide'); $('btn-hr').classList.remove('hide'); } @@ -529,11 +527,11 @@ function handleSubmit() { prg.classList.remove('hide'); prg.classList.add('active') update.innerHTML = 'Update in progress'; - + let formData = new FormData(); formData.set('update', fileElement.files[0]); var req = new XMLHttpRequest(); - req.open('POST', '/update?size=' + fileElement.files[0].size); + req.open('POST', '/update?size=' + fileElement.files[0].size); req.onload = function(d) { loader.classList.add('hide'); prg.classList.remove('active'); @@ -579,6 +577,7 @@ $('svg-no-eye').innerHTML = svgNoEye; $('svg-scan').innerHTML = svgScan; $('svg-connect').innerHTML = svgConnect; $('svg-save').innerHTML = svgSave; +$('svg-save2').innerHTML = svgSave; $('svg-restart').innerHTML = svgRestart; $('img-logo').innerHTML = svgLogo; @@ -608,6 +607,7 @@ $('no-dhcp').addEventListener('change', function() { } else { el.classList.add('hide'); + btn.classList.remove('hide'); } }); window.addEventListener('load', getParameters); diff --git a/built-in-webpages/setup/setup.htm b/built-in-webpages/setup/setup.htm index aea135e6..830482a6 100644 --- a/built-in-webpages/setup/setup.htm +++ b/built-in-webpages/setup/setup.htm @@ -79,7 +79,7 @@

Connect to WiFi

-
From 2950b5c7cce1e648d0deb8975bb5240c19da8696 Mon Sep 17 00:00:00 2001 From: rob040 Date: Wed, 10 Jan 2024 11:28:57 +0100 Subject: [PATCH 2/3] Some typo's corrected and undo changes introduced by 'setupPageFix', since they are already corrected in master. --- README.md | 12 ++-- built-in-webpages/setup/app.js | 55 ++++++++++--------- built-in-webpages/setup/setup.htm | 2 +- examples/customHTML/customElements.h | 4 +- examples/customHTML/customHTML.ino | 29 +++++----- examples/customHTML/thingsboard.h | 2 +- examples/customOptions/customOptions.ino | 10 ++-- examples/esp32-cam/esp32-cam.ino | 6 +- examples/gpio_list/gpio_list.ino | 4 +- examples/handleFormData/handleFormData.ino | 6 +- examples/highcharts/highcharts.ino | 6 +- examples/highcharts/readme.md | 10 ++-- examples/remoteOTA/remoteOTA.ino | 4 +- examples/simpleServer/simpleServer.ino | 6 +- .../simpleServerCaptive.ino | 8 ++- examples/withWebSocket/readme.md | 6 +- examples/withWebSocket/withWebSocket.ino | 6 +- 17 files changed, 91 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index 2169edd2..9a556f8e 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,16 @@ If you like this work, please consider [sponsoring this project!](https://paypal # async-esp-fs-webserver ESP32/ESP8266 WebServer, WiFi manager and ACE web editor Arduino library. Based on [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) from @me-no-dev -Thi is the equivalent to **esp-fs-webserver** Arduino library, but working with the very good **ESPAsyncWebServer** library instead default webserver library. +This is the equivalent to **esp-fs-webserver** Arduino library, but working with the very good **ESPAsyncWebServer** library instead default webserver library. From some tests I have done, I have been able to observe that a webserver created with this library is much faster and more responsive, which is why I decided to develop this variant of the library. **Note**: -Starting from version 2.0.0 ESP32 core for Aruino introduced the LittlsFS library like ESP8266. The examples in this library is written to work with this for both platform by default. Change according to your needs if you prefer other filesystems. +Starting from version 2.0.0 ESP32 core for Arduino introduced the LittlsFS library like ESP8266. The examples in this library is written to work with this for both platform by default. Change according to your needs if you prefer other filesystems. ## WiFi, OTA firmware update and Options manager -Thanks to the built-in page **/setup** (about 6.9Kb of program space) is possible scan and set the WiFi credentials and other freely configurable parameters. +Thanks to the built-in page **/setup** (about 6.9Kb of program space) it is possible to scan and set the WiFi credentials and other freely configurable parameters. -With **/setup** webpage is also possible perform remote firmware update. +With **/setup** webpage it is also possible to perform remote firmware update (OTA-update). ![image](https://github.com/cotestatnt/async-esp-fs-webserver/assets/27758688/e16cf5cb-252a-42bb-b111-305387f9d0cc) @@ -25,8 +25,8 @@ In the image below, for example, the HTML and Javascript code to provision the d ## ACE web file editor/browser -Thanks to the built-in **/edit** page, is possible upload, delete and edit the HTML/CSS/JavaScript source files directly from browser and immediately displaying the changes introduced at runtime without having to recompile the device firmware. -The page can be enabled at runtime using the method `enableFsCodeEditor()` and it occupy about 6.7Kb of program space. +Thanks to the built-in **/edit** page, it is possible to upload, delete and edit the HTML/CSS/JavaScript source files directly from browser and immediately display the changes introduced at runtime without having to recompile the device firmware. +The page can be enabled at runtime using the method `enableFsCodeEditor()` and it occupies about 6.7Kb of program space. ![image](https://github.com/cotestatnt/async-esp-fs-webserver/assets/27758688/668c0899-a060-4aed-956b-51311bf3fe13) diff --git a/built-in-webpages/setup/app.js b/built-in-webpages/setup/app.js index fd57a501..0e88fc88 100644 --- a/built-in-webpages/setup/app.js +++ b/built-in-webpages/setup/app.js @@ -18,7 +18,7 @@ var lastBox; // Simple JQuery-like selector var $ = function(el) { - return document.getElementById(el); + return document.getElementById(el); }; function newEl(element, attribute) { @@ -71,13 +71,13 @@ function selectWifi(row) { function listWifiNetworks(elems) { const list = document.querySelector('#wifi-list'); list.innerHTML = ""; - elems.forEach((elem, idx) => { + elems.forEach((elem, idx) => { // Create a single row with all columns var row = newEl('tr'); var id = 'wifi-' + idx; row.id = id; row.addEventListener('click', selectWifi); - row.innerHTML = ``; + row.innerHTML = ``; row.innerHTML += `${elem.ssid}`; row.innerHTML += '' + elem.strength + ' dBm'; row.innerHTML += (elem.security) ? '' + svgLock + '' : '' + svgUnlock + ''; @@ -156,7 +156,7 @@ function addOptionsElement(opt) { obj[key] = opt[key]; return obj; }, {}); - + if (Object.entries(bools).length !== 0) { var d = newEl('div', {'class': 'row-wrapper'}); Object.entries(bools).forEach(([key, value]) => { @@ -174,20 +174,20 @@ function addOptionsElement(opt) { }); lastBox.appendChild(d); } - + const others = Object.keys(opt) .filter(key => typeof(opt[key]) !== "boolean") .reduce((obj, key) => { obj[key] = opt[key]; return obj; }, {}); - + Object.entries(others).forEach(([key, value]) => { let lbl = newEl('label', {'class': 'input-label', 'label-for': key}); lbl.textContent = key; let el = newEl('input', {'class': 'opt-input', 'type': 'text', 'id': key}); el.value = value; - + if (typeof(value) === "number") el.setAttribute('type', 'number'); if (typeof(value) === "object" ) { @@ -223,7 +223,7 @@ function addOptionsElement(opt) { el.classList.add('hide'); } }); - + } @@ -233,7 +233,7 @@ function createNewBox(cont, lbl) { h.innerHTML = lbl; box.appendChild(h); $('main-box').appendChild(box); - + // Add new voice in menu and relatvie listener var lnk = newEl('a', {'class': 'a-link', 'id': 'set-opt'+cont, 'data-box': 'option-box'+cont}); lnk.innerHTML = lbl; @@ -245,8 +245,8 @@ function createNewBox(cont, lbl) { async function createOptionsBox(raw) { var nest = {}; var boxId = 'wifi-box'; - lastBox = $(boxId); - + lastBox = $(boxId); + Object.entries(raw).forEach(([key, value], index) => { if (boxId === 'wifi-box') { $('no-dhcp').checked = raw.dhcp; @@ -300,7 +300,7 @@ async function createOptionsBox(raw) { } } }); - + // Add last items if (Object.entries(nest).length !== 0) { addOptionsElement(nest); @@ -351,7 +351,7 @@ function addInputListener(item) { function insertKey(key,value,obj,pos){ return Object.keys(obj).reduce((ac,a,i) => { if(i === pos) ac[key] = value; - ac[a] = obj[a]; + ac[a] = obj[a]; return ac; },{}); } @@ -360,13 +360,13 @@ function saveParameters() { // Backward compatibility if(Object.keys(options)[0].startsWith('param-box')) { if(Object.keys(options)[0] === 'param-box0') { - options['param-box-0'] = options['wifi-box']; + options['param-box-0'] = options['wifi-box']; options = {'dhcp': false, ...options}; } else options = {'wifi-box': '', 'dhcp': false, ...options}; } - + options.dhcp = $('no-dhcp').checked; if ($('no-dhcp').checked) { options = insertKey('ip_address', $('ip').value, options, 2); @@ -376,7 +376,7 @@ function saveParameters() { options["gateway"] = $('gateway').value; options["subnet"] = $('subnet').value; } - + var myblob = new Blob([JSON.stringify(options, null, 2)], { type: 'application/json' }); @@ -417,7 +417,7 @@ function doConnection(e, f) { body: formdata, redirect: 'follow' }; - + $('loader').classList.remove('hide'); var s; fetch('/connect', requestOptions) @@ -434,13 +434,13 @@ function doConnection(e, f) { else openModalMessage('Connect to WiFi', data, restartESP); } - else + else openModalMessage('Error!', data); $('loader').classList.add('hide'); }) .catch((error) => { openModalMessage('Connect to WiFi', error); - $('loader').classList.add('hide'); + $('loader').classList.add('hide'); }); } @@ -463,13 +463,15 @@ function switchPage(el) { if(el.target.id != 'set-wifi') { var fragment = document.createDocumentFragment(); fragment.appendChild($('btn-hr')); - fragment.appendChild($('btn-box')); - const box = $(el.target.getAttribute("data-box")); - box.appendChild(fragment); - document.querySelectorAll('.raw-html').forEach(function(el) { - if (el.getAttribute("data-box") === box.id) + fragment.appendChild($('btn-box')); + const box = $(el.target.getAttribute("data-box")); + box.appendChild(fragment); + + document.querySelectorAll('.raw-html').forEach(function(el) { + if (el.getAttribute("data-box") === box.id) box.insertBefore(el, $('btn-hr')); }); + $('btn-box').classList.remove('hide'); $('btn-hr').classList.remove('hide'); } @@ -527,11 +529,11 @@ function handleSubmit() { prg.classList.remove('hide'); prg.classList.add('active') update.innerHTML = 'Update in progress'; - + let formData = new FormData(); formData.set('update', fileElement.files[0]); var req = new XMLHttpRequest(); - req.open('POST', '/update?size=' + fileElement.files[0].size); + req.open('POST', '/update?size=' + fileElement.files[0].size); req.onload = function(d) { loader.classList.add('hide'); prg.classList.remove('active'); @@ -607,7 +609,6 @@ $('no-dhcp').addEventListener('change', function() { } else { el.classList.add('hide'); - btn.classList.remove('hide'); } }); window.addEventListener('load', getParameters); diff --git a/built-in-webpages/setup/setup.htm b/built-in-webpages/setup/setup.htm index 830482a6..9f481cbb 100644 --- a/built-in-webpages/setup/setup.htm +++ b/built-in-webpages/setup/setup.htm @@ -79,7 +79,7 @@

Connect to WiFi

-