From f727971138752b8040e79fd45e19b980afcce513 Mon Sep 17 00:00:00 2001 From: c3ma Date: Wed, 27 Oct 2021 22:04:44 +0200 Subject: [PATCH 1/4] increased ota flash sizes --- esp32/defaultWithSmallerSpiffs.csv | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/esp32/defaultWithSmallerSpiffs.csv b/esp32/defaultWithSmallerSpiffs.csv index 8458d8b..85ef317 100644 --- a/esp32/defaultWithSmallerSpiffs.csv +++ b/esp32/defaultWithSmallerSpiffs.csv @@ -1,6 +1,7 @@ # Name, Type, SubType, Offset, Size, Flags nvs, data, nvs, 0x9000, 0x5000, otadata, data, ota, 0xe000, 0x2000, -app0, app, ota_0, 0x10000, 0x150000, -app1, app, ota_1, 0x160000,0x150000, -spiffs, data, spiffs, 0x300000,0x17000, +app0, app, ota_0, 0x10000, 0x300000, +app1, app, ota_1, 0x310000,0x300000, +spiffs, data, spiffs, 0x610000,0x17000, +#https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html \ No newline at end of file From 66d69eab6bb647c79794ac53476fdee404863f4d Mon Sep 17 00:00:00 2001 From: c3ma Date: Sat, 13 Nov 2021 17:26:39 +0100 Subject: [PATCH 2/4] Exceptions added --- esp32/include/ControllerConfiguration.h | 4 ++-- esp32/platformio.ini | 3 ++- esp32/src/main.cpp | 31 +++++++++++++++++++------ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/esp32/include/ControllerConfiguration.h b/esp32/include/ControllerConfiguration.h index f757744..cc1485c 100644 --- a/esp32/include/ControllerConfiguration.h +++ b/esp32/include/ControllerConfiguration.h @@ -85,9 +85,9 @@ #define FIRMWARE_VERSION "sw 2.0 hw 0.10b" #define TIMED_LIGHT_PIN CUSTOM1_PIN5 -//#define FLOWMETER_PIN CUSTOM1_PIN1 +#define FLOWMETER_PIN CUSTOM1_PIN1 #ifdef FLOWMETER_PIN - #define FLOWMETER_FLOWFACTOR 22 /** F = 22 * Q;Q = L/min */ + #define FLOWMETER_FLOWFACTOR 23 /** F = 22 * Q;Q = L/min */ #endif #define MOIST_SENSOR_MAX_FRQ 60000 // 60kHz (500Hz margin) diff --git a/esp32/platformio.ini b/esp32/platformio.ini index 089714c..110308f 100644 --- a/esp32/platformio.ini +++ b/esp32/platformio.ini @@ -12,9 +12,10 @@ platform = espressif32 board = esp32doit-devkit-v1 framework = arduino -build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY +build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY -fexceptions -lstdc++-exc board_build.partitions = defaultWithSmallerSpiffs.csv + ; the latest development brankitchen-lightch (convention V3.0.x) lib_deps = ArduinoJson@6.16.1 OneWire diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 08b3c96..4aa2a1a 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -69,7 +69,7 @@ RTC_DATA_ATTR long consecutiveWateringPlant[MAX_PLANTS] = {0}; bool volatile mDownloadMode = false; /**< Controller must not sleep */ bool volatile mSensorsRead = false; /**< Sensors are read without Wifi or MQTT */ int volatile pumpToRun = -1; /** pump to run at the end of the cycle */ -int volatile selfTestPumpRun = -1; /** pump to run at the end of the cycle */ +int volatile selfTestPumpRun = -1; /** pump to run at the end of the cycle */ bool mConfigured = false; long nextBlink = 0; /**< Time needed in main loop to support expected blink code */ @@ -639,12 +639,9 @@ void pumpActiveLoop() } } -/** - * @brief Startup function - * Is called once, the controller is started - */ -void setup() +void safeSetup() { + throw std::runtime_error("Shit happened"); /* reduce power consumption */ setCpuFrequencyMhz(80); @@ -829,9 +826,29 @@ void setup() setupFinishedTimestamp = millis(); } +/** + * @brief Startup function + * Is called once, the controller is started + */ +void setup() +{ + try + { + safeSetup(); + } + catch (const std::exception &e) + { + Serial.printf("Exception thrown: \"%s\"", e.what()); + } + catch (...) + { + Serial.println("Other exception thrown."); + } +} + void selfTest() { - + if (selfTestPumpRun >= 0 && selfTestPumpRun < MAX_PLANTS) { Serial << "self test mode pump deactivate " << pumpToRun << endl; From a457db44474f0c41f957f46313a3849ecd6c5b1e Mon Sep 17 00:00:00 2001 From: Ollo Date: Sun, 14 Nov 2021 13:51:52 +0100 Subject: [PATCH 3/4] Fixed memory leak --- esp32/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 4aa2a1a..918f310 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -208,7 +208,7 @@ void readOneWireSensors() continue; } - char buf[sizeof(ds18b20Address) * 2]; + char buf[(sizeof(ds18b20Address) * 2)+1]; /* additional byte for trailing terminator */ snprintf(buf, sizeof(buf), "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X", ds18b20Address[0], ds18b20Address[1], From c5bce25afe93e1ad41e48a43f148e6492941d4e8 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sun, 14 Nov 2021 19:49:40 +0100 Subject: [PATCH 4/4] Added time into logs --- esp32/src/MQTTUtils.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/esp32/src/MQTTUtils.cpp b/esp32/src/MQTTUtils.cpp index 8dd5827..7cdabfb 100644 --- a/esp32/src/MQTTUtils.cpp +++ b/esp32/src/MQTTUtils.cpp @@ -9,9 +9,19 @@ void log(int level, String message, int statusCode) { String buffer; StaticJsonDocument<200> doc; + // Read the current time + time_t now; // this is the epoch + tm tm; // the structure tm holds time information in a more convient way doc["level"] = level; doc["message"] = message; doc["statusCode"] = statusCode; + time(&now); + localtime_r(&now, &tm); + if (tm.tm_year > (2021 - 1970)) { /* Only add the time, if we have at least 2021 */ + doc["time"] = String(String(1900 + tm.tm_year) + "-" + String(tm.tm_mon + 1) + "-" + String(tm.tm_mday) + + " " + String(tm.tm_hour) + ":" + String(tm.tm_min) + ":" + String(tm.tm_sec)); + } + serializeJson(doc, buffer); if (mAliveWasRead) { @@ -84,4 +94,4 @@ void startMQTTRoundtripTest(){ Homie.getMqttClient() .subscribe(backupTopic, 2); } -} \ No newline at end of file +}