add 24hr restart proc

This commit is contained in:
Travis Shears 2025-09-13 21:32:15 +02:00
parent 33b231583b
commit c99f619fe5

11
node1.c
View file

@ -11,6 +11,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <hardware/watchdog.h>
// 5 sec loop is for testing // 5 sec loop is for testing
// #define LOOP_INTERVAL_MS 5000 // #define LOOP_INTERVAL_MS 5000
@ -48,6 +49,14 @@ void comms_led_update() {
} }
} }
// Callback to reset the Pico after 24 hours
static bool cb_24h(__unused struct repeating_timer *t) {
printf("Restarting Pico after 24 hours...\n");
watchdog_enable(1, 1); // 1 ms timeout, reset on next loop
while (1) { tight_loop_contents(); } // Wait for reset
return false; // Not reached
}
static mqtt_client_config mqtt_config; static mqtt_client_config mqtt_config;
static pms5003_config pms_config; static pms5003_config pms_config;
@ -142,6 +151,8 @@ int main() {
struct repeating_timer timer_30; struct repeating_timer timer_30;
add_repeating_timer_ms(LOOP_INTERVAL_MS, cb_30, NULL, &timer_30); add_repeating_timer_ms(LOOP_INTERVAL_MS, cb_30, NULL, &timer_30);
struct repeating_timer timer_24h;
add_repeating_timer_ms(86400000, cb_24h, NULL, &timer_24h);
while (true) { while (true) {
comms_led_update(); comms_led_update();
sleep_us(100); sleep_us(100);