diff --git a/node1.c b/node1.c index 9370444..bd6af05 100644 --- a/node1.c +++ b/node1.c @@ -2,14 +2,26 @@ #include "pico/cyw43_arch.h" #include "pico/stdlib.h" #include +#include "tcp_client.h" #include #include #include #define SENSOR_READING_INTERVAL_US (1000000 * 10) // 10 seconds +static tcp_client_config tcp_config; static bme280_config bem_config; static bme280_reading current_bem280_reading; +char msg_to_send[256]; + +static void send_msg(char *msg) { + bool success = tcp_client_send_message(&tcp_config, msg); + if (success) { + printf("✓ Data sent successfully\n"); + } else { + printf("✗ Failed to send data\n"); + } +} int main() { stdio_init_all(); @@ -56,6 +68,12 @@ int main() { printf("WiFi connected!\n"); + if (!tcp_client_init(&tcp_config, BACKEND_SERVER_IP, BACKEND_SERVER_PORT, + 20000)) { + panic("TCP client initialization failed!"); + } + watchdog_update(); + // Poll every 5 seconds absolute_time_t last_check = get_absolute_time(); absolute_time_t last_sensor_reading = get_absolute_time(); @@ -70,6 +88,11 @@ int main() { last_sensor_reading = now; printf("Making BME280 Reading\n"); current_bem280_reading = bme280_read(&bem_config); + snprintf(msg_to_send, sizeof(msg_to_send), "M001,%.2f,%.2f,%2f\n", + current_bem280_reading.temperature, current_bem280_reading.pressure, + current_bem280_reading.humidity); + printf("Sending temperature, pressure, and humidity to backend server...\n"); + send_msg(msg_to_send); } if (absolute_time_diff_us(last_check, now) >= 5000000) {