add 12h restart
", "); "); ");
This commit is contained in:
parent
0e513dc79a
commit
c94f8df1cc
1 changed files with 15 additions and 3 deletions
18
node1.c
18
node1.c
|
|
@ -8,9 +8,10 @@
|
|||
#include <pico/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define SENSOR_READING_INTERVAL_US (1000000 * 15) // 15 seconds
|
||||
#define SENSOR_READING_INTERVAL_US (1000000 * 30) // 30 seconds
|
||||
#define WIFI_CHECK_INTERVAL_US (1000000 * 10) // 10 seconds
|
||||
#define WIFI_STATUS_LED_PIN 16
|
||||
#define RESTART_INTERVAL_MIN (12 * 60) // 12 hours in minutes
|
||||
|
||||
static tcp_client_config tcp_config;
|
||||
static bme280_config bem_config;
|
||||
|
|
@ -20,6 +21,11 @@ static pms5003_reading current_pms5003_reading;
|
|||
char msg_to_send[256];
|
||||
|
||||
static int8_t readings_index = 0;
|
||||
static absolute_time_t startup_time;
|
||||
|
||||
static uint64_t absolute_time_diff_min(absolute_time_t from, absolute_time_t to) {
|
||||
return absolute_time_diff_us(from, to) / (1000000 * 60);
|
||||
}
|
||||
|
||||
static void send_msg(char *msg) {
|
||||
bool success = tcp_client_send_message(&tcp_config, msg);
|
||||
|
|
@ -92,6 +98,7 @@ int main() {
|
|||
// Poll every 5 seconds
|
||||
absolute_time_t last_check = get_absolute_time();
|
||||
absolute_time_t last_sensor_reading = get_absolute_time();
|
||||
startup_time = get_absolute_time();
|
||||
|
||||
while (1) {
|
||||
watchdog_update();
|
||||
|
|
@ -129,8 +136,7 @@ int main() {
|
|||
snprintf(msg_to_send, sizeof(msg_to_send), "M02,%.2f,%.2f,%2f\n",
|
||||
current_pms5003_reading.pm1, current_pms5003_reading.pm2_5,
|
||||
current_pms5003_reading.pm10);
|
||||
printf(
|
||||
"Sending particle matter readings to backend server...\n");
|
||||
printf("Sending particle matter readings to backend server...\n");
|
||||
send_msg(msg_to_send);
|
||||
}
|
||||
|
||||
|
|
@ -172,6 +178,12 @@ int main() {
|
|||
}
|
||||
}
|
||||
|
||||
// Check if 12 hours have elapsed for restart
|
||||
if (absolute_time_diff_min(startup_time, now) >= RESTART_INTERVAL_MIN) {
|
||||
printf("12-hour restart interval reached. Restarting...\n");
|
||||
watchdog_reboot(0, 0, 0); // Force immediate restart via watchdog
|
||||
}
|
||||
|
||||
sleep_ms(100);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue