From f73ce60468757bc3fbdb2c8dcfae4fd3e336ec1f Mon Sep 17 00:00:00 2001 From: Nic Limper Date: Thu, 25 May 2023 09:22:48 +0200 Subject: [PATCH] apconfig improvements --- ESP32_AP-Flasher/data/www/index.html | 61 +++++++++++++++++++------ ESP32_AP-Flasher/data/www/main.css | 28 ++++++------ ESP32_AP-Flasher/data/www/main.js | 16 +++++-- ESP32_AP-Flasher/include/settings.h | 7 --- ESP32_AP-Flasher/include/tag_db.h | 10 ++++ ESP32_AP-Flasher/platformio.ini | 5 +- ESP32_AP-Flasher/src/contentmanager.cpp | 10 ++-- ESP32_AP-Flasher/src/language.cpp | 2 +- ESP32_AP-Flasher/src/leds.cpp | 4 +- ESP32_AP-Flasher/src/newproto.cpp | 14 +++--- ESP32_AP-Flasher/src/tag_db.cpp | 30 +++++++----- ESP32_AP-Flasher/src/udp.cpp | 8 ++-- ESP32_AP-Flasher/src/web.cpp | 29 ++++++++---- 13 files changed, 149 insertions(+), 75 deletions(-) diff --git a/ESP32_AP-Flasher/data/www/index.html b/ESP32_AP-Flasher/data/www/index.html index bdc9a5a6..c659869c 100644 --- a/ESP32_AP-Flasher/data/www/index.html +++ b/ESP32_AP-Flasher/data/www/index.html @@ -38,7 +38,7 @@
-

Access Point config

+

Access Point config

@@ -56,7 +56,7 @@

- +

- +

+

+ + +

+

+ + +

-

Active access points:
@@ -102,12 +112,35 @@

reboot AP download tagDB +

Github OpenEPaperLink

+
+
+

Firmware updates

+

+ test +

+

+ +

