switch to network poll arch
", ", "); "); "); "); "); "); "); "); "); ", BACKEND_SERVER_IP, BACKEND_SERVER_PORT);
This commit is contained in:
parent
af4b86b966
commit
f107bfb55b
2 changed files with 16 additions and 13 deletions
|
|
@ -33,7 +33,7 @@ pico_set_program_version(node1 "0.1")
|
||||||
pico_set_program_name(node1 "node_one")
|
pico_set_program_name(node1 "node_one")
|
||||||
|
|
||||||
# pull in common dependencies
|
# pull in common dependencies
|
||||||
target_link_libraries(node1 pico_stdlib hardware_i2c pico_cyw43_arch_lwip_threadsafe_background)
|
target_link_libraries(node1 pico_stdlib hardware_i2c pico_cyw43_arch_lwip_poll)
|
||||||
|
|
||||||
target_include_directories(node1 PRIVATE
|
target_include_directories(node1 PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
|
|
||||||
27
node1.c
27
node1.c
|
|
@ -135,22 +135,23 @@ static bool cb_30(__unused struct repeating_timer *t) {
|
||||||
// current_pms5003_reading = pms5003_finish_reading(&pms_config);
|
// current_pms5003_reading = pms5003_finish_reading(&pms_config);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// readings_index++;
|
readings_index++;
|
||||||
if (wifi_connected) {
|
if (wifi_connected) {
|
||||||
char msg[256];
|
char msg[256];
|
||||||
snprintf(msg, sizeof(msg),
|
snprintf(msg, sizeof(msg),
|
||||||
"M001,%.2f,%.2f%.2f\n",
|
"M001,%.2f,%.2f,%2f\n",
|
||||||
current_bem280_reading.temperature,
|
current_bem280_reading.temperature,
|
||||||
current_bem280_reading.pressure,
|
current_bem280_reading.pressure,
|
||||||
current_bem280_reading.humidity);
|
current_bem280_reading.humidity);
|
||||||
printf("Sending data to backend server...\n");
|
printf("Sending data to backend server...\n");
|
||||||
bool success = tcp_client_send_message(&tcp_config, msg);
|
printf("MSG: %s", msg);
|
||||||
if (success) {
|
// bool success = tcp_client_send_message(&tcp_config, msg);
|
||||||
printf("✓ Data sent successfully\n");
|
// if (success) {
|
||||||
comms_led_blink();
|
// printf("✓ Data sent successfully\n");
|
||||||
} else {
|
// comms_led_blink();
|
||||||
printf("✗ Failed to send data\n");
|
// } else {
|
||||||
}
|
// printf("✗ Failed to send data\n");
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
printf("WiFi not connected, skipping send\n");
|
printf("WiFi not connected, skipping send\n");
|
||||||
}
|
}
|
||||||
|
|
@ -170,14 +171,14 @@ int main() {
|
||||||
printf("Initializing WiFi...\n");
|
printf("Initializing WiFi...\n");
|
||||||
if (!wifi_init()) {
|
if (!wifi_init()) {
|
||||||
printf("WiFi initialization failed!\n");
|
printf("WiFi initialization failed!\n");
|
||||||
// Continue anyway for sensor readings
|
panic("WiFi initialization failed!");
|
||||||
} else {
|
} else {
|
||||||
wifi_connected = true;
|
wifi_connected = true;
|
||||||
|
|
||||||
// Initialize TCP client
|
// Initialize TCP client
|
||||||
if (!tcp_client_init(&tcp_config, BACKEND_SERVER_IP,
|
if (!tcp_client_init(&tcp_config, BACKEND_SERVER_IP,
|
||||||
BACKEND_SERVER_PORT, 10000)) {
|
BACKEND_SERVER_PORT, 10000)) {
|
||||||
printf("TCP client initialization failed\n");
|
printf("TCP client initialization failed\n");
|
||||||
|
panic("TCP client initialization failed!");
|
||||||
wifi_connected = false;
|
wifi_connected = false;
|
||||||
} else {
|
} else {
|
||||||
printf("TCP client ready: %s:%d\n", BACKEND_SERVER_IP, BACKEND_SERVER_PORT);
|
printf("TCP client ready: %s:%d\n", BACKEND_SERVER_IP, BACKEND_SERVER_PORT);
|
||||||
|
|
@ -195,8 +196,10 @@ int main() {
|
||||||
struct repeating_timer timer_24h;
|
struct repeating_timer timer_24h;
|
||||||
add_repeating_timer_ms(86400000, cb_24h, NULL, &timer_24h);
|
add_repeating_timer_ms(86400000, cb_24h, NULL, &timer_24h);
|
||||||
while (true) {
|
while (true) {
|
||||||
|
cyw43_arch_poll();
|
||||||
|
cyw43_arch_wait_for_work_until(make_timeout_time_ms(1000));
|
||||||
comms_led_update();
|
comms_led_update();
|
||||||
tight_loop_contents();
|
|
||||||
watchdog_update();
|
watchdog_update();
|
||||||
|
tight_loop_contents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue