From 1aaa906fe8eeb948dcdb1aaa23853845c46af958 Mon Sep 17 00:00:00 2001 From: Mario Lukas Date: Wed, 9 Dec 2020 19:24:05 +0100 Subject: [PATCH] refactor (HTML): changed a couple of things in the management.html file - changed html parts to a more meaningful naming --- html/{websiteBasic.html => accesspoint.html} | 0 ...bsiteBasic_EN.html => accesspoint_EN.html} | 0 html/management.html | 724 ++++++++++++++++++ html/{website_EN.html => management_EN.html} | 0 html/website.html | 639 ---------------- platformio.ini | 10 +- processHtml.py | 133 ++-- src/{websiteBasic.h => HTMLaccesspoint.h} | 6 +- ...websiteBasic_EN.h => HTMLaccesspoint_EN.h} | 2 +- src/HTMLmanagement.h | 721 +++++++++++++++++ src/{websiteMgmt_EN.h => HTMLmanagement_EN.h} | 2 +- src/main.cpp | 15 +- src/websiteMgmt.h | 640 ---------------- 13 files changed, 1535 insertions(+), 1357 deletions(-) rename html/{websiteBasic.html => accesspoint.html} (100%) rename html/{websiteBasic_EN.html => accesspoint_EN.html} (100%) create mode 100644 html/management.html rename html/{website_EN.html => management_EN.html} (100%) delete mode 100644 html/website.html rename src/{websiteBasic.h => HTMLaccesspoint.h} (93%) rename src/{websiteBasic_EN.h => HTMLaccesspoint_EN.h} (93%) create mode 100644 src/HTMLmanagement.h rename src/{websiteMgmt_EN.h => HTMLmanagement_EN.h} (99%) delete mode 100644 src/websiteMgmt.h diff --git a/html/websiteBasic.html b/html/accesspoint.html similarity index 100% rename from html/websiteBasic.html rename to html/accesspoint.html diff --git a/html/websiteBasic_EN.html b/html/accesspoint_EN.html similarity index 100% rename from html/websiteBasic_EN.html rename to html/accesspoint_EN.html diff --git a/html/management.html b/html/management.html new file mode 100644 index 0000000..7c616ed --- /dev/null +++ b/html/management.html @@ -0,0 +1,724 @@ + + + + ESPuino-Konfiguration + + + + + + + + + + + + + + + + + + +
+ +
+ + + + diff --git a/html/website_EN.html b/html/management_EN.html similarity index 100% rename from html/website_EN.html rename to html/management_EN.html diff --git a/html/website.html b/html/website.html deleted file mode 100644 index 5fd60a9..0000000 --- a/html/website.html +++ /dev/null @@ -1,639 +0,0 @@ - - - - ESPuino-Konfiguration - - - - - - - - - - - - - - - - -
-
-

WLAN-Konfiguration

-
-
- - -
- Bitte SSID des WLANs eintragen. -
- - - - -
- - -
-
-
-
-

RFID-Zuweisungen

-
-
- - - - -
-
-
-
- Dateiliste aktualisieren -
-
-
-
-


Der Prozess kann mehrere Minuten dauern...
-
-
-
-
- - -
- - -
-
-
-
-

RFID-Modifkationen

-
-
- - -
- Bitte eine 12-stellige Zahl eingeben. -
- - -
- - -
-
-
-
-

MQTT-Konfiguration

-
-
- - -
-
- - - - - - -
- - -
-
-
-
-

FTP-Konfiguration

-
-
- - - - -
- - -
-
-
-
-

Allgemeine Konfiguration

-
-
- - - - - - -
-
- - - - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- - -
-
-
-
-

NVS-Importer

