From 112a467cff6abe5499013bc4f156d7f334063f39 Mon Sep 17 00:00:00 2001 From: Nic Limper Date: Sun, 9 Jul 2023 00:56:48 +0200 Subject: [PATCH] added wifi power and time zone to APconfig - added wifi transmit power option - added time zone config option - small fixes --- ESP32_AP-Flasher/data/www/index.html | 59 +++++++++++++++++++++++++ ESP32_AP-Flasher/data/www/main.js | 6 ++- ESP32_AP-Flasher/include/tag_db.h | 2 + ESP32_AP-Flasher/src/contentmanager.cpp | 5 +-- ESP32_AP-Flasher/src/main.cpp | 10 ++--- ESP32_AP-Flasher/src/makeimage.cpp | 4 +- ESP32_AP-Flasher/src/system.cpp | 8 ++++ ESP32_AP-Flasher/src/tag_db.cpp | 10 +++++ ESP32_AP-Flasher/src/web.cpp | 17 ++++--- 9 files changed, 105 insertions(+), 16 deletions(-) diff --git a/ESP32_AP-Flasher/data/www/index.html b/ESP32_AP-Flasher/data/www/index.html index 28f5f025..dfa5c1ac 100644 --- a/ESP32_AP-Flasher/data/www/index.html +++ b/ESP32_AP-Flasher/data/www/index.html @@ -116,6 +116,65 @@ Latency will be around 40 seconds.">

+

+ + +

+

+ + +

