Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade(framework): upgrade to latest arduino core / esp-idf #39

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AquaMQTT/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lib_deps =
googletest

[env:arduino_nano_esp32]
platform = espressif32@6.8.1
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.05/platform-espressif32.zip
board = arduino_nano_esp32
framework = arduino
test_framework = googletest
Expand Down
2 changes: 2 additions & 0 deletions AquaMQTT/src/handler/OTA.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "handler/OTA.h"

#include <ArduinoOTA.h>
#include <esp_task_wdt.h>

#include "config/Configuration.h"

Expand Down Expand Up @@ -36,6 +37,7 @@ void OTAHandler::setup() // NOLINT(*-convert-member-functions-to-static)
.onEnd([]() { Serial.println("\nEnd"); })
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
esp_task_wdt_reset();
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
Expand Down
66 changes: 37 additions & 29 deletions AquaMQTT/src/handler/RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,51 @@ void RTCHandler::setup()

void RTCHandler::loop()
{
if (timeStatus() != timeSet)
// do a ntp update if case time is not set or last ntp update is an hour ago
if (timeStatus() != timeSet || (millis() - mLastNTPUpdate) >= 3600000)
{
if ((millis() - mLastNTPUpdate) >= 3600000)
mLastNTPUpdate = millis();
struct tm timeinfo
{
mLastNTPUpdate = millis();
struct tm timeinfo
{
};
if (getLocalTime(&timeinfo, 5000))
{
setTime(timeinfo.tm_hour,
timeinfo.tm_min,
timeinfo.tm_sec,
timeinfo.tm_mday,
timeinfo.tm_mon + 1,
timeinfo.tm_year + 1900);
if (mFoundRTC)
{
mRTC.adjust(DateTime(now()));
}
}
else if (mFoundRTC)
};

// success getting time via ntp
if (getLocalTime(&timeinfo, 5000))
{
// set local time in lib (PaulStoffregen/Time)
setTime(timeinfo.tm_hour,
timeinfo.tm_min,
timeinfo.tm_sec,
timeinfo.tm_mday,
timeinfo.tm_mon + 1,
timeinfo.tm_year + 1900);

// store the new time to the rtc
if (mFoundRTC)
{
setTime(mRTC.now().unixtime());
mRTC.adjust(DateTime(now()));
}
}
// ntp update failed, but we have a hardware rtc
else if (mFoundRTC)
{
// set local time in lib from RTC
setTime(mRTC.now().unixtime());
}
}
else if (config::OVERRIDE_TIME_AND_DATE_IN_MITM && (millis() - mLastStateUpdate) > 500)

// if time is known (either from RTC or NTP), then update the state
if (timeStatus() == timeSet && config::OVERRIDE_TIME_AND_DATE_IN_MITM && ((millis() - mLastStateUpdate) > 1000))
{
mLastStateUpdate = now();
mLastStateUpdate = millis();
time_t timeUpdate = now();
aquamqtt::HMIStateProxy::getInstance().updateTime(
second(mLastStateUpdate),
minute(mLastStateUpdate),
hour(mLastStateUpdate),
day(mLastStateUpdate),
month(mLastStateUpdate),
year(mLastStateUpdate));
second(timeUpdate),
minute(timeUpdate),
hour(timeUpdate),
day(timeUpdate),
month(timeUpdate),
year(timeUpdate));
}
}

Expand Down
7 changes: 6 additions & 1 deletion AquaMQTT/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ OTAHandler otaHandler;
RTCHandler rtcHandler;
WifiHandler wifiHandler;

esp_task_wdt_config_t twdt_config = {
.timeout_ms = WATCHDOG_TIMEOUT_S * 1000,
.idle_core_mask = (1 << configNUM_CORES) - 1,
.trigger_panic = true,
};

void loop()
{
Expand All @@ -44,7 +49,7 @@ void setup()
Serial.println("REBOOT");

// initialize watchdog
esp_task_wdt_init(WATCHDOG_TIMEOUT_S, true);
esp_task_wdt_init(&twdt_config);
esp_task_wdt_add(nullptr);

// setup wifi
Expand Down
Loading