convert mqtt_client from app to lib
This commit is contained in:
parent
495d415102
commit
6d7a8b99a7
6 changed files with 154 additions and 195 deletions
21
node1.c
21
node1.c
|
|
@ -1,6 +1,7 @@
|
|||
#include "bme280.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include "pms5003.h"
|
||||
#include "mqtt_client.h"
|
||||
#include <hardware/gpio.h>
|
||||
#include <hardware/i2c.h>
|
||||
#include <hardware/uart.h>
|
||||
|
|
@ -9,10 +10,11 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LOOP_INTERVAL_MS 5000
|
||||
// TODO: put loop back to 30 seconds when done testing
|
||||
// #define LOOP_INTERVAL_MS 30000
|
||||
// 5 sec loop is for testing
|
||||
// #define LOOP_INTERVAL_MS 5000
|
||||
#define LOOP_INTERVAL_MS 30000
|
||||
|
||||
/**
|
||||
* Balcony Weather Station Node 1
|
||||
|
|
@ -46,6 +48,8 @@ void comms_led_update() {
|
|||
}
|
||||
}
|
||||
|
||||
static mqtt_client_config mqtt_config;
|
||||
|
||||
static pms5003_config pms_config;
|
||||
static pms5003_reading current_pms5003_reading;
|
||||
|
||||
|
|
@ -88,9 +92,13 @@ static bool cb_30(__unused struct repeating_timer *t) {
|
|||
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);
|
||||
|
||||
// char msg[100];
|
||||
char msg[200];
|
||||
snprintf(msg, sizeof(msg), "{\"temp\": %.2f, \"pressure\": %.2f, \"humidity\": %.2f, \"pm1\": %.2f, \"pm2_5\": %.2f, \"pm10\": %.2f}\n",
|
||||
current_bem280_reading.temperature, current_bem280_reading.pressure, current_bem280_reading.humidity,
|
||||
current_pms5003_reading.pm1, current_pms5003_reading.pm2_5, current_pms5003_reading.pm10);
|
||||
printf("Sending data to home assistant...\n");
|
||||
// TODO: Send data to home assistant
|
||||
mqtt_client_pub_message(&mqtt_config, msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -124,6 +132,8 @@ int main() {
|
|||
// Initialize communication LED
|
||||
comms_led_init();
|
||||
|
||||
mqtt_client_init(&mqtt_config, "homeassistant/sensor/bws/node1/state", "bws-node1");
|
||||
|
||||
// Setup BME280
|
||||
bme280_init(&bem_config, i2c1, 14, 15);
|
||||
|
||||
|
|
@ -136,5 +146,6 @@ int main() {
|
|||
comms_led_update();
|
||||
sleep_us(100);
|
||||
tight_loop_contents();
|
||||
mqtt_client_do_network_stuff(&mqtt_config);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue