Browse Source

0.8.90

* added preprocessor defines to HTML (from platform.ini) to reduce the HTML in size if modules aren't enabled
* auto build minimal English versions of ESP8266 and ESP32
pull/1491/head
lumapu 11 months ago
parent
commit
e5c0e8e996
  1. 2
      .github/workflows/compile_development.yml
  2. 89
      scripts/convertHtml.py
  3. 39
      scripts/htmlPreprocessorDefines.py
  4. 4
      src/CHANGES.md
  5. 2
      src/defines.h
  6. 4
      src/platformio.ini
  7. 2
      src/web/html/includes/nav.html
  8. 113
      src/web/html/setup.html

2
.github/workflows/compile_development.yml

@ -24,9 +24,11 @@ jobs:
matrix: matrix:
variant: variant:
- esp8266 - esp8266
- esp8266-minimal
- esp8266-prometheus - esp8266-prometheus
- esp8285 - esp8285
- esp32-wroom32 - esp32-wroom32
- esp32-wroom32-minimal
- esp32-wroom32-prometheus - esp32-wroom32-prometheus
- esp32-wroom32-ethernet - esp32-wroom32-ethernet
- esp32-s2-mini - esp32-s2-mini

89
scripts/convertHtml.py

@ -7,8 +7,37 @@ import json
from datetime import date from datetime import date
from pathlib import Path from pathlib import Path
import subprocess import subprocess
import configparser
Import("env") Import("env")
import htmlPreprocessorDefines as prepro
def get_build_flags():
config = configparser.ConfigParser()
config.read('platformio.ini')
global build_flags
build_flags = config["env:" + env['PIOENV']]['build_flags'].split('\n')
for i in range(len(build_flags)):
build_flags[i] = build_flags[i][2:]
# translate board
board = config["env:" + env['PIOENV']]['board']
if board == "esp12e" or board == "esp8285":
build_flags.append("ESP8266")
elif board == "lolin_d32":
build_flags.append("ESP32")
elif board == "lolin_s2_mini":
build_flags.append("ESP32")
build_flags.append("ESP32-S2")
elif board == "lolin_c3_mini":
build_flags.append("ESP32")
build_flags.append("ESP32-C3")
elif board == "esp32-s3-devkitc-1":
build_flags.append("ESP32")
build_flags.append("ESP32-S3")
def get_git_sha(): def get_git_sha():
try: try:
@ -50,38 +79,46 @@ def readVersionFull(path):
return version return version
def htmlParts(file, header, nav, footer, versionPath, lang): def htmlParts(file, header, nav, footer, versionPath, lang):
p = "";
f = open(file, "r") f = open(file, "r")
lines = f.readlines() lines = f.readlines()
f.close(); f.close();
f = open(header, "r") f = open(header, "r")
h = f.read().strip() h = f.readlines()
f.close() f.close()
f = open(nav, "r") f = open(nav, "r")
n = f.read().strip() n = f.readlines()
f.close() f.close()
f = open(footer, "r") f = open(footer, "r")
fo = f.read().strip() fo = f.readlines()
f.close() f.close()
linesExt = []
for line in lines: for line in lines:
line = line.replace("{#HTML_HEADER}", h) if line.find("{#HTML_HEADER}") != -1:
line = line.replace("{#HTML_NAV}", n) linesExt.extend(h)
line = line.replace("{#HTML_FOOTER}", fo) elif line.find("{#HTML_NAV}") != -1:
p += line linesExt.extend(n)
elif line.find("{#HTML_FOOTER}") != -1:
linesExt.extend(fo)
else:
linesExt.append(line)
linesMod = prepro.conv(linesExt, build_flags)
#placeholders #placeholders
version = readVersion(versionPath); version = readVersion(versionPath);
link = '<a target="_blank" href="https://github.com/lumapu/ahoy/commits/' + get_git_sha() + '">GIT SHA: ' + get_git_sha() + ' :: ' + version + '</a>' link = '<a target="_blank" href="https://github.com/lumapu/ahoy/commits/' + get_git_sha() + '">GIT SHA: ' + get_git_sha() + ' :: ' + version + '</a>'
p = ""
for line in linesMod:
p += line
p = p.replace("{#VERSION}", version) p = p.replace("{#VERSION}", version)
p = p.replace("{#VERSION_FULL}", readVersionFull(versionPath)) p = p.replace("{#VERSION_FULL}", readVersionFull(versionPath))
p = p.replace("{#VERSION_GIT}", link) p = p.replace("{#VERSION_GIT}", link)
# remove if - endif ESP32
p = checkIf(p)
p = translate(file, p, lang) p = translate(file, p, lang)
p = translate("general", p, lang) # menu / header / footer p = translate("general", p, lang) # menu / header / footer
@ -90,30 +127,6 @@ def htmlParts(file, header, nav, footer, versionPath, lang):
f.close(); f.close();
return p return p
def checkIf(data):
if (env['PIOENV'][0:5] == "esp32") or env['PIOENV'][0:4] == "open":
data = data.replace("<!--IF_ESP32-->", "")
data = data.replace("<!--ENDIF_ESP32-->", "")
data = data.replace("/*IF_ESP32*/", "")
data = data.replace("/*ENDIF_ESP32*/", "")
else:
while 1:
start = data.find("<!--IF_ESP32-->")
end = data.find("<!--ENDIF_ESP32-->")+18
if -1 == start:
break
else:
data = data[0:start] + data[end:]
while 1:
start = data.find("/*IF_ESP32*/")
end = data.find("/*ENDIF_ESP32*/")+15
if -1 == start:
break
else:
data = data[0:start] + data[end:]
return data
def findLang(file): def findLang(file):
with open('../lang.json') as j: with open('../lang.json') as j:
lang = json.load(j) lang = json.load(j)
@ -189,6 +202,10 @@ def convert2Header(inFile, versionPath, lang):
f.write("#endif /*__{}_{}_H__*/\n".format(define, define2)) f.write("#endif /*__{}_{}_H__*/\n".format(define, define2))
f.close() f.close()
def main():
get_build_flags()
# delete all files in the 'h' dir # delete all files in the 'h' dir
wd = 'web/html/h' wd = 'web/html/h'
@ -216,6 +233,10 @@ lang = "en"
if env['PIOENV'][-3:] == "-de": if env['PIOENV'][-3:] == "-de":
lang = "de" lang = "de"
# go throw the array # go throw the array
for val in files_grabbed: for val in files_grabbed:
convert2Header(val, "../../defines.h", lang) convert2Header(val, "../../defines.h", lang)
main()