diff --git a/ESP32_AP-Flasher/data/www/main.js b/ESP32_AP-Flasher/data/www/main.js index 75588c28..c562d5fd 100644 --- a/ESP32_AP-Flasher/data/www/main.js +++ b/ESP32_AP-Flasher/data/www/main.js @@ -94,7 +94,7 @@ function connect() { processTags(msg.tags); } if (msg.sys) { - $('#sysinfo').innerHTML = 'free heap: ' + msg.sys.heap + ' bytes ┇ db size: ' + convertSize(msg.sys.dbsize) + " ("+ msg.sys.dbsize + ' bytes) ┇ db record count: ' + msg.sys.recordcount + ' ┇ filesystem free: ' + convertSize(msg.sys.littlefsfree); + $('#sysinfo').innerHTML = 'free heap: ' + convertSize(msg.sys.heap) + ' ┇ db size: ' + convertSize(msg.sys.dbsize) + ' ┇ db record count: ' + msg.sys.recordcount + ' ┇ filesystem free: ' + convertSize(msg.sys.littlefsfree); if (msg.sys.apstate) { $("#apstatecolor").style.color = apstate[msg.sys.apstate].color; $("#apstate").innerHTML = apstate[msg.sys.apstate].state; @@ -452,6 +452,8 @@ $('#apconfigbutton').onclick = function () { $("#apcfglanguage").value = data.language; $("#apclatency").value = data.maxsleep; $("#apcpreventsleep").value = data.stopsleep; + $("#apcwifipower").value = data.wifipower; + $("#apctimezone").value = data.timezone; }) $('#apconfigbox').style.display = 'block' } @@ -464,6 +466,8 @@ $('#apcfgsave').onclick = function () { formData.append('language', $('#apcfglanguage').value); formData.append('maxsleep', $('#apclatency').value); formData.append('stopsleep', $('#apcpreventsleep').value); + formData.append('wifipower', $('#apcwifipower').value); + formData.append('timezone', $('#apctimezone').value); fetch("/save_apcfg", { method: "POST", body: formData diff --git a/ESP32_AP-Flasher/include/tag_db.h b/ESP32_AP-Flasher/include/tag_db.h index 63c16ad3..51fa1b20 100644 --- a/ESP32_AP-Flasher/include/tag_db.h +++ b/ESP32_AP-Flasher/include/tag_db.h @@ -63,6 +63,8 @@ struct Config { uint8_t maxsleep; uint8_t stopsleep; uint8_t runStatus; + uint8_t wifiPower; + char timeZone[52]; }; // extern SemaphoreHandle_t tagDBOwner; diff --git a/ESP32_AP-Flasher/src/contentmanager.cpp b/ESP32_AP-Flasher/src/contentmanager.cpp index 8f5298bf..83c9e803 100644 --- a/ESP32_AP-Flasher/src/contentmanager.cpp +++ b/ESP32_AP-Flasher/src/contentmanager.cpp @@ -511,7 +511,7 @@ void drawWeather(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, imgP drawString(spr, String(tmpOutput), loc["temp"][0], loc["temp"][1], loc["temp"][2], TL_DATUM, (temperature < 0 ? PAL_RED : PAL_BLACK)); spr.loadFont(loc["icon"][2], *contentFS); - if (weathercode == 55 || weathercode == 65 || weathercode == 75 || weathercode == 82 || weathercode == 86 || weathercode == 95 || weathercode == 99) { + if (weathercode == 55 || weathercode == 65 || weathercode == 75 || weathercode == 82 || weathercode == 86 || weathercode == 95 || weathercode == 96 || weathercode == 99) { spr.setTextColor(PAL_RED, PAL_WHITE); } else { spr.setTextColor(PAL_BLACK, PAL_WHITE); @@ -584,7 +584,7 @@ void drawForecast(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, img uint8_t weathercode = doc["daily"]["weathercode"][dag].as(); if (weathercode > 40) weathercode -= 40; spr.loadFont(loc["icon"][2], *contentFS); - if (weathercode == 55 || weathercode == 65 || weathercode == 75 || weathercode == 82 || weathercode == 86 || weathercode == 95 || weathercode == 99) { + if (weathercode == 55 || weathercode == 65 || weathercode == 75 || weathercode == 82 || weathercode == 86 || weathercode == 95 || weathercode == 96 || weathercode == 99) { spr.setTextColor(PAL_RED, PAL_WHITE); } else { spr.setTextColor(PAL_BLACK, PAL_WHITE); @@ -775,7 +775,6 @@ bool getCalFeed(String &filename, String URL, String title, tagRecord *&taginfo, for (int i = 0; i < n; i++) { JsonObject obj = doc[i]; String eventtitle = obj["title"]; - String startz = obj["start"]; time_t starttime = obj["start"]; time_t endtime = obj["end"]; setU8G2Font(loc["line"][3], u8f); diff --git a/ESP32_AP-Flasher/src/main.cpp b/ESP32_AP-Flasher/src/main.cpp index 213edb4f..6705c8e1 100644 --- a/ESP32_AP-Flasher/src/main.cpp +++ b/ESP32_AP-Flasher/src/main.cpp @@ -35,13 +35,13 @@ void delayedStart(void* parameter) { void timeTask(void* parameter) { wsSendSysteminfo(); - Serial.printf("Free heap: %.2f KB\n", ESP.getFreeHeap() / 1024.0f); + Serial.printf("Free heap: %.2f kB\n", ESP.getFreeHeap() / 1024.0f); while (1) { time_t now; time(&now); if (now % 5 == 0 || apInfo.state != AP_STATE_ONLINE || config.runStatus != RUNSTATUS_RUN) wsSendSysteminfo(); - if (now % 5 == 0) Serial.printf("Free heap: %.2f KB\n", ESP.getFreeHeap() / 1024.0f); + if (now % 5 == 0) Serial.printf("Free heap: %.2f kB\n", ESP.getFreeHeap() / 1024.0f); if (now % 300 == 6 && config.runStatus != RUNSTATUS_STOP) saveDB("/current/tagDB.json"); if (apInfo.state == AP_STATE_ONLINE) contentRunner(); @@ -55,8 +55,8 @@ void setup() { xTaskCreate(ledTask, "ledhandler", 2000, NULL, 2, NULL); vTaskDelay(10 / portTICK_PERIOD_MS); - // show a nice pattern to indicate the AP is booting / waiting for WiFi setup #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 @@ -122,10 +122,10 @@ void setup() { xTaskCreate(usbFlasherTask, "usbflasher", 10000, NULL, configMAX_PRIORITIES - 10, NULL); #endif - configTzTime("CET-1CEST,M3.5.0,M10.5.0/3", "0.nl.pool.ntp.org", "europe.pool.ntp.org", "time.nist.gov"); + initAPconfig(); + configTzTime(config.timeZone, "0.nl.pool.ntp.org", "europe.pool.ntp.org", "time.nist.gov"); // https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv - initAPconfig(); updateLanguageFromConfig(); updateBrightnessFromConfig(); diff --git a/ESP32_AP-Flasher/src/makeimage.cpp b/ESP32_AP-Flasher/src/makeimage.cpp index 639a5c1a..d8f3ebc7 100644 --- a/ESP32_AP-Flasher/src/makeimage.cpp +++ b/ESP32_AP-Flasher/src/makeimage.cpp @@ -219,8 +219,10 @@ void spr2buffer(TFT_eSprite &spr, String &fileout, imgParam &imageParams) { free(blackBuffer); if (imageParams.hasRed) { uint8_t *redBuffer = (uint8_t*) spr2color(spr, imageParams, &bufferSize, true); - if(!redBuffer) + if(!redBuffer) { + imageParams.hasRed = false; return; + } f_out.write(redBuffer, bufferSize); free(redBuffer); } diff --git a/ESP32_AP-Flasher/src/system.cpp b/ESP32_AP-Flasher/src/system.cpp index 83879d08..819a7fb7 100644 --- a/ESP32_AP-Flasher/src/system.cpp +++ b/ESP32_AP-Flasher/src/system.cpp @@ -30,6 +30,14 @@ void logLine(String text) { File logFile = contentFS->open("/log.txt", "a"); if (logFile) { + if (logFile.size() >= 10 * 1024) { + logFile.close(); + contentFS->remove("/logold.txt"); + contentFS->rename("/log.txt", "/logold.txt"); + logFile = contentFS->open("/log.txt", "a"); + if (!logFile) return; + } + logFile.print(timeStr); logFile.println(text); logFile.close(); diff --git a/ESP32_AP-Flasher/src/tag_db.cpp b/ESP32_AP-Flasher/src/tag_db.cpp index 3dd9c3ca..e2acba77 100644 --- a/ESP32_AP-Flasher/src/tag_db.cpp +++ b/ESP32_AP-Flasher/src/tag_db.cpp @@ -286,6 +286,14 @@ void initAPconfig() { config.language = APconfig["language"] | getDefaultLanguage(); config.maxsleep = APconfig["maxsleep"] | 10; config.stopsleep = APconfig["stopsleep"] | 1; + // default wifi power 8.5 dbM + // see https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/WiFiGeneric.h#L111 + config.wifiPower = APconfig["wifipower"] | 34; + if (APconfig["timezone"]) { + strlcpy(config.timeZone, APconfig["timezone"], sizeof(config.timeZone)); + } else { + strlcpy(config.timeZone, "CET-1CEST,M3.5.0,M10.5.0/3", sizeof(config.timeZone)); + } } void saveAPconfig() { @@ -297,6 +305,8 @@ void saveAPconfig() { APconfig["language"] = config.language; APconfig["maxsleep"] = config.maxsleep; APconfig["stopsleep"] = config.stopsleep; + APconfig["wifipower"] = config.wifiPower; + APconfig["timezone"] = config.timeZone; serializeJsonPretty(APconfig, configFile); configFile.close(); } \ No newline at end of file diff --git a/ESP32_AP-Flasher/src/web.cpp b/ESP32_AP-Flasher/src/web.cpp index a192f404..52641916 100644 --- a/ESP32_AP-Flasher/src/web.cpp +++ b/ESP32_AP-Flasher/src/web.cpp @@ -235,18 +235,13 @@ void init_web() { WiFiManager wm; bool res; -#if defined(OPENEPAPERLINK_MINI_AP_PCB) || defined(OPENEPAPERLINK_NANO_AP_PCB) - WiFi.setTxPower(WIFI_POWER_15dBm); -#endif + WiFi.setTxPower(static_cast(config.wifiPower)); wm.setWiFiAutoReconnect(true); res = wm.autoConnect("OpenEPaperLink Setup"); if (!res) { Serial.println("Failed to connect"); ESP.restart(); } -#if defined(OPENEPAPERLINK_MINI_AP_PCB) || defined(OPENEPAPERLINK_NANO_AP_PCB) - WiFi.setTxPower(WIFI_POWER_19_5dBm); -#endif Serial.print("Connected! IP address: "); Serial.println(WiFi.localIP()); @@ -419,6 +414,16 @@ void init_web() { if (request->hasParam("stopsleep", true)) { config.stopsleep = static_cast(request->getParam("stopsleep", true)->value().toInt()); } + if (request->hasParam("wifipower", true)) { + config.wifiPower = static_cast(request->getParam("wifipower", true)->value().toInt()); + WiFi.setTxPower(static_cast(config.wifiPower)); + } + if (request->hasParam("timezone", true)) { + strncpy(config.timeZone, request->getParam("timezone", true)->value().c_str(), sizeof(config.timeZone) - 1); + config.timeZone[sizeof(config.timeZone) - 1] = '\0'; + setenv("TZ", config.timeZone, 1); + tzset(); + } saveAPconfig(); setAPchannel(); }