-
-
- - -
- -
-
-
- - - diff --git a/platformio.ini b/platformio.ini index b8911b9..7771b77 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,17 +9,17 @@ ; https://docs.platformio.org/page/projectconf.html ;[env:nodemcu-32s] -[env:lolin32] +[env:az-delivery-devkit-v4] platform = espressif32 -;board = nodemcu-32s -board = lolin32 +board = az-delivery-devkit-v4 framework = arduino monitor_speed = 115200 board_build.partitions = no_ota.csv -;board_build.partitions = min_spiffs.csv - upload_port = /dev/cu.SLAB_USBtoUART monitor_port = /dev/cu.SLAB_USBtoUART +build_flags = -O2 +build_unflags = -Os + lib_deps = https://github.com/schreibfaul1/ESP32-audioI2S.git diff --git a/processHtml.py b/processHtml.py index 471c6c3..74e2749 100644 --- a/processHtml.py +++ b/processHtml.py @@ -1,61 +1,74 @@ +# -*- coding: utf-8 -*- #!/usr/bin/python -import re - -content = '' -content2 = '' -contentEN = '' -content2EN = '' - -# TODO: Add a JS Minifier python lib -with open('html/website.html', 'r') as r: - data = r.read() - data = data.replace('\n', '\\\n') - data = data.replace('\"', '\\"') - data = data.replace('\\d', '\\\d') - data = data.replace('\\.', '\\\.') - data = data.replace('\\^', '\\\\^') - data = data.replace('%;', '%%;') - content += data - -with open('src/websiteMgmt.h', 'w') as w: - w.write("static const char mgtWebsite[] PROGMEM = \"") - w.write(content) - w.write("\";") - -with open('html/website_EN.html', 'r') as ren: - data = ren.read().replace('\n', '\\\n') - data = data.replace('\"', '\\"') - data = data.replace('\\d', '\\\d') - data = data.replace('\\.', '\\\.') - data = data.replace('\\^', '\\\\^') - contentEN += data - -with open('src/websiteMgmt_EN.h', 'w') as wen: - wen.write("static const char mgtWebsite[] PROGMEM = \"") - wen.write(contentEN) - wen.write("\";") - -with open('html/websiteBasic.html', 'r') as r2: - data = r2.read().replace('\n', '\\\n') - data = data.replace('\"', '\\"') - content2 += data - -with open('src/websiteBasic.h', 'w') as w2: - w2.write("static const char basicWebsite[] PROGMEM = \"") - w2.write(content2) - w2.write("\";") - -with open('html/websiteBasic_EN.html', 'r') as r2en: - data = r2en.read().replace('\n', '\\\n') - data = data.replace('\"', '\\"') - content2EN += data - -with open('src/websiteBasic_EN.h', 'w') as w2en: - w2en.write("static const char basicWebsite[] PROGMEM = \"") - w2en.write(content2EN) - w2en.write("\";") - -r.close() -w.close() -r2.close() -w2.close() \ No newline at end of file +### +# Use this script for creating PROGMEM header files from html files. +# needs pip install requests +## +# html file base names +import requests +import argparse + +def str2bool(v): + if isinstance(v, bool): + return v + if v.lower() in ('yes', 'true', 't', 'y', '1'): + return True + elif v.lower() in ('no', 'false', 'f', 'n', '0'): + return False + else: + raise argparse.ArgumentTypeError('Boolean value expected.') + +HTML_FILES = ["management","management_EN", "accesspoint", "accesspoint_EN"] + +class htmlHeaderProcessor(object): + + """ + Returns a minified HTML string, uses html-minifier.com api. + """ + def minifyHTML(self, filename): + with open('html/' + filename + '.html', 'r') as r: + data = r.read() + return requests.post('https://html-minifier.com/raw', data=dict(input=data)).text.encode('utf8') + + def escape_html(self, data): + data = data.replace('\n', '\\\n') + data = data.replace('\"', '\\"') + data = data.replace('\\d', '\\\d') + data = data.replace('\\.', '\\\.') + data = data.replace('\\^', '\\\\^') + data = data.replace('%;', '%%;') + return data + + def html_to_c_header(self, filename): + content = "" + with open('html/' + filename + '.html', 'r') as r: + data = r.read() + content += self.escape_html(data) + return content + + + def write_header_file(self, filename, content): + with open('src/HTML' + filename + '.h', 'w') as w: + varname = filename.split('_')[0] + w.write("static const char " + varname + "_HTML[] PROGMEM = \"") + w.write(content) + w.write("\";") + + def main(self): + parser = argparse.ArgumentParser(description='Create c code PROGMEM header files from HTML files.') + parser.add_argument("--minify", type=str2bool, nargs='?', + const=True, default=False, + help="Minify HTML Code") + args = parser.parse_args() + + for file in HTML_FILES: + if args.minify: + + self.header_file_content = self.minifyHTML(file) + self.header_file_content = self.escape_html(self.header_file_content) + else: + self.header_file_content = self.html_to_c_header(file) + self.write_header_file(file, self.header_file_content) + +if __name__ == '__main__': + htmlHeaderProcessor().main() \ No newline at end of file diff --git a/src/websiteBasic.h b/src/HTMLaccesspoint.h similarity index 93% rename from src/websiteBasic.h rename to src/HTMLaccesspoint.h index 03548cb..8fe5b4a 100644 --- a/src/websiteBasic.h +++ b/src/HTMLaccesspoint.h @@ -1,10 +1,10 @@ -static const char basicWebsite[] PROGMEM = "\ +static const char accesspoint_HTML[] PROGMEM = "\ \ \ WLAN-Einrichtung\ \ +\ +\ +\ +
\ + \ +
\ +
\ +
\ +
\ +
\ +
\ + \ + \ +
\ + Bitte SSID des WLANs eintragen.\ +
\ + \ + \ + \ + \ +
\ +
\ +
\ + \ + \ +
\ +
\ +
\ +
\ +
\ +
\ +
\ + RFID-Zuweisungen\ +
\ +
\ + \ + \ + \ + \ +
\ +
\ +
\ +
\ + Dateiliste aktualisieren\ +
\ +
\ +
\ +
\ +