39
scripts/htmlPreprocessorDefines.py

@ -0,0 +1,39 @@
import re
import os
import queue
def error(msg):
print("ERROR: " + msg)
exit()
def check(inp, lst, pattern):
q = queue.LifoQueue()
out = []
keep = True
for line in inp:
x = re.findall(pattern, line)
if len(x) > 0:
if line.find("ENDIF_") != -1:
if q.empty():
error("missing open statement!")
if q.get() != x[0]:
error("wrong close statement!")
keep = True
elif line.find("IF_") != -1:
q.put(x[0])
if keep is True:
keep = x[0] in lst
elif line.find("E") != -1:
if q.empty():
error("missing open statement!")
keep = not keep
else:
if keep is True:
out.append(line)
return out
def conv(inp, lst):
print(lst)
out = check(inp, lst, r'\/\*(?:IF_|ELS|ENDIF_)([A-Z0-9\-_]+)?\*\/')
return check(out, lst, r'\<\!\-\-(?:IF_|ELS|ENDIF_)([A-Z0-9\-_]+)?\-\-\>')

4
src/CHANGES.md

@ -1,5 +1,9 @@
# Development Changes # Development Changes
## 0.8.90 - 2024-03-05
* added preprocessor defines to HTML (from platform.ini) to reduce the HTML in size if modules aren't enabled
* auto build minimal English versions of ESP8266 and ESP32
## 0.8.89 - 2024-03-02 ## 0.8.89 - 2024-03-02
* merge PR: Collection of small fixes #1465 * merge PR: Collection of small fixes #1465
* fix: show esp type on `/history` #1463 * fix: show esp type on `/history` #1463

2
src/defines.h