+ +
+
diff --git a/ESP32_AP-Flasher/data/www/main.css b/ESP32_AP-Flasher/data/www/main.css index d92c886e..ef22168f 100644 --- a/ESP32_AP-Flasher/data/www/main.css +++ b/ESP32_AP-Flasher/data/www/main.css @@ -29,8 +29,10 @@ header { } label { - width:100px; + width: 120px; display: inline-block; + vertical-align: top; + padding: 3px 0px; } .logo { @@ -62,7 +64,7 @@ label { gap: 20px; } -#rebootbutton, #downloadDBbutton, #apconfigbutton, .filebutton { +#rebootbutton, #updatebutton, #downloadDBbutton, #apconfigbutton, .filebutton { padding: 2px 5px; background-color: #cccccc; text-decoration: none; @@ -85,7 +87,7 @@ button { } input { - border: solid 1px #666666; + border: solid 1px #cccccc; padding: 4px; border-radius: 0px; } @@ -102,11 +104,12 @@ button:hover { } select { - padding: 4px; + padding: 3px 4px; border-radius: 0px; + border: solid 1px #cccccc; } -#configbox, #apconfigbox { +#configbox, #apconfigbox, #apupdatebox { display: none; position: fixed; top: 80px; @@ -118,22 +121,17 @@ select { box-shadow: 7px 10px 52px -19px rgba(0, 0, 0, 0.63); } -#configbox p, #apconfigbox p { +#configbox p, #apconfigbox p, #apupdatebox p { padding: 5px; } -#configbox h3, #apconfigbox h3 { +#configbox h3, #apconfigbox h3, #apupdatebox h3 { font-size: 1.5em; font-weight: bold; } #configbox input, #apconfigbox input { - border: solid 1px #666666; - /*padding: 4px;*/ -} - -#configbox label, #apconfigbox label { - text-transform: capitalize; + border: solid 1px #cccccc; } #configbox input[type=number] { @@ -169,6 +167,10 @@ select { text-align: right; } +#apupdatebox { + background-color: #f0e0d0; +} + #cfgdelete { position: absolute; bottom: 15px; diff --git a/ESP32_AP-Flasher/data/www/main.js b/ESP32_AP-Flasher/data/www/main.js index 9397b855..25662212 100644 --- a/ESP32_AP-Flasher/data/www/main.js +++ b/ESP32_AP-Flasher/data/www/main.js @@ -346,23 +346,27 @@ $('#apconfigbutton').onclick = function () { for (var i = rowCount - 1; i > 0; i--) { table.deleteRow(i); } - $('#apconfigbox').style.display = 'block' fetch("/get_ap_list") .then(response => response.json()) .then(data => { $('#apcfgalias').value = data.alias; $('#apcfgchid').value = data.channel; - $("#apcfgledbrightness").value = data.ledbrightness; + $("#apcfgledbrightness").value = data.led; $("#apcfglanguage").value = data.language; + $("#apclatency").value = data.maxsleep; + $("#apcpreventsleep").value = data.stopsleep; }) + $('#apconfigbox').style.display = 'block' } $('#apcfgsave').onclick = function () { let formData = new FormData(); formData.append("alias", $('#apcfgalias').value); formData.append("channel", $('#apcfgchid').value); - formData.append('ledbrightness', $('#apcfgledbrightness').value); + formData.append('led', $('#apcfgledbrightness').value); formData.append('language', $('#apcfglanguage').value); + formData.append('maxsleep', $('#apclatency').value); + formData.append('stopsleep', $('#apcpreventsleep').value); fetch("/save_apcfg", { method: "POST", body: formData @@ -374,6 +378,12 @@ $('#apcfgsave').onclick = function () { $('#apconfigbox').style.display = 'none'; } +$('#updatebutton').onclick = function () { + $('#apconfigbox').style.display = 'none'; + $('#apupdatebox').style.display = 'block'; + //https://api.github.com/repos/jjwbruijn/OpenEPaperLink/commits +} + $('#paintbutton').onclick = function () { if (paintShow) { paintShow = false; diff --git a/ESP32_AP-Flasher/include/settings.h b/ESP32_AP-Flasher/include/settings.h index 947683f7..6ca8b425 100644 --- a/ESP32_AP-Flasher/include/settings.h +++ b/ESP32_AP-Flasher/include/settings.h @@ -6,13 +6,6 @@ #define FLASHER_ALTRADIO_PORT 2 #endif -// how long the we should keep the transfer metadata -#define PENDING_TIMEOUT 24 * 3600 -// this determines how long images will be cached; -#define PENDING_DATA_TIMEOUT 60 -// maximum time (in minutes) that a tag is put to sleep if no update is expected. -#define MIN_RESPONSE_TIME 10 - // Which port we should use for the AP process // (useful for testing, can only be FLASHER_AP_PORT for any other board than the OpenEPaperLinkPCB board) #define AP_PROCESS_PORT FLASHER_AP_PORT diff --git a/ESP32_AP-Flasher/include/tag_db.h b/ESP32_AP-Flasher/include/tag_db.h index 652eb34a..3ce6c409 100644 --- a/ESP32_AP-Flasher/include/tag_db.h +++ b/ESP32_AP-Flasher/include/tag_db.h @@ -44,6 +44,16 @@ class tagRecord { static tagRecord* findByMAC(uint8_t mac[8]); }; +struct Config { + uint8_t channel; + char alias[32]; + int16_t led; + uint8_t language; + uint8_t maxsleep; + uint8_t stopsleep; +}; + +extern Config config; extern std::vector tagDB; extern DynamicJsonDocument APconfig; String tagDBtoJson(uint8_t mac[8] = nullptr, uint8_t startPos = 0); diff --git a/ESP32_AP-Flasher/platformio.ini b/ESP32_AP-Flasher/platformio.ini index e7d172f8..d0c54f8d 100644 --- a/ESP32_AP-Flasher/platformio.ini +++ b/ESP32_AP-Flasher/platformio.ini @@ -29,6 +29,9 @@ board_build.f_cpu = 240000000L ;upload_port = COM30 ;monitor_port = COM30 +build_flags = + -D BUILD_ENV_NAME=$PIOENV + -D BUILD_TIME=$UNIX_TIME [env:OpenEPaperLink_Mini_AP] platform = https://github.com/platformio/platform-espressif32.git @@ -137,7 +140,7 @@ board = esp32dev board_build.partitions = default.csv build_flags = - -DCORE_DEBUG_LEVEL=0 + -D CORE_DEBUG_LEVEL=0 -D SIMPLE_AP -D FLASHER_AP_SS=5 diff --git a/ESP32_AP-Flasher/src/contentmanager.cpp b/ESP32_AP-Flasher/src/contentmanager.cpp index a21ad7ef..452f7e89 100644 --- a/ESP32_AP-Flasher/src/contentmanager.cpp +++ b/ESP32_AP-Flasher/src/contentmanager.cpp @@ -56,8 +56,8 @@ void contentRunner() { if (taginfo->expectedNextCheckin > now - 10 && taginfo->expectedNextCheckin < now + 30 && taginfo->pendingIdle == 0 && taginfo->pending == false) { uint16_t minutesUntilNextUpdate = 0; minutesUntilNextUpdate = (taginfo->nextupdate - now) / 60; - if (minutesUntilNextUpdate > MIN_RESPONSE_TIME) minutesUntilNextUpdate = MIN_RESPONSE_TIME; - if (minutesUntilNextUpdate > 1 && wsClientCount() == 0) { + if (minutesUntilNextUpdate > config.maxsleep) minutesUntilNextUpdate = config.maxsleep; + if (minutesUntilNextUpdate > 1 && (wsClientCount() == 0 || config.stopsleep == 0)) { taginfo->pendingIdle = minutesUntilNextUpdate; if (taginfo->isExternal == false) prepareIdleReq(taginfo->mac, minutesUntilNextUpdate); } @@ -301,7 +301,11 @@ void drawDate(String &filename, tagRecord *&taginfo, imgParam &imageParams) { if (taginfo->hwType == SOLUM_29_SSD1619 || taginfo->hwType == SOLUM_29_UC8151) { initSprite(spr, 296, 128); - drawString(spr, languageDays[getCurrentLanguage()][timeinfo.tm_wday], 296 / 2, 10, "fonts/calibrib62", TC_DATUM, PAL_RED); + if (getCurrentLanguage() == 0 && timeinfo.tm_wday == 3) { + drawString(spr, languageDays[getCurrentLanguage()][timeinfo.tm_wday], 296 / 2, 10, "fonts/calibrib50", TC_DATUM, PAL_RED); + } else { + drawString(spr, languageDays[getCurrentLanguage()][timeinfo.tm_wday], 296 / 2, 10, "fonts/calibrib62", TC_DATUM, PAL_RED); + } drawString(spr, String(timeinfo.tm_mday) + " " + languageMonth[getCurrentLanguage()][timeinfo.tm_mon], 296 / 2, 73, "fonts/calibrib50", TC_DATUM); } else if (taginfo->hwType == SOLUM_154_SSD1619) { diff --git a/ESP32_AP-Flasher/src/language.cpp b/ESP32_AP-Flasher/src/language.cpp index 3d2b997a..e639c2cf 100644 --- a/ESP32_AP-Flasher/src/language.cpp +++ b/ESP32_AP-Flasher/src/language.cpp @@ -8,7 +8,7 @@ int currentLanguage = defaultLanguage; void updateLanguageFromConfig() { - int tempLang = APconfig["language"].as(); + int tempLang = config.language; if (tempLang < 0 || tempLang >= sizeof(languageList)) { Serial.println("Language not supported"); return; diff --git a/ESP32_AP-Flasher/src/leds.cpp b/ESP32_AP-Flasher/src/leds.cpp index 158a2866..3032a5fa 100644 --- a/ESP32_AP-Flasher/src/leds.cpp +++ b/ESP32_AP-Flasher/src/leds.cpp @@ -172,8 +172,8 @@ void setBrightness(int brightness) { } void updateBrightnessFromConfig() { - if (APconfig["ledbrightness"].as() != 0) { - int newbrightness = APconfig["ledbrightness"].as(); + if (config.led != 0) { + int newbrightness = config.led; if (newbrightness < 0) newbrightness = 0; if (newbrightness != maxledbrightness) { setBrightness(newbrightness); diff --git a/ESP32_AP-Flasher/src/newproto.cpp b/ESP32_AP-Flasher/src/newproto.cpp index 71d98155..4bbfd12d 100644 --- a/ESP32_AP-Flasher/src/newproto.cpp +++ b/ESP32_AP-Flasher/src/newproto.cpp @@ -64,13 +64,13 @@ void prepareCancelPending(uint8_t dst[8]) { } void prepareIdleReq(uint8_t* dst, uint16_t nextCheckin) { - if (nextCheckin > MIN_RESPONSE_TIME) nextCheckin = MIN_RESPONSE_TIME; + if (nextCheckin > config.maxsleep) nextCheckin = config.maxsleep; if (nextCheckin > 0) { struct pendingData pending = {0}; memcpy(pending.targetMac, dst, 8); pending.availdatainfo.dataType = DATATYPE_NOUPDATE; pending.availdatainfo.nextCheckIn = nextCheckin; - pending.attemptsLeft = 10 + MIN_RESPONSE_TIME; + pending.attemptsLeft = 10 + config.maxsleep; char buffer[64]; sprintf(buffer, ">SDA %02X%02X%02X%02X%02X%02X%02X%02X NOP\n", dst[7], dst[6], dst[5], dst[4], dst[3], dst[2], dst[1], dst[0]); @@ -127,8 +127,8 @@ void prepareNFCReq(uint8_t* dst, const char* url) { } bool prepareDataAvail(String* filename, uint8_t dataType, uint8_t* dst, uint16_t nextCheckin) { - if (nextCheckin > MIN_RESPONSE_TIME) nextCheckin = MIN_RESPONSE_TIME; - if (wsClientCount()) nextCheckin=0; + if (nextCheckin > config.maxsleep) nextCheckin = config.maxsleep; + if (wsClientCount() && config.stopsleep == 1) nextCheckin=0; tagRecord* taginfo = nullptr; taginfo = tagRecord::findByMAC(dst); @@ -507,13 +507,13 @@ void refreshAllPending() { }; void setAPchannel() { - if (APconfig["channel"].as() == 0) { + if (config.channel == 0) { // trigger channel autoselect UDPcomm udpsync; udpsync.getAPList(); } else { - if (curChannel.channel != APconfig["channel"].as()) { - curChannel.channel = APconfig["channel"].as(); + if (curChannel.channel != config.channel) { + curChannel.channel = config.channel; sendChannelPower(&curChannel); } } diff --git a/ESP32_AP-Flasher/src/tag_db.cpp b/ESP32_AP-Flasher/src/tag_db.cpp index f7295a6f..3d82e178 100644 --- a/ESP32_AP-Flasher/src/tag_db.cpp +++ b/ESP32_AP-Flasher/src/tag_db.cpp @@ -9,7 +9,8 @@ #include "language.h" std::vector tagDB; -DynamicJsonDocument APconfig(150); + +Config config; tagRecord* tagRecord::findByMAC(uint8_t mac[8]) { for (int16_t c = 0; c < tagDB.size(); c++) { @@ -245,27 +246,32 @@ void clearPending(tagRecord* taginfo) { void initAPconfig() { LittleFS.begin(true); + DynamicJsonDocument APconfig(150); File configFile = LittleFS.open("/current/apconfig.json", "r"); - if (!configFile) { - // default values' - Serial.println("APconfig not found"); - APconfig["channel"] = 0; - APconfig["alias"] = String(); - APconfig["ledbrightness"] = 255; - APconfig["language"] = getDefaultLanguage(); - return; - } DeserializationError error = deserializeJson(APconfig, configFile); if (error) { configFile.close(); - Serial.println("apconfig.json file corrupted, or not enough space in apconfig to hold it"); - return; + Serial.println("failed to read apconfig.json. Using default config"); } configFile.close(); + + config.channel = APconfig["channel"] | 25; + strlcpy(config.alias, APconfig["alias"], sizeof(config.alias)); + config.led = APconfig["led"] | 255; + config.language = APconfig["language"] | getDefaultLanguage(); + config.maxsleep = APconfig["maxsleep"] | 10; + config.stopsleep = APconfig["stopsleep"] | 1; } void saveAPconfig() { fs::File configFile = LittleFS.open("/current/apconfig.json", "w"); + DynamicJsonDocument APconfig(150); + APconfig["channel"] = config.channel; + APconfig["alias"] = config.alias; + APconfig["led"] = config.led; + APconfig["language"] = config.language; + APconfig["maxsleep"] = config.maxsleep; + APconfig["stopsleep"] = config.stopsleep; serializeJson(APconfig, configFile); configFile.close(); } \ No newline at end of file diff --git a/ESP32_AP-Flasher/src/udp.cpp b/ESP32_AP-Flasher/src/udp.cpp index ef126b4d..e71ffe9e 100644 --- a/ESP32_AP-Flasher/src/udp.cpp +++ b/ESP32_AP-Flasher/src/udp.cpp @@ -67,7 +67,7 @@ void UDPcomm::processPacket(AsyncUDPPacket packet) { APlist APitem; APitem.src = WiFi.localIP(); - strcpy(APitem.alias, APconfig["alias"]); + strcpy(APitem.alias, config.alias); APitem.channelId = curChannel.channel; APitem.tagCount = getTagCount(); APitem.version = apInfo.version; @@ -116,7 +116,7 @@ void autoselect(void* pvParameters) { if (curChannel.channel == 0) { curChannel.channel = 11; } - APconfig["channel"] = curChannel.channel; + config.channel = curChannel.channel; do { vTaskDelay(1000 / portTICK_PERIOD_MS); } while (!apInfo.isOnline); @@ -131,13 +131,13 @@ void autoselect(void* pvParameters) { void UDPcomm::getAPList() { APlist APitem; APitem.src = WiFi.localIP(); - strcpy(APitem.alias, APconfig["alias"]); + strcpy(APitem.alias, config.alias); APitem.channelId = curChannel.channel; APitem.tagCount = getTagCount(); APitem.version = apInfo.version; wsSendAPitem(&APitem); - if (APconfig["channel"].as() == 0) { + if (config.alias == 0) { xTaskCreate(autoselect, "autoselect", 5000, NULL, configMAX_PRIORITIES - 10, NULL); } diff --git a/ESP32_AP-Flasher/src/web.cpp b/ESP32_AP-Flasher/src/web.cpp index 8f4ffa14..0f70efd0 100644 --- a/ESP32_AP-Flasher/src/web.cpp +++ b/ESP32_AP-Flasher/src/web.cpp @@ -21,8 +21,8 @@ extern uint8_t data_to_send[]; -const char *http_username = "admin"; -const char *http_password = "admin"; +//const char *http_username = "admin"; +//const char *http_password = "admin"; AsyncWebServer server(80); AsyncWebSocket ws("/ws"); @@ -224,7 +224,8 @@ void init_web() { Serial.print("Connected! IP address: "); Serial.println(WiFi.localIP()); - server.addHandler(new SPIFFSEditor(LittleFS, http_username, http_password)); + //server.addHandler(new SPIFFSEditor(LittleFS, http_username, http_password)); + server.addHandler(new SPIFFSEditor(LittleFS)); ws.onEvent(onEvent); server.addHandler(&ws); @@ -341,16 +342,28 @@ void init_web() { server.on("/save_apcfg", HTTP_POST, [](AsyncWebServerRequest *request) { if (request->hasParam("alias", true) && request->hasParam("channel", true)) { - APconfig["alias"] = request->getParam("alias", true)->value(); - APconfig["channel"] = request->getParam("channel", true)->value(); - if (request->hasParam("ledbrightness", true)) { - APconfig["ledbrightness"] = request->getParam("ledbrightness", true)->value(); + + String aliasValue = request->getParam("alias", true)->value(); + size_t aliasLength = aliasValue.length(); + if (aliasLength > 31) aliasLength = 31; + aliasValue.toCharArray(config.alias, aliasLength + 1); + config.alias[aliasLength] = '\0'; + + config.channel = static_cast(request->getParam("channel", true)->value().toInt()); + if (request->hasParam("led", true)) { + config.led = static_cast(request->getParam("led", true)->value().toInt()); updateBrightnessFromConfig(); } if (request->hasParam("language", true)) { - APconfig["language"] = request->getParam("language", true)->value(); + config.language = static_cast(request->getParam("language", true)->value().toInt()); updateLanguageFromConfig(); } + if (request->hasParam("maxsleep", true)) { + config.maxsleep = static_cast(request->getParam("maxsleep", true)->value().toInt()); + } + if (request->hasParam("stopsleep", true)) { + config.stopsleep = static_cast(request->getParam("stopsleep", true)->value().toInt()); + } saveAPconfig(); setAPchannel(); }