From 9ce03e0da1ee762c3852c25f5f937c9da5c84bd4 Mon Sep 17 00:00:00 2001 From: Mario Lukas Date: Wed, 9 Dec 2020 12:32:39 +0100 Subject: [PATCH 1/4] feat (MDNS): added option for using mdns - enabeled mdns can be uses for raching the tonuino over .local --- src/main.cpp | 12 ++++++++++++ src/settings.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index b5e2d85..0e46e85 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,10 @@ #include #endif +#ifdef MDNS_ENABLE + #include +#endif + #if (LANGUAGE == 1) #include "logmessages.h" #include "websiteMgmt.h" @@ -2987,6 +2991,14 @@ wl_status_t wifiManager(void) { } else { // Starts AP if WiFi-connect wasn't successful accessPointStart((char *) FPSTR(accessPointNetworkSSID), apIP, apNetmask); } + + #ifdef MDNS_ENABLE + // zero conf, make device available as .local + if (MDNS.begin(hostname.c_str())) { + MDNS.addService("http", "tcp", 80); + } + #endif + wifiNeedsRestart = false; } diff --git a/src/settings.h b/src/settings.h index 95ffa90..38430d0 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,6 +1,7 @@ #include "Arduino.h" //########################## MODULES ################################# +//#define MDNS_ENABLE #define MQTT_ENABLE // Make sure to configure mqtt-server and (optionally) username+pwd #define FTP_ENABLE // Enables FTP-server #define NEOPIXEL_ENABLE // Don't forget configuration of NUM_LEDS if enabled From 1aaa906fe8eeb948dcdb1aaa23853845c46af958 Mon Sep 17 00:00:00 2001 From: Mario Lukas Date: Wed, 9 Dec 2020 19:24:05 +0100 Subject: [PATCH 2/4] 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 From c9fd37f0a02a4945a4df176283a0709132a98411 Mon Sep 17 00:00:00 2001 From: Mario Lukas Date: Wed, 9 Dec 2020 20:35:23 +0100 Subject: [PATCH 3/4] fix (HTML): fixed assignment of default slider values --- html/management.html | 33 ++++++++++++++++++--------------- src/HTMLmanagement.h | 35 +++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/html/management.html b/html/management.html index 7c616ed..c89c996 100644 --- a/html/management.html +++ b/html/management.html @@ -29,7 +29,11 @@ margin-right: 1em; } - + .slider-handle{ + height: 30px; + width: 30px; + top: -5px; + } legend.scheduler-border { width:inherit; /* Or auto */ @@ -291,18 +295,18 @@
+ data-slider-value="%INIT_VOLUME%" value="%INIT_VOLUME%" required>
+ data-slider-value="%MAX_VOLUME_SPEAKER%" value="%MAX_VOLUME_SPEAKER%" required>

+ data-slider-value="%MAX_VOLUME_HEADPHONE%" value="%MAX_VOLUME_HEADPHONE%" required>
@@ -314,13 +318,12 @@
+ data-slider-value="%INIT_LED_BRIGHTNESS%" value="%INIT_LED_BRIGHTNESS%" required>
- +
@@ -331,7 +334,7 @@
+ data-slider-value="%MAX_INACTIVITY%" value="%MAX_INACTIVITY%" required>
@@ -345,28 +348,28 @@
+ data-slider-value="%WARNING_LOW_VOLTAGE%" value="%WARNING_LOW_VOLTAGE%" pattern="^\d{1,2}(\.\d{1,3})?" required>

- +

- +

- +
diff --git a/src/HTMLmanagement.h b/src/HTMLmanagement.h index 7cc71af..b1e06ff 100644 --- a/src/HTMLmanagement.h +++ b/src/HTMLmanagement.h @@ -27,7 +27,14 @@ static const char management_HTML[] PROGMEM = "\ width: 60%%;\ margin-left: 1em;\ margin-right: 1em;\ +\ + }\ + .slider-handle{\ + height: 30px;\ + width: 30px;\ + top: -5px;\ }\ + \ legend.scheduler-border {\ width:inherit; /* Or auto */\ padding:0 10px; /* To give a bit of padding on the left and right */\ @@ -288,18 +295,18 @@ static const char management_HTML[] PROGMEM = "\ \
\
\ + data-slider-value=\"%INIT_VOLUME%\" value=\"%INIT_VOLUME%\" required> \
\ \
\ \ + data-slider-value=\"%MAX_VOLUME_SPEAKER%\" value=\"%MAX_VOLUME_SPEAKER%\" required> \
\
\ \
\ \ + data-slider-value=\"%MAX_VOLUME_HEADPHONE%\" value=\"%MAX_VOLUME_HEADPHONE%\" required> \
\ \ \ @@ -311,13 +318,12 @@ static const char management_HTML[] PROGMEM = "\
\ \ \ + data-slider-value=\"%INIT_LED_BRIGHTNESS%\" value=\"%INIT_LED_BRIGHTNESS%\" required>\
\ \ \
\ - \ + \
\ \ \ @@ -328,7 +334,7 @@ static const char management_HTML[] PROGMEM = "\ \ \
\ + data-slider-value=\"%MAX_INACTIVITY%\" value=\"%MAX_INACTIVITY%\" required>\ \ \
\ @@ -342,28 +348,28 @@ static const char management_HTML[] PROGMEM = "\ \
\ \ + data-slider-value=\"%WARNING_LOW_VOLTAGE%\" value=\"%WARNING_LOW_VOLTAGE%\" pattern=\"^\\d{1,2}(\\.\\d{1,3})?\" required> \
\
\ \
\ - \ + \
\
\ \ \
\ - \ + \
\ \
\ \
\ - \ + \
\ \ \ @@ -714,6 +720,7 @@ static const char management_HTML[] PROGMEM = "\ $(function () {\ $('[data-toggle=\"tooltip\"]').tooltip();\ });\ +\ });\ \ \ From 624ab2f837a82bd648db039afe2de80595986e15 Mon Sep 17 00:00:00 2001 From: Mario Lukas Date: Wed, 9 Dec 2020 20:37:34 +0100 Subject: [PATCH 4/4] chore (pio): reverted to default paltformio config file --- platformio.ini | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7771b77..b8911b9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,17 +9,17 @@ ; https://docs.platformio.org/page/projectconf.html ;[env:nodemcu-32s] -[env:az-delivery-devkit-v4] +[env:lolin32] platform = espressif32 -board = az-delivery-devkit-v4 +;board = nodemcu-32s +board = lolin32 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