Der Prozess kann mehrere Minuten dauern...
\ +
\ +
\ +
\ +
\ + \ + \ +
\ +
\ +
\ + \ + \ +
\ +
\ +
\ +
\ +\ +
\ +
\ +
\ +
\ + RFID-Modifkationen\ +
\ +
\ + \ + \ +
\ + Bitte eine 12-stellige Zahl eingeben.\ +
\ + \ + \ +
\ +
\ +
\ + \ + \ +
\ +
\ +
\ +
\ +
\ +
\ +
\ +\ +
\ +
\ + \ + \ +
\ +
\ + \ + \ + \ + \ + \ + \ +
\ +
\ +
\ + \ + \ +
\ +
\ +
\ +
\ +
\ +
\ +\ +
\ +
\ + \ + \ + \ + \ +
\ +
\ +
\ + \ + \ +
\ +
\ +
\ +
\ +\ +
\ +
\ +\ +
\ +
\ +
\ + Lautstärke\ + \ +
\ +
\ +
\ + \ +
\ + \ +
\ +
\ + \ +
\ + \ +
\ +
\ +
\ +
\ +
\ +
\ + Neopixel (Helligkeit)\ + \ +
\ + \ + \ +
\ +\ + \ +
\ + \ +
\ +
\ +
\ +
\ +
\ +
\ + Deep Sleep\ +\ + \ +
\ +
\ +
\ +
\ +\ +
\ +
\ + Batterie\ +
Status über Neopixel anzeigen
\ +
\ + \ +
\ + \ +
\ +
\ + \ +
\ + \ +
\ +
\ + \ +\ +
\ + \ +
\ +\ +
\ + \ +
\ + \ +
\ +\ +
\ +
\ +
\ +
\ + \ + \ +
\ +
\ +
\ +
\ +
\ +
\ +

NVS-Importer

