From 3621c84cc497c62caf17dc248ae63551f6b80f26 Mon Sep 17 00:00:00 2001 From: Nic Limper Date: Mon, 2 Oct 2023 13:43:53 +0200 Subject: [PATCH] various small fixes - neopixel patterns optimized. The 'breathing' led state now is green colored if everything is okay, and blue if there are one or more tags timed out. - time zone is now set before wifi connect to show correct time zone in the logs during startup - concurrent image upload POST is now blocked. If an upload is in progress while you do a second http POST, http status 409 Conflict is returned. - small synchronisation bug fix in web interface on loading tag type - dialog window close bugfix in painter - image upload is now logged in /log.txt --- ESP32_AP-Flasher/include/leds.h | 1 + ESP32_AP-Flasher/src/leds.cpp | 8 ++------ ESP32_AP-Flasher/src/main.cpp | 7 +------ ESP32_AP-Flasher/src/serialap.cpp | 1 + ESP32_AP-Flasher/src/web.cpp | 18 ++++++++++++------ ESP32_AP-Flasher/wwwroot/main.js | 15 +++++++++++---- ESP32_AP-Flasher/wwwroot/painter.js | 2 +- 7 files changed, 29 insertions(+), 23 deletions(-) diff --git a/ESP32_AP-Flasher/include/leds.h b/ESP32_AP-Flasher/include/leds.h index 16e99bed..0f094c11 100644 --- a/ESP32_AP-Flasher/include/leds.h +++ b/ESP32_AP-Flasher/include/leds.h @@ -29,6 +29,7 @@ void updateBrightnessFromConfig(); #ifdef HAS_RGB_LED extern CRGB rgbIdleColor; +extern uint16_t rgbIdlePeriod; void shortBlink(CRGB cname); void showColorPattern(CRGB colorone, CRGB colortwo, CRGB colorthree); void rgbIdle(); diff --git a/ESP32_AP-Flasher/src/leds.cpp b/ESP32_AP-Flasher/src/leds.cpp index b642eb4e..71b39a9d 100644 --- a/ESP32_AP-Flasher/src/leds.cpp +++ b/ESP32_AP-Flasher/src/leds.cpp @@ -15,6 +15,7 @@ int maxledbrightness = 255; #ifdef HAS_RGB_LED QueueHandle_t rgbLedQueue; CRGB rgbIdleColor = CRGB::Green; +uint16_t rgbIdlePeriod = 511; struct ledInstructionRGB { CRGB ledColor; @@ -122,8 +123,6 @@ void showRGB() { FastLED.show(); } -volatile uint16_t rgbIdlePeriod = 767; - void rgbIdleStep() { static bool dirUp = true; static uint16_t step = 0; @@ -131,7 +130,7 @@ void rgbIdleStep() { if (dirUp) { // up step++; - if (step == rgbIdlePeriod) { + if (step >= rgbIdlePeriod) { dirUp = false; } } else { @@ -226,9 +225,6 @@ void ledTask(void* parameter) { addFadeColor(CRGB::Red); addFadeColor(CRGB::Green); addFadeColor(CRGB::Blue); - addFadeColor(CRGB::Red); - addFadeColor(CRGB::Green); - addFadeColor(CRGB::Blue); CRGB oldColor = CRGB::Black; uint16_t rgbInstructionFadeTime = 0; #endif diff --git a/ESP32_AP-Flasher/src/main.cpp b/ESP32_AP-Flasher/src/main.cpp index a02fdcce..bfa3c4fb 100644 --- a/ESP32_AP-Flasher/src/main.cpp +++ b/ESP32_AP-Flasher/src/main.cpp @@ -53,11 +53,6 @@ void setup() { xTaskCreate(ledTask, "ledhandler", 2000, NULL, 2, NULL); vTaskDelay(10 / portTICK_PERIOD_MS); -#ifdef HAS_RGB_LED - // show a nice pattern to indicate the AP is booting / waiting for WiFi setup - showColorPattern(CRGB::Aqua, CRGB::Green, CRGB::Blue); -#endif - #if defined(OPENEPAPERLINK_MINI_AP_PCB) || defined(OPENEPAPERLINK_NANO_AP_PCB) APEnterEarlyReset(); // this allows us to view the booting process. After the device showing up, you have 3 seconds to open a terminal on the COM port @@ -119,6 +114,7 @@ void setup() { initAPconfig(); + xTaskCreate(initTime, "init time", 5000, NULL, 2, NULL); updateLanguageFromConfig(); updateBrightnessFromConfig(); @@ -140,7 +136,6 @@ void setup() { config.runStatus = RUNSTATUS_PAUSE; } - xTaskCreate(initTime, "init time", 5000, NULL, 2, NULL); xTaskCreate(delayedStart, "delaystart", 2000, NULL, 2, NULL); wsSendSysteminfo(); diff --git a/ESP32_AP-Flasher/src/serialap.cpp b/ESP32_AP-Flasher/src/serialap.cpp index 547611b5..3c672f6d 100644 --- a/ESP32_AP-Flasher/src/serialap.cpp +++ b/ESP32_AP-Flasher/src/serialap.cpp @@ -151,6 +151,7 @@ void setAPstate(bool isOnline, uint8_t state) { CRGB::YellowGreen }; rgbIdleColor = colorMap[state]; + rgbIdlePeriod = (isOnline ? 767 : 255); #endif } diff --git a/ESP32_AP-Flasher/src/web.cpp b/ESP32_AP-Flasher/src/web.cpp index a4dfed93..b9c8aed3 100644 --- a/ESP32_AP-Flasher/src/web.cpp +++ b/ESP32_AP-Flasher/src/web.cpp @@ -20,6 +20,7 @@ #include "serialap.h" #include "settings.h" #include "storage.h" +#include "system.h" #include "tag_db.h" #include "udp.h" #include "wifimanager.h" @@ -101,8 +102,10 @@ void wsSendSysteminfo() { uint32_t tagcount = getTagCount(timeoutcount); char result[40]; if (timeoutcount > 0) { + if (apInfo.state == AP_STATE_ONLINE && apInfo.isOnline == true) rgbIdleColor = CRGB::DarkBlue; snprintf(result, sizeof(result), "%lu / %lu, %lu timed out", tagcount, tagDB.size(), timeoutcount); } else { + if (apInfo.state == AP_STATE_ONLINE && apInfo.isOnline == true) rgbIdleColor = CRGB::Green; snprintf(result, sizeof(result), "%lu / %lu", tagcount, tagDB.size()); } setVarDB("ap_tagcount", result); @@ -185,9 +188,8 @@ uint8_t wsClientCount() { void init_web() { wsMutex = xSemaphoreCreateMutex(); - Storage.begin(); - WiFi.mode(WIFI_STA); + WiFi.mode(WIFI_STA); WiFi.setTxPower(static_cast(config.wifiPower)); wm.connectToWifi(); @@ -623,16 +625,19 @@ void init_web() { } void doImageUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { - if (config.runStatus != RUNSTATUS_RUN) { - request->send(409, "text/plain", "come back later"); - return; - } + static bool imageUploadBusy = false; if (!index) { + if (config.runStatus != RUNSTATUS_RUN || imageUploadBusy) { + request->send(409, "text/plain", "Come back later"); + return; + } if (request->hasParam("mac", true)) { filename = request->getParam("mac", true)->value() + ".jpg"; } else { filename = "unknown.jpg"; } + imageUploadBusy = true; + logLine("http imageUpload " + filename); xSemaphoreTake(fsMutex, portMAX_DELAY); request->_tempFile = contentFS->open("/" + filename, "w"); } @@ -668,6 +673,7 @@ void doImageUpload(AsyncWebServerRequest *request, String filename, size_t index } else { request->send(400, "text/plain", "parameters incomplete"); } + imageUploadBusy = false; } } diff --git a/ESP32_AP-Flasher/wwwroot/main.js b/ESP32_AP-Flasher/wwwroot/main.js index 0e6c9d89..e0ac5c30 100644 --- a/ESP32_AP-Flasher/wwwroot/main.js +++ b/ESP32_AP-Flasher/wwwroot/main.js @@ -222,7 +222,6 @@ function processTags(tagArray) { if (!alias) alias = tagmac.replace(/^0{1,4}/, ''); if ($('#tag' + tagmac + ' .alias').innerHTML != alias) { $('#tag' + tagmac + ' .alias').innerHTML = alias; - //GroupSortFilter(); } let contentDefObj = getContentDefById(element.contentMode); @@ -1023,10 +1022,18 @@ $('#activefilter').addEventListener('click', (event) => { }); async function getTagtype(hwtype) { - if (tagTypes[hwtype]) { + if (tagTypes[hwtype] && tagTypes[hwtype].busy == false) { return tagTypes[hwtype]; } + // nice, but no possibility to invalidate this cache yet. + /* + const storedData = JSON.parse(localStorage.getItem("tagTypes")); + if (storedData && storedData[hwtype]) { + return storedData[hwtype]; + } + */ + if (getTagtypeBusy) { await new Promise(resolve => { const checkBusy = setInterval(() => { @@ -1045,7 +1052,7 @@ async function getTagtype(hwtype) { clearInterval(checkBusy); resolve(); } - }, 10); + }, 50); }); } @@ -1054,8 +1061,8 @@ async function getTagtype(hwtype) { } try { - tagTypes[hwtype] = { busy: true }; getTagtypeBusy = true; + tagTypes[hwtype] = { busy: true }; const response = await fetch('/tagtypes/' + hwtype.toString(16).padStart(2, '0').toUpperCase() + '.json'); if (!response.ok) { let data = { name: 'unknown id ' + hwtype, width: 0, height: 0, bpp: 0, rotatebuffer: 0, colortable: [], busy: false }; diff --git a/ESP32_AP-Flasher/wwwroot/painter.js b/ESP32_AP-Flasher/wwwroot/painter.js index 4178c3e8..7cf83afd 100644 --- a/ESP32_AP-Flasher/wwwroot/painter.js +++ b/ESP32_AP-Flasher/wwwroot/painter.js @@ -104,7 +104,7 @@ function startPainter(mac, width, height) { const xhr = new XMLHttpRequest(); xhr.open('POST', '/imgupload'); xhr.send(formData); - $('#configbox').style.display = 'none'; + $('#configbox').close(); }); $("#buttonbar").appendChild(blackButton);