@ -13,7 +13,7 @@
//------------------------------------- //-------------------------------------
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 8 #define VERSION_MINOR 8
#define VERSION_PATCH 89 #define VERSION_PATCH 90
//------------------------------------- //-------------------------------------
typedef struct { typedef struct {

4
src/platformio.ini

@ -191,7 +191,7 @@ monitor_filters =
[env:esp32-wroom32-ethernet] [env:esp32-wroom32-ethernet]
platform = espressif32 platform = espressif32
board = esp32dev board = lolin_d32
lib_deps = lib_deps =
khoih-prog/AsyncWebServer_ESP32_W5500 khoih-prog/AsyncWebServer_ESP32_W5500
khoih-prog/AsyncUDP_ESP32_W5500 khoih-prog/AsyncUDP_ESP32_W5500
@ -214,7 +214,7 @@ monitor_filters =
[env:esp32-wroom32-ethernet-de] [env:esp32-wroom32-ethernet-de]
platform = espressif32 platform = espressif32
board = esp32dev board = lolin_d32
lib_deps = lib_deps =
khoih-prog/AsyncWebServer_ESP32_W5500 khoih-prog/AsyncWebServer_ESP32_W5500
khoih-prog/AsyncUDP_ESP32_W5500 khoih-prog/AsyncUDP_ESP32_W5500

2
src/web/html/includes/nav.html

@ -7,7 +7,9 @@
</a> </a>
<div id="topnav" class="mobile"> <div id="topnav" class="mobile">
<a id="nav3" class="hide" href="/live?v={#VERSION}">{#NAV_LIVE}</a> <a id="nav3" class="hide" href="/live?v={#VERSION}">{#NAV_LIVE}</a>
<!--IF_ENABLE_HISTORY-->
<a id="nav11" class="acitve" href="/history?v={#VERSION}">{#NAV_HISTORY}</a> <a id="nav11" class="acitve" href="/history?v={#VERSION}">{#NAV_HISTORY}</a>
<!--ENDIF_ENABLE_HISTORY-->
<a id="nav4" class="hide" href="/serial?v={#VERSION}">{#NAV_WEBSERIAL}</a> <a id="nav4" class="hide" href="/serial?v={#VERSION}">{#NAV_WEBSERIAL}</a>
<a id="nav5" class="hide" href="/setup?v={#VERSION}">{#NAV_SETTINGS}</a> <a id="nav5" class="hide" href="/setup?v={#VERSION}">{#NAV_SETTINGS}</a>
<span class="separator"></span> <span class="separator"></span>

113
src/web/html/setup.html

@ -272,7 +272,7 @@
<!--ENDIF_ESP32--> <!--ENDIF_ESP32-->
</fieldset> </fieldset>
</div> </div>
<!--IF_PLUGIN_DISPLAY-->
<button type="button" class="s_collapsible">{#DISPLAY_CONFIG}</button> <button type="button" class="s_collapsible">{#DISPLAY_CONFIG}</button>
<div class="s_content"> <div class="s_content">
<fieldset class="mb-4"> <fieldset class="mb-4">
@ -301,6 +301,7 @@
</div> </div>
</fieldset> </fieldset>
</div> </div>
<!--ENDIF_PLUGIN_DISPLAY-->
<div class="row mb-4 mt-4"> <div class="row mb-4 mt-4">
<div class="col-8 col-sm-3">{#BTN_REBOOT_SUCCESSFUL_SAVE}</div> <div class="col-8 col-sm-3">{#BTN_REBOOT_SUCCESSFUL_SAVE}</div>
@ -341,6 +342,7 @@
var maxInv = 0; var maxInv = 0;
var ts = 0; var ts = 0;
/*IF_ESP8266*/
var esp8266pins = [ var esp8266pins = [
[255, "{#PIN_OFF}"], [255, "{#PIN_OFF}"],
[0, "D3 (GPIO0)"], [0, "D3 (GPIO0)"],
@ -361,6 +363,7 @@
[15, "D8 (GPIO15)"], [15, "D8 (GPIO15)"],
[16, "D0 (GPIO16 - {#PIN_NO_IRQ})"] [16, "D0 (GPIO16 - {#PIN_NO_IRQ})"]
]; ];
/*ENDIF_ESP8266*/
/*IF_ESP32*/ /*IF_ESP32*/
var esp32pins = [ var esp32pins = [
@ -392,6 +395,7 @@
[36, "VP (GPIO36, {#PIN_INPUT_ONLY})"], [36, "VP (GPIO36, {#PIN_INPUT_ONLY})"],
[39, "VN (GPIO39, {#PIN_INPUT_ONLY})"] [39, "VN (GPIO39, {#PIN_INPUT_ONLY})"]
]; ];
/*IF_ESP32-S2*/
var esp32sXpins = [ var esp32sXpins = [
[255, "off / default"], [255, "off / default"],
[0, "GPIO0 ({#PIN_DONT_USE} - BOOT)"], [0, "GPIO0 ({#PIN_DONT_USE} - BOOT)"],
@ -440,6 +444,58 @@
[47, "GPIO47"], [47, "GPIO47"],
[48, "GPIO48"], [48, "GPIO48"],
]; ];
/*ENDIF_ESP32-S2*/
/*IF_ESP32-S3*/
var esp32sXpins = [
[255, "off / default"],
[0, "GPIO0 ({#PIN_DONT_USE} - BOOT)"],
[1, "GPIO1"],
[2, "GPIO2"],
[3, "GPIO3"],
[4, "GPIO4"],
[5, "GPIO5"],
[6, "GPIO6"],
[7, "GPIO7"],
[8, "GPIO8"],
[9, "GPIO9"],
[10, "GPIO10"],
[11, "GPIO11"],
[12, "GPIO12"],
[13, "GPIO13"],
[14, "GPIO14"],
[15, "GPIO15"],
[16, "GPIO16"],
[17, "GPIO17"],
[18, "GPIO18"],
[19, "GPIO19 ({#PIN_DONT_USE} - USB-)"],
[20, "GPIO20 ({#PIN_DONT_USE} - USB+)"],
[21, "GPIO21"],
[26, "GPIO26 (PSRAM - {#PIN_NOT_AVAIL})"],
[27, "GPIO27 (FLASH - {#PIN_NOT_AVAIL})"],
[28, "GPIO28 (FLASH - {#PIN_NOT_AVAIL})"],
[29, "GPIO29 (FLASH - {#PIN_NOT_AVAIL})"],
[30, "GPIO30 (FLASH - {#PIN_NOT_AVAIL})"],
[31, "GPIO31 (FLASH - {#PIN_NOT_AVAIL})"],
[32, "GPIO32 (FLASH - {#PIN_NOT_AVAIL})"],
[33, "GPIO33 (not exposed on S3-WROOM modules)"],
[34, "GPIO34 (not exposed on S3-WROOM modules)"],
[35, "GPIO35"],
[36, "GPIO36"],
[37, "GPIO37"],
[38, "GPIO38"],
[39, "GPIO39"],
[40, "GPIO40"],
[41, "GPIO41"],
[42, "GPIO42"],
[43, "GPIO43"],
[44, "GPIO44"],
[45, "GPIO45 ({#PIN_DONT_USE} - STRAPPING PIN)"],
[46, "GPIO46 ({#PIN_DONT_USE} - STRAPPING PIN)"],
[47, "GPIO47"],
[48, "GPIO48"],
];
/*ENDIF_ESP32-S3*/
/*IF_ESP32-C3*/
var esp32c3pins = [ var esp32c3pins = [
[255, "off / default"], [255, "off / default"],
[0, "GPIO0"], [0, "GPIO0"],
@ -465,6 +521,7 @@
[20, "GPIO20 (RX)"], [20, "GPIO20 (RX)"],
[21, "GPIO21 (TX)"], [21, "GPIO21 (TX)"],
]; ];
/*ENDIF_ESP32-C3*/
/*ENDIF_ESP32*/ /*ENDIF_ESP32*/
var nrfPa = [ var nrfPa = [
[0, "MIN ({#PIN_RECOMMENDED})"], [0, "MIN ({#PIN_RECOMMENDED})"],
@ -890,11 +947,19 @@
function parsePinout(obj, type, system) { function parsePinout(obj, type, system) {
var e = document.getElementById("pinout"); var e = document.getElementById("pinout");
var pinList = esp8266pins;
/*IF_ESP32*/ /*IF_ESP32*/
var pinList = esp32pins; var pinList = esp32pins;
if ("ESP32-S3" == system.chip_model || "ESP32-S2" == system.chip_model) pinList = esp32sXpins; /*IF_ESP32-S2*/
else if("ESP32-C3" == system["chip_model"]) pinList = esp32c3pins; pinList = esp32sXpins;
/*ENDIF_ESP32-S2*/
/*IF_ESP32-S3*/
pinList = esp32sXpins;
/*ENDIF_ESP32-S3*/
/*IF_ESP32-C3*/
pinList = esp32c3pins;
/*ENDIF_ESP32-C3*/
/*ELSE*/
var pinList = esp8266pins;
/*ENDIF_ESP32*/ /*ENDIF_ESP32*/
pins = [['led0', 'pinLed0', '{#LED_AT_LEAST_ONE_PRODUCING}'], ['led1', 'pinLed1', '{#LED_MQTT_CONNECTED}'], ['led2', 'pinLed2', '{#LED_NIGHT_TIME}']]; pins = [['led0', 'pinLed0', '{#LED_AT_LEAST_ONE_PRODUCING}'], ['led1', 'pinLed1', '{#LED_MQTT_CONNECTED}'], ['led2', 'pinLed2', '{#LED_NIGHT_TIME}']];
for(p of pins) { for(p of pins) {
@ -926,11 +991,19 @@
var en = inp("nrfEnable", null, null, ["cb"], "nrfEnable", "checkbox"); var en = inp("nrfEnable", null, null, ["cb"], "nrfEnable", "checkbox");
en.checked = obj["en"]; en.checked = obj["en"];
var pinList = esp8266pins;
/*IF_ESP32*/ /*IF_ESP32*/
var pinList = esp32pins; var pinList = esp32pins;
if ("ESP32-S3" == system.chip_model || "ESP32-S2" == system.chip_model) pinList = esp32sXpins; /*IF_ESP32-S2*/
else if("ESP32-C3" == system["chip_model"]) pinList = esp32c3pins; pinList = esp32sXpins;
/*ENDIF_ESP32-S2*/
/*IF_ESP32-S3*/
pinList = esp32sXpins;
/*ENDIF_ESP32-S3*/
/*IF_ESP32-C3*/
pinList = esp32c3pins;
/*ENDIF_ESP32-C3*/
/*ELSE*/
var pinList = esp8266pins;
/*ENDIF_ESP32*/ /*ENDIF_ESP32*/
e.replaceChildren ( e.replaceChildren (
@ -962,8 +1035,15 @@
var e = document.getElementById("cmt"); var e = document.getElementById("cmt");
var en = inp("cmtEnable", null, null, ["cb"], "cmtEnable", "checkbox"); var en = inp("cmtEnable", null, null, ["cb"], "cmtEnable", "checkbox");
var pinList = esp32pins; var pinList = esp32pins;
if ("ESP32-S3" == system.chip_model || "ESP32-S2" == system.chip_model) pinList = esp32sXpins; /*IF_ESP32-S2*/
else if("ESP32-C3" == system["chip_model"]) pinList = esp32c3pins; pinList = esp32sXpins;
/*ENDIF_ESP32-S2*/
/*IF_ESP32-S3*/
pinList = esp32sXpins;
/*ENDIF_ESP32-S3*/
/*IF_ESP32-C3*/
pinList = esp32c3pins;
/*ENDIF_ESP32-C3*/
en.checked = obj["en"]; en.checked = obj["en"];
@ -1008,12 +1088,20 @@
} }
} }
/*IF_PLUGIN_DISPLAY*/
function parseDisplay(obj, type, system) { function parseDisplay(obj, type, system) {
var pinList = esp8266pins; var pinList = esp8266pins;
/*IF_ESP32*/ /*IF_ESP32*/
var pinList = esp32pins; var pinList = esp32pins;
if ("ESP32-S3" == system.chip_model || "ESP32-S2" == system.chip_model) pinList = esp32sXpins; /*IF_ESP32-S2*/
else if("ESP32-C3" == system["chip_model"]) pinList = esp32c3pins; pinList = esp32sXpins;
/*ENDIF_ESP32-S2*/
/*IF_ESP32-S3*/
pinList = esp32sXpins;
/*ENDIF_ESP32-S3*/
/*IF_ESP32-C3*/
pinList = esp32c3pins;
/*ENDIF_ESP32-C3*/
/*ENDIF_ESP32*/ /*ENDIF_ESP32*/
for(var i of ["disp_pwr"]) for(var i of ["disp_pwr"])
@ -1149,6 +1237,7 @@
setHide("screenSaver", !optionsMap.get(dispType)[2]); setHide("screenSaver", !optionsMap.get(dispType)[2]);
setHide("pirPin", !(optionsMap.get(dispType)[2] && (screenSaver==2))); // show pir pin only for motion screensaver setHide("pirPin", !(optionsMap.get(dispType)[2] && (screenSaver==2))); // show pir pin only for motion screensaver
} }
/*ENDIF_PLUGIN_DISPLAY*/
function tick() { function tick() {
document.getElementById("date").innerHTML = toIsoDateStr((new Date((++ts) * 1000))); document.getElementById("date").innerHTML = toIsoDateStr((new Date((++ts) * 1000)));
@ -1168,7 +1257,9 @@
parseCmtRadio(root["radioCmt"], root["system"]["esp_type"], root["system"]); parseCmtRadio(root["radioCmt"], root["system"]["esp_type"], root["system"]);
/*ENDIF_ESP32*/ /*ENDIF_ESP32*/
parseSerial(root["serial"]); parseSerial(root["serial"]);
/*IF_PLUGIN_DISPLAY*/
parseDisplay(root["display"], root["system"]["esp_type"], root["system"]); parseDisplay(root["display"], root["system"]["esp_type"], root["system"]);
/*ENDIF_PLUGIN_DISPLAY*/
getAjax("/api/inverter/list", parseIv); getAjax("/api/inverter/list", parseIv);
} }
} }

Loading…
Cancel
Save