From db88de1f7549a2be64733ff80ff1fcf94813ff54 Mon Sep 17 00:00:00 2001 From: Nic Limper Date: Thu, 1 Jun 2023 21:42:09 +0200 Subject: [PATCH] minor bug fixes - --- ESP32_AP-Flasher/data/www/content_cards.json | 2 +- ESP32_AP-Flasher/data/www/ota.js | 1 + ESP32_AP-Flasher/include/contentmanager.h | 2 +- ESP32_AP-Flasher/src/contentmanager.cpp | 71 +++++++++++--------- ESP32_AP-Flasher/src/makeimage.cpp | 4 ++ ESP32_AP-Flasher/src/ota.cpp | 2 +- ESP32_AP-Flasher/src/powermgt.cpp | 14 ++-- ESP32_AP-Flasher/src/tag_db.cpp | 7 +- 8 files changed, 58 insertions(+), 45 deletions(-) diff --git a/ESP32_AP-Flasher/data/www/content_cards.json b/ESP32_AP-Flasher/data/www/content_cards.json index fd4ba76a..17aa3e1d 100644 --- a/ESP32_AP-Flasher/data/www/content_cards.json +++ b/ESP32_AP-Flasher/data/www/content_cards.json @@ -166,7 +166,7 @@ { "id": 16, "name": "Buienradar", - "desc": "Dutch rain predictions for the next two hours. Only works for Dutch locations.", + "desc": "Dutch rain predictions for the next two hours. Only works for locations in the Netherlands and Belgium.", "hwtype": [ 1 ], diff --git a/ESP32_AP-Flasher/data/www/ota.js b/ESP32_AP-Flasher/data/www/ota.js index f08e4eb9..ba0516f6 100644 --- a/ESP32_AP-Flasher/data/www/ota.js +++ b/ESP32_AP-Flasher/data/www/ota.js @@ -265,6 +265,7 @@ export async function updateESP(fileUrl, showConfirm) { } } catch (error) { print('Error: ' + error, "red"); + print("Something went wrong, try again."); } running = false; diff --git a/ESP32_AP-Flasher/include/contentmanager.h b/ESP32_AP-Flasher/include/contentmanager.h index 706b7c27..c11165a4 100644 --- a/ESP32_AP-Flasher/include/contentmanager.h +++ b/ESP32_AP-Flasher/include/contentmanager.h @@ -24,7 +24,7 @@ void drawNumber(String &filename, int32_t count, int32_t thresholdred, tagRecord void drawWeather(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, imgParam &imageParams); void drawForecast(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, imgParam &imageParams); void drawIdentify(String &filename, tagRecord *&taginfo, imgParam &imageParams); -bool getImgURL(String &filename, String URL, time_t fetched, imgParam &imageParams, String MAC); +int getImgURL(String &filename, String URL, time_t fetched, imgParam &imageParams, String MAC); bool getRssFeed(String &filename, String URL, String title, tagRecord *&taginfo, imgParam &imageParams); bool getCalFeed(String &filename, String URL, String title, tagRecord *&taginfo, imgParam &imageParams); void drawQR(String &filename, String qrcontent, String title, tagRecord *&taginfo, imgParam &imageParams); diff --git a/ESP32_AP-Flasher/src/contentmanager.cpp b/ESP32_AP-Flasher/src/contentmanager.cpp index 946f7661..d7b4070a 100644 --- a/ESP32_AP-Flasher/src/contentmanager.cpp +++ b/ESP32_AP-Flasher/src/contentmanager.cpp @@ -30,12 +30,15 @@ #include "web.h" #include "language.h" -// #define PAL_BLACK 0 -// #define PAL_WHITE 9 -// #define PAL_RED 2 +#ifdef BOARD_HAS_PSRAM #define PAL_BLACK TFT_BLACK #define PAL_WHITE TFT_WHITE #define PAL_RED TFT_RED +#else +#define PAL_BLACK 0 +#define PAL_WHITE 9 +#define PAL_RED 2 +#endif enum contentModes { Image, @@ -206,14 +209,19 @@ void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo) { case ImageUrl: - if (getImgURL(filename, cfgobj["url"], (time_t)cfgobj["#fetched"], imageParams, String(hexmac))) { - taginfo->nextupdate = now + 60 * (cfgobj["interval"].as() < 5 ? 5 : cfgobj["interval"].as()); + { + int httpcode = getImgURL(filename, cfgobj["url"], (time_t)cfgobj["#fetched"], imageParams, String(hexmac)); + if (httpcode == 200) { + taginfo->nextupdate = now + 60 * (cfgobj["interval"].as() < 3 ? 3 : cfgobj["interval"].as()); updateTagImage(filename, mac, cfgobj["interval"].as(), taginfo, imageParams); cfgobj["#fetched"] = now; + } else if (httpcode == 304) { + taginfo->nextupdate = now + 60 * (cfgobj["interval"].as() < 3 ? 3 : cfgobj["interval"].as()); } else { taginfo->nextupdate = now + 300; } - break; + break; + } case RSSFeed: @@ -270,8 +278,8 @@ void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo) { case 16: // buienradar drawBuienradar(filename, cfgobj, taginfo, imageParams); - taginfo->nextupdate = now + (cfgobj["timetolive"].as() < 5 ? 5 : cfgobj["timetolive"].as())* 60; - updateTagImage(filename, mac, (cfgobj["timetolive"].as() < 5 ? 5 : cfgobj["timetolive"].as()), taginfo, imageParams); + taginfo->nextupdate = now + (cfgobj["ttl"].as() < 5 ? 5 : cfgobj["ttl"].as()) * 60; + updateTagImage(filename, mac, (cfgobj["ttl"].as() < 5 ? 5 : cfgobj["ttl"].as()), taginfo, imageParams); break; } @@ -298,16 +306,18 @@ void drawString(TFT_eSprite &spr, String content, uint16_t posx, uint16_t posy, } void initSprite(TFT_eSprite &spr, int w, int h) { - // spr.setColorDepth(4); // 4 bits per pixel, uses indexed color +#ifdef BOARD_HAS_PSRAM spr.setColorDepth(8); spr.createSprite(w, h); - /* +#else + spr.setColorDepth(4); // 4 bits per pixel, uses indexed color + spr.createSprite(w, h); uint16_t cmap[16]; cmap[PAL_BLACK] = TFT_BLACK; cmap[PAL_RED] = TFT_RED; cmap[PAL_WHITE] = TFT_WHITE; spr.createPalette(cmap, 16); - */ +#endif if (spr.getPointer() == nullptr) { wsErr("Failed to create sprite"); } @@ -360,26 +370,21 @@ void drawDate(String &filename, tagRecord *&taginfo, imgParam &imageParams) { } void drawNumber(String &filename, int32_t count, int32_t thresholdred, tagRecord *&taginfo, imgParam &imageParams) { - if (taginfo->hwType == SOLUM_SEG_UK) { imageParams.symbols = 0x00; if (count > 19999) { sprintf(imageParams.segments, "over flow"); + return; + } else if (count > 9999) { + imageParams.symbols = 0x02; + sprintf(imageParams.segments, "%04d", count - 10000); } else { - if (count > 9999) { - imageParams.symbols = 0x02; - if (taginfo->contentMode == CountHours) { - sprintf(imageParams.segments, "%04d hour", count - 10000); - } else { - sprintf(imageParams.segments, "%04d days", count - 10000); - } - } else { - if (taginfo->contentMode == CountHours) { - sprintf(imageParams.segments, "%4d hour", count); - } else { - sprintf(imageParams.segments, "%4d days", count); - } - } + sprintf(imageParams.segments, "%4d", count); + } + if (taginfo->contentMode == CountHours) { + strcat(imageParams.segments, " hour"); + } else { + strcat(imageParams.segments, " days"); } return; } @@ -788,7 +793,7 @@ void drawIdentify(String &filename, tagRecord *&taginfo, imgParam &imageParams) spr.deleteSprite(); } -bool getImgURL(String &filename, String URL, time_t fetched, imgParam &imageParams, String MAC) { +int getImgURL(String &filename, String URL, time_t fetched, imgParam &imageParams, String MAC) { // https://images.klari.net/kat-bw29.jpg LittleFS.begin(); @@ -811,11 +816,11 @@ bool getImgURL(String &filename, String URL, time_t fetched, imgParam &imagePara if (httpCode != 304) { wsErr("http " + URL + " " + String(httpCode)); } else { - wsLog("http " + URL + " " + String(httpCode)); + Serial.println("http 304, image is not changed " + URL); } } http.end(); - return (httpCode == 200 || httpCode == 304); + return httpCode; } #ifdef CONTENT_RSS @@ -928,7 +933,7 @@ bool getCalFeed(String &filename, String URL, String title, tagRecord *&taginfo, struct tm timeinfo; localtime_r(&now, &timeinfo); static char dateString[40]; - strftime(dateString, sizeof(dateString), " - %d.%m.%Y", &timeinfo); + strftime(dateString, sizeof(dateString), "%d.%m.%Y", &timeinfo); HTTPClient http; http.begin(URL); @@ -963,6 +968,7 @@ bool getCalFeed(String &filename, String URL, String title, tagRecord *&taginfo, u8f.setBackgroundColor(PAL_WHITE); u8f.setCursor(5, 16); u8f.print(title); + u8f.setCursor(180, 16); u8f.print(dateString); int n = doc.size(); @@ -999,6 +1005,7 @@ bool getCalFeed(String &filename, String URL, String title, tagRecord *&taginfo, u8f.setBackgroundColor(PAL_WHITE); u8f.setCursor(5, 16); u8f.print(title); + u8f.setCursor(280, 16); u8f.print(dateString); int n = doc.size(); @@ -1156,7 +1163,9 @@ void drawBuienradar(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, i char *formatHttpDate(time_t t) { static char buf[40]; struct tm *timeinfo; - timeinfo = gmtime(&t); + timeinfo = localtime(&t); // Get the local time + time_t utcTime = mktime(timeinfo); // Convert to UTC + timeinfo = gmtime(&utcTime); strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", timeinfo); return buf; } diff --git a/ESP32_AP-Flasher/src/makeimage.cpp b/ESP32_AP-Flasher/src/makeimage.cpp index b27ff2d8..2e5e5c49 100644 --- a/ESP32_AP-Flasher/src/makeimage.cpp +++ b/ESP32_AP-Flasher/src/makeimage.cpp @@ -30,7 +30,11 @@ void jpg2buffer(String filein, String fileout, imgParam &imageParams) { } Serial.println("jpeg conversion " + String(w) + "x" + String(h)); +#ifdef BOARD_HAS_PSRAM spr.setColorDepth(16); +#else + spr.setColorDepth(8); +#endif spr.createSprite(w, h); if (spr.getPointer() == nullptr) { //no heap space for 8bpp, fallback to 1bpp diff --git a/ESP32_AP-Flasher/src/ota.cpp b/ESP32_AP-Flasher/src/ota.cpp index b2a367d9..5ae5347f 100644 --- a/ESP32_AP-Flasher/src/ota.cpp +++ b/ESP32_AP-Flasher/src/ota.cpp @@ -86,7 +86,7 @@ void handleGetExtUrl(AsyncWebServerRequest* request) { String url = request->getParam("url")->value(); HTTPClient http; http.begin(url); - http.setConnectTimeout(4000); + http.setConnectTimeout(5000); http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS); int httpResponseCode = http.GET(); if (httpResponseCode > 0) { diff --git a/ESP32_AP-Flasher/src/powermgt.cpp b/ESP32_AP-Flasher/src/powermgt.cpp index 205c2cbf..1148616a 100644 --- a/ESP32_AP-Flasher/src/powermgt.cpp +++ b/ESP32_AP-Flasher/src/powermgt.cpp @@ -11,12 +11,14 @@ #ifdef SIMPLE_AP void simpleAPPower(bool state) { - pinMode(FLASHER_AP_POWER, INPUT); - pinMode(FLASHER_AP_POWER2, INPUT); - digitalWrite(FLASHER_AP_POWER, state); - digitalWrite(FLASHER_AP_POWER2, state); - pinMode(FLASHER_AP_POWER, OUTPUT); - pinMode(FLASHER_AP_POWER2, OUTPUT); + if (FLASHER_AP_POWER >= 0 && FLASHER_AP_POWER2 >= 0) { + pinMode(FLASHER_AP_POWER, INPUT); + pinMode(FLASHER_AP_POWER2, INPUT); + digitalWrite(FLASHER_AP_POWER, state); + digitalWrite(FLASHER_AP_POWER2, state); + pinMode(FLASHER_AP_POWER, OUTPUT); + pinMode(FLASHER_AP_POWER2, OUTPUT); + } } #endif diff --git a/ESP32_AP-Flasher/src/tag_db.cpp b/ESP32_AP-Flasher/src/tag_db.cpp index 9e208c2a..c7089e95 100644 --- a/ESP32_AP-Flasher/src/tag_db.cpp +++ b/ESP32_AP-Flasher/src/tag_db.cpp @@ -156,7 +156,7 @@ void saveDB(String filename) { void loadDB(String filename) { StaticJsonDocument<1000> doc; - Serial.println("start reading DB from file"); + Serial.println("reading DB from file"); long t = millis(); LittleFS.begin(); @@ -221,9 +221,6 @@ void loadDB(String filename) { } readfile.close(); - Serial.println(millis() - t); - Serial.println("finished reading file"); - return; } @@ -290,6 +287,6 @@ void saveAPconfig() { APconfig["language"] = config.language; APconfig["maxsleep"] = config.maxsleep; APconfig["stopsleep"] = config.stopsleep; - serializeJson(APconfig, configFile); + serializeJsonPretty(APconfig, configFile); configFile.close(); } \ No newline at end of file