switch to network poll arch

",
",
");
");
");
");
");
");
");
");
");
", BACKEND_SERVER_IP, BACKEND_SERVER_PORT);
This commit is contained in:
Travis Shears 2025-12-21 19:10:22 +01:00
parent af4b86b966
commit f107bfb55b
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
2 changed files with 16 additions and 13 deletions

27
node1.c
View file

@ -135,22 +135,23 @@ static bool cb_30(__unused struct repeating_timer *t) {
// current_pms5003_reading = pms5003_finish_reading(&pms_config);
// }
// readings_index++;
readings_index++;
if (wifi_connected) {
char msg[256];
snprintf(msg, sizeof(msg),
"M001,%.2f,%.2f%.2f\n",
"M001,%.2f,%.2f,%2f\n",
current_bem280_reading.temperature,
current_bem280_reading.pressure,
current_bem280_reading.humidity);
printf("Sending data to backend server...\n");
bool success = tcp_client_send_message(&tcp_config, msg);
if (success) {
printf("✓ Data sent successfully\n");
comms_led_blink();
} else {
printf("✗ Failed to send data\n");
}
printf("MSG: %s", msg);
// bool success = tcp_client_send_message(&tcp_config, msg);
// if (success) {
// printf("✓ Data sent successfully\n");
// comms_led_blink();
// } else {
// printf("✗ Failed to send data\n");
// }
} else {
printf("WiFi not connected, skipping send\n");
}
@ -170,14 +171,14 @@ int main() {
printf("Initializing WiFi...\n");
if (!wifi_init()) {
printf("WiFi initialization failed!\n");
// Continue anyway for sensor readings
panic("WiFi initialization failed!");
} else {
wifi_connected = true;
// Initialize TCP client
if (!tcp_client_init(&tcp_config, BACKEND_SERVER_IP,
BACKEND_SERVER_PORT, 10000)) {
printf("TCP client initialization failed\n");
panic("TCP client initialization failed!");
wifi_connected = false;
} else {
printf("TCP client ready: %s:%d\n", BACKEND_SERVER_IP, BACKEND_SERVER_PORT);
@ -195,8 +196,10 @@ int main() {
struct repeating_timer timer_24h;
add_repeating_timer_ms(86400000, cb_24h, NULL, &timer_24h);
while (true) {
cyw43_arch_poll();
cyw43_arch_wait_for_work_until(make_timeout_time_ms(1000));
comms_led_update();
tight_loop_contents();
watchdog_update();
tight_loop_contents();
}
}