\ +
\ +
\ + \ + \ +
\ +
\ +
\ + \ +
\ +
\ +
\ +
\ +
\ +\ +\ +\ +"; \ No newline at end of file diff --git a/src/websiteMgmt_EN.h b/src/HTMLmanagement_EN.h similarity index 99% rename from src/websiteMgmt_EN.h rename to src/HTMLmanagement_EN.h index a46536a..469e09a 100644 --- a/src/websiteMgmt_EN.h +++ b/src/HTMLmanagement_EN.h @@ -1,4 +1,4 @@ -static const char mgtWebsite[] PROGMEM = "\ +static const char management_HTML[] PROGMEM = "\ \ \ ESPuino-configuration\ diff --git a/src/main.cpp b/src/main.cpp index 0e46e85..56ba5a0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,13 +31,13 @@ #if (LANGUAGE == 1) #include "logmessages.h" - #include "websiteMgmt.h" - #include "websiteBasic.h" + #include "HTMLmanagement.h" + #include "HTMLaccesspoint.h" #endif #if (LANGUAGE == 2) #include "logmessages_EN.h" - #include "websiteMgmt_EN.h" - #include "websiteBasic_EN.h" + #include "HTMLmanagement_EN.h" + #include "HTMLaccesspoint_EN.h" #endif #include @@ -46,7 +46,6 @@ #include - // Info-docs: // https://docs.aws.amazon.com/de_de/freertos-kernel/latest/dg/queue-management.html // https://arduino-esp8266.readthedocs.io/en/latest/PROGMEM.html#how-do-i-declare-a-global-flash-string-and-use-it @@ -2869,7 +2868,7 @@ void accessPointStart(const char *SSID, IPAddress ip, IPAddress netmask) { loggerNl(logBuf, LOGLEVEL_NOTICE); wServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ - request->send_P(200, "text/html", basicWebsite); + request->send_P(200, "text/html", accesspoint_HTML); }); wServer.on("/init", HTTP_POST, [] (AsyncWebServerRequest *request) { @@ -2881,7 +2880,7 @@ void accessPointStart(const char *SSID, IPAddress ip, IPAddress netmask) { prefsSettings.putString("Password", request->getParam("pwd", true)->value()); prefsSettings.putString("Hostname", request->getParam("hostname", true)->value()); } - request->send_P(200, "text/html", basicWebsite); + request->send_P(200, "text/html", accesspoint_HTML); }); wServer.on("/restart", HTTP_GET, [] (AsyncWebServerRequest *request) { @@ -3360,7 +3359,7 @@ void webserverStart(void) { wServer.addHandler(&events); wServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { - request->send_P(200, "text/html", mgtWebsite, templateProcessor); + request->send_P(200, "text/html", management_HTML, templateProcessor); }); wServer.on("/upload", HTTP_POST, [](AsyncWebServerRequest *request){ diff --git a/src/websiteMgmt.h b/src/websiteMgmt.h deleted file mode 100644 index 2c11616..0000000 --- a/src/websiteMgmt.h +++ /dev/null @@ -1,640 +0,0 @@ -static const char mgtWebsite[] PROGMEM = "\ -\ -\ - ESPuino-Konfiguration\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -\ -\ -\ -
\ -
\ -

WLAN-Konfiguration

\ -
\ -
\ - \ - \ -
\ - Bitte SSID des WLANs eintragen.\ -
\ - \ - \ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ -

RFID-Zuweisungen

\ -
\ -
\ - \ - \ - \ - \ -
\ -
\ -
\ -
\ - Dateiliste aktualisieren\ -
\ -
\ -
\ -
\ -


Der Prozess kann mehrere Minuten dauern...
\ -
\ -
\ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ -

RFID-Modifkationen

\ -
\ -
\ - \ - \ -
\ - Bitte eine 12-stellige Zahl eingeben.\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ -

MQTT-Konfiguration

\ -
\ -
\ - \ - \ -
\ -
\ - \ - \ - \ - \ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ -

FTP-Konfiguration

\ -
\ -
\ - \ - \ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ -

Allgemeine Konfiguration

\ -
\ -
\ - \ - \ - \ - \ - \ - \ -
\ -
\ - \ - \ - \ - \ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ -

NVS-Importer

\ -
\ -
\ - \ - \ -
\ - \ -
\ -
\ -
\ -\ -\ -\ -"; \ No newline at end of file