From c403c06b098e2ded0dd7958804f1e4c1ba7f06f7 Mon Sep 17 00:00:00 2001 From: Nic Limper Date: Wed, 4 Oct 2023 15:33:22 +0200 Subject: [PATCH] fix AP not responding + add more logs to investigate crashes --- ESP32_AP-Flasher/include/util.h | 2 ++ ESP32_AP-Flasher/src/contentmanager.cpp | 5 +++++ ESP32_AP-Flasher/src/newproto.cpp | 3 +++ ESP32_AP-Flasher/src/serialap.cpp | 12 ++++-------- ESP32_AP-Flasher/src/system.cpp | 4 +++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ESP32_AP-Flasher/include/util.h b/ESP32_AP-Flasher/include/util.h index fdf988d0..085bfca8 100644 --- a/ESP32_AP-Flasher/include/util.h +++ b/ESP32_AP-Flasher/include/util.h @@ -4,6 +4,7 @@ #include #include +#include "system.h" #include "web.h" namespace util { @@ -72,6 +73,7 @@ static void printLargestFreeBlock() { static bool httpGetJson(String &url, JsonDocument &json, const uint16_t timeout, JsonDocument *filter = nullptr) //, const followRedirects_t redirects = followRedirects_t::HTTPC_DISABLE_FOLLOW_REDIRECTS) { HTTPClient http; + logLine("http httpGetJson " + url); http.begin(url); http.setTimeout(timeout); // http.setFollowRedirects(redirects); diff --git a/ESP32_AP-Flasher/src/contentmanager.cpp b/ESP32_AP-Flasher/src/contentmanager.cpp index 13a1578f..5212f5b7 100644 --- a/ESP32_AP-Flasher/src/contentmanager.cpp +++ b/ESP32_AP-Flasher/src/contentmanager.cpp @@ -28,6 +28,7 @@ #endif #include "language.h" #include "settings.h" +#include "system.h" #include "tag_db.h" #include "truetype.h" #include "util.h" @@ -870,6 +871,7 @@ int getImgURL(String &filename, String URL, time_t fetched, imgParam &imageParam Storage.begin(); HTTPClient http; + logLine("http getImgURL " + URL); http.begin(URL); http.addHeader("If-Modified-Since", formatHttpDate(fetched)); http.addHeader("X-ESL-MAC", MAC); @@ -975,6 +977,7 @@ bool getCalFeed(String &filename, String URL, String title, tagRecord *&taginfo, strftime(dateString, sizeof(dateString), "%d.%m.%Y", &timeinfo); HTTPClient http; + logLine("http getCalFeed " + URL); http.begin(URL); http.setTimeout(10000); http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); @@ -1077,6 +1080,7 @@ uint8_t drawBuienradar(String &filename, JsonObject &cfgobj, tagRecord *&taginfo String lat = cfgobj["#lat"]; String lon = cfgobj["#lon"]; + logLine("http drawBuienradar"); http.begin("https://gps.buienradar.nl/getrr.php?lat=" + lat + "&lon=" + lon); http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); http.setTimeout(5000); @@ -1338,6 +1342,7 @@ bool getJsonTemplateFileExtractVariables(String &filename, String jsonfile, Json int getJsonTemplateUrl(String &filename, String URL, time_t fetched, String MAC, tagRecord *&taginfo, imgParam &imageParams) { HTTPClient http; http.useHTTP10(true); + logLine("http getJsonTemplateUrl " + URL); http.begin(URL); http.addHeader("If-Modified-Since", formatHttpDate(fetched)); http.addHeader("X-ESL-MAC", MAC); diff --git a/ESP32_AP-Flasher/src/newproto.cpp b/ESP32_AP-Flasher/src/newproto.cpp index 88e203ba..45bb6b13 100644 --- a/ESP32_AP-Flasher/src/newproto.cpp +++ b/ESP32_AP-Flasher/src/newproto.cpp @@ -239,6 +239,7 @@ void prepareExternalDataAvail(struct pendingData* pending, IPAddress remoteIP) { String imageUrl = "http://" + remoteIP.toString() + filename; wsLog("GET " + imageUrl); HTTPClient http; + logLine("http prepareExternalDataAvail " + imageUrl); http.begin(imageUrl); int httpCode = http.GET(); if (httpCode == 200) { @@ -250,6 +251,7 @@ void prepareExternalDataAvail(struct pendingData* pending, IPAddress remoteIP) { } else if (httpCode == 404) { imageUrl = "http://" + remoteIP.toString() + "/current/" + String(hexmac) + ".raw"; http.end(); + logLine("http prepareExternalDataAvail " + imageUrl); http.begin(imageUrl); httpCode = http.GET(); if (httpCode == 200) { @@ -296,6 +298,7 @@ void prepareExternalDataAvail(struct pendingData* pending, IPAddress remoteIP) { String dataUrl = "http://" + remoteIP.toString() + "/getdata?mac=" + String(hexmac); wsLog("GET " + dataUrl); HTTPClient http; + logLine("http DATATYPE_CUSTOM_LUT_OTA " + dataUrl); http.begin(dataUrl); int httpCode = http.GET(); if (httpCode == 200) { diff --git a/ESP32_AP-Flasher/src/serialap.cpp b/ESP32_AP-Flasher/src/serialap.cpp index 3c672f6d..de4fd074 100644 --- a/ESP32_AP-Flasher/src/serialap.cpp +++ b/ESP32_AP-Flasher/src/serialap.cpp @@ -288,7 +288,7 @@ bool sendPing() { Serial.print("ping"); int t = millis(); if (!txStart()) return false; - for (uint8_t attempt = 0; attempt < 5; attempt++) { + for (uint8_t attempt = 0; attempt < 3; attempt++) { cmdReplyValue = CMD_REPLY_WAIT; AP_SERIAL_PORT.print("RDY?"); if (waitCmdReply()) { @@ -681,11 +681,7 @@ bool bringAPOnline() { // try without rebooting AP_SERIAL_PORT.updateBaudRate(115200); uint32_t bootTimeout = millis(); - bool APrdy = false; - while ((!APrdy) && (millis() - bootTimeout < 3 * 1000)) { - APrdy = sendPing(); - vTaskDelay(300 / portTICK_PERIOD_MS); - } + bool APrdy = sendPing(); if (!APrdy) { if (apInfo.state == AP_STATE_FLASHING) return false; APTagReset(); @@ -761,10 +757,10 @@ void APTask(void* parameter) { ShowAPInfo(); if (apInfo.type == SOLUM_SEG_UK) { - setAPstate(false, AP_STATE_COMING_ONLINE); + setAPstate(true, AP_STATE_COMING_ONLINE); segmentedShowIp(); showAPSegmentedInfo(apInfo.mac, true); - setAPstate(false, AP_STATE_ONLINE); + setAPstate(true, AP_STATE_ONLINE); updateContent(apInfo.mac); } diff --git a/ESP32_AP-Flasher/src/system.cpp b/ESP32_AP-Flasher/src/system.cpp index c0f3a196..aa613254 100644 --- a/ESP32_AP-Flasher/src/system.cpp +++ b/ESP32_AP-Flasher/src/system.cpp @@ -16,6 +16,7 @@ void initTime(void* parameter) { sntp_set_time_sync_notification_cb(timeSyncCallback); sntp_set_sync_interval(300 * 1000); configTzTime(config.timeZone, "nl.pool.ntp.org", "europe.pool.ntp.org", "time.nist.gov"); + logStartUp(); struct tm timeinfo; while (millis() < 30000) { if (!getLocalTime(&timeinfo)) { @@ -25,7 +26,6 @@ void initTime(void* parameter) { break; } } - logStartUp(); if (config.runStatus = RUNSTATUS_INIT) config.runStatus = RUNSTATUS_RUN; vTaskDelay(10 / portTICK_PERIOD_MS); vTaskDelete(NULL); @@ -43,6 +43,7 @@ void logLine(const String& text) { const char* format = (now < (time_t)1672531200) ? " %H:%M:%S " : "%Y-%m-%d %H:%M:%S "; strftime(timeStr, sizeof(timeStr), format, localtime(&now)); + xSemaphoreTake(fsMutex, portMAX_DELAY); File logFile = contentFS->open("/log.txt", "a"); if (logFile) { if (logFile.size() >= 10 * 1024) { @@ -57,6 +58,7 @@ void logLine(const String& text) { logFile.println(text); logFile.close(); } + xSemaphoreGive(fsMutex); } void logStartUp() {