get pm measurment working
This commit is contained in:
parent
eac8412475
commit
e0a5fef8fc
2 changed files with 63 additions and 46 deletions
|
|
@ -86,7 +86,7 @@ type Message1DTO struct {
|
||||||
|
|
||||||
type Message2DTO struct {
|
type Message2DTO struct {
|
||||||
PM1 float32 `json:"pm1"`
|
PM1 float32 `json:"pm1"`
|
||||||
PM25 float32 `json:"pm25"`
|
PM25 float32 `json:"pm2_5"`
|
||||||
PM10 float32 `json:"pm10"`
|
PM10 float32 `json:"pm10"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
79
node1.c
79
node1.c
|
|
@ -15,9 +15,9 @@
|
||||||
#include <hardware/watchdog.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
|
||||||
// #define LOOP_INTERVAL_MS 10000
|
// #define LOOP_INTERVAL_MS 10000
|
||||||
#define LOOP_INTERVAL_MS 30000
|
// #define LOOP_INTERVAL_MS 30000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Balcony Weather Station Node 1
|
* Balcony Weather Station Node 1
|
||||||
|
|
@ -58,8 +58,8 @@ static bool cb_24h(__unused struct repeating_timer *t) {
|
||||||
static tcp_client_config tcp_config;
|
static tcp_client_config tcp_config;
|
||||||
static bool wifi_connected = false;
|
static bool wifi_connected = false;
|
||||||
|
|
||||||
// static pms5003_config pms_config;
|
static pms5003_config pms_config;
|
||||||
// static pms5003_reading current_pms5003_reading;
|
static pms5003_reading current_pms5003_reading;
|
||||||
|
|
||||||
static int8_t readings_index = 0;
|
static int8_t readings_index = 0;
|
||||||
static bme280_config bem_config;
|
static bme280_config bem_config;
|
||||||
|
|
@ -91,50 +91,50 @@ bool wifi_init(void) {
|
||||||
static bool cb_30(__unused struct repeating_timer *t) {
|
static bool cb_30(__unused struct repeating_timer *t) {
|
||||||
comms_led_blink();
|
comms_led_blink();
|
||||||
printf("cb_30: %d\n", readings_index);
|
printf("cb_30: %d\n", readings_index);
|
||||||
// if (readings_index >= 10) {
|
|
||||||
// printf("Preparing data to send\n");
|
|
||||||
// readings_index = 0;
|
|
||||||
|
|
||||||
// Calculate average BME280 reading
|
|
||||||
// printf("Tempature: %.2f\n", current_bem280_reading.temperature);
|
|
||||||
// printf("Pressure: %.2f\n", current_bem280_reading.pressure);
|
|
||||||
// printf("Humidity: %.2f\n", current_bem280_reading.humidity);
|
|
||||||
|
|
||||||
// printf("PM1: %.2f\n", current_pms5003_reading.pm1);
|
|
||||||
// printf("PM2.5: %.2f\n", current_pms5003_reading.pm2_5);
|
|
||||||
// printf("PM10: %.2f\n", current_pms5003_reading.pm10);
|
|
||||||
|
|
||||||
// Send to backend server if WiFi is connected
|
|
||||||
|
|
||||||
// Read BME280
|
// Read BME280
|
||||||
printf("Making BME280 Reading\n");
|
printf("Making BME280 Reading\n");
|
||||||
current_bem280_reading = bme280_read(&bem_config);
|
current_bem280_reading = bme280_read(&bem_config);
|
||||||
|
|
||||||
|
|
||||||
// if (readings_index == 2) {
|
if (readings_index == 2) {
|
||||||
// printf("Warming up PMSS5003\n");
|
printf("Warming up PMSS5003\n");
|
||||||
// pms5003_warmup(&pms_config);
|
pms5003_warmup(&pms_config);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (readings_index == 4) {
|
if (readings_index == 4) {
|
||||||
// printf("Starting reads on PMSS5003\n");
|
printf("Starting reads on PMSS5003\n");
|
||||||
// pms5003_start_reading(&pms_config);
|
pms5003_start_reading(&pms_config);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (readings_index == 6) {
|
if (readings_index == 6) {
|
||||||
// printf("Finished reading PMSS5003\n");
|
printf("Finished reading PMSS5003\n");
|
||||||
// current_pms5003_reading = pms5003_finish_reading(&pms_config);
|
current_pms5003_reading = pms5003_finish_reading(&pms_config);
|
||||||
// }
|
// TODO: send data to backend server if WiFi is connected
|
||||||
|
// printf("PM1: %.2f\n", current_pms5003_reading.pm1);
|
||||||
|
// printf("PM2.5: %.2f\n", current_pms5003_reading.pm2_5);
|
||||||
|
// printf("PM10: %.2f\n", current_pms5003_reading.pm10);
|
||||||
|
}
|
||||||
|
|
||||||
readings_index++;
|
readings_index++;
|
||||||
if (wifi_connected) {
|
if (readings_index >= 10) {
|
||||||
|
readings_index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!wifi_connected) {
|
||||||
|
printf("WiFi not connected, skipping send\n");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
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 temperature, pressure, and humidity to backend server...\n");
|
||||||
printf("MSG: %s", msg);
|
printf("MSG: %s", msg);
|
||||||
bool success = tcp_client_send_message(&tcp_config, msg);
|
bool success = tcp_client_send_message(&tcp_config, msg);
|
||||||
if (success) {
|
if (success) {
|
||||||
|
|
@ -142,9 +142,26 @@ static bool cb_30(__unused struct repeating_timer *t) {
|
||||||
comms_led_blink();
|
comms_led_blink();
|
||||||
} else {
|
} else {
|
||||||
printf("✗ Failed to send data\n");
|
printf("✗ Failed to send data\n");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send PM readings
|
||||||
|
if (readings_index == 6) {
|
||||||
|
snprintf(msg, sizeof(msg),
|
||||||
|
"M02,%.2f,%.2f,%2f\n",
|
||||||
|
current_pms5003_reading.pm1,
|
||||||
|
current_pms5003_reading.pm2_5,
|
||||||
|
current_pms5003_reading.pm10);
|
||||||
|
printf("Sending particulate matter readings to backend server...\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 {
|
} else {
|
||||||
printf("WiFi not connected, skipping send\n");
|
printf("✗ Failed to send data\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue