Remove auto-reboot and make timezone configurable

This commit is contained in:
2026-02-13 10:46:58 +01:00
parent 32851ea61b
commit f65a6d28d9
4 changed files with 22 additions and 25 deletions

View File

@@ -29,8 +29,6 @@ static char g_device_id[16] = "";
static SenderStatus g_sender_statuses[NUM_SENDERS];
static bool g_ap_mode = false;
static WifiMqttConfig g_cfg;
static uint32_t g_boot_ms = 0;
static bool g_debug_forced_reboot_done = false;
static FaultCounters g_sender_faults = {};
static FaultCounters g_receiver_faults = {};
static FaultCounters g_receiver_faults_published = {};
@@ -121,7 +119,6 @@ static constexpr uint32_t METER_READER_TASK_STACK_WORDS = 4096;
static constexpr UBaseType_t METER_READER_TASK_PRIORITY = 2;
static constexpr BaseType_t METER_READER_TASK_CORE = 0;
#endif
static constexpr uint32_t DEBUG_FORCED_REBOOT_INTERVAL_MS = 3UL * 60UL * 60UL * 1000UL;
enum class TxBuildError : uint8_t {
None = 0,
@@ -937,7 +934,6 @@ void setup() {
#endif
watchdog_init();
g_boot_ms = millis();
g_role = detect_role();
init_device_ids(g_short_id, g_device_id, sizeof(g_device_id));
display_set_role(g_role);
@@ -1364,16 +1360,6 @@ receiver_loop_done:
}
void loop() {
if (SERIAL_DEBUG_MODE && !g_debug_forced_reboot_done &&
(millis() - g_boot_ms >= DEBUG_FORCED_REBOOT_INTERVAL_MS)) {
g_debug_forced_reboot_done = true;
serial_debug_printf("debug: force reboot after %lu ms uptime",
static_cast<unsigned long>(millis() - g_boot_ms));
#ifdef ARDUINO_ARCH_ESP32
delay(50);
esp_restart();
#endif
}
#ifdef ENABLE_TEST_MODE
if (g_role == DeviceRole::Sender) {
test_sender_loop(g_short_id, g_device_id);

View File

@@ -1,4 +1,5 @@
#include "time_manager.h"
#include "config.h"
#include <time.h>
static bool g_time_synced = false;
@@ -12,15 +13,20 @@ static void note_last_sync(uint32_t epoch) {
g_last_sync_utc = epoch;
}
static void ensure_timezone_set() {
if (g_tz_set) {
return;
}
setenv("TZ", TIMEZONE_TZ, 1);
tzset();
g_tz_set = true;
}
void time_receiver_init(const char *ntp_server_1, const char *ntp_server_2) {
const char *server1 = (ntp_server_1 && ntp_server_1[0] != '\0') ? ntp_server_1 : "pool.ntp.org";
const char *server2 = (ntp_server_2 && ntp_server_2[0] != '\0') ? ntp_server_2 : "time.nist.gov";
configTime(0, 0, server1, server2);
if (!g_tz_set) {
setenv("TZ", "CET-1CEST,M3.5.0/2,M10.5.0/3", 1);
tzset();
g_tz_set = true;
}
ensure_timezone_set();
}
uint32_t time_get_utc() {
@@ -40,11 +46,7 @@ bool time_is_synced() {
}
void time_set_utc(uint32_t epoch) {
if (!g_tz_set) {
setenv("TZ", "CET-1CEST,M3.5.0/2,M10.5.0/3", 1);
tzset();
g_tz_set = true;
}
ensure_timezone_set();
struct timeval tv;
tv.tv_sec = epoch;
tv.tv_usec = 0;