state information
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
idf_component_register(SRCS "thermo_sensor.c" "ygg_http_routes.c" "ygg_bmp280.c" "ygg_http_req.c" "../../common/esp32/ygg_wifi.c" "../../common/esp32/ygg_http_server.c"
|
||||
idf_component_register(SRCS "thermo_sensor.c" "ygg_http_routes.c" "ygg_bmp280.c" "ygg_http_req.c" "ygg_state.c" "../../common/esp32/ygg_wifi.c" "../../common/esp32/ygg_http_server.c"
|
||||
INCLUDE_DIRS "." "../../common/esp32")
|
||||
|
||||
@@ -11,21 +11,18 @@
|
||||
#include "ygg_http_server.h"
|
||||
#include "ygg_bmp280.h"
|
||||
#include "ygg_http_req.h"
|
||||
#include "ygg_state.h"
|
||||
|
||||
|
||||
static const char *TAG = "thermo_sensor";
|
||||
float last_temperature = 0.0f;
|
||||
float last_pressure = 0.0f;
|
||||
float last_humidity = 0.0f;
|
||||
bmp280_t dev_bmp_280;
|
||||
|
||||
void main_loop(void *pvParameters) {
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10000));
|
||||
ygg_bmp280_read_sensor(&dev_bmp_280);
|
||||
ygg_send_sensor_redouts(last_temperature,
|
||||
last_pressure,
|
||||
last_humidity);
|
||||
ygg_send_sensor_readouts(SENSOR_NAME,
|
||||
CURR_READOUT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
#include <string.h>
|
||||
#include <bmp280.h>
|
||||
#include "ygg_bmp280.h"
|
||||
|
||||
extern float last_temperature;
|
||||
extern float last_pressure;
|
||||
extern float last_humidity;
|
||||
#include "ygg_state.h"
|
||||
|
||||
void ygg_bmp280_init(bmp280_t *dev) {
|
||||
bmp280_params_t params;
|
||||
@@ -26,9 +23,9 @@ void ygg_bmp280_read_sensor(bmp280_t *dev) {
|
||||
if (bmp280_read_float(dev, &temperature, &pressure, &humidity) != ESP_OK)
|
||||
printf("Temperature/pressure reading failed\n");
|
||||
|
||||
last_temperature = temperature;
|
||||
last_pressure = pressure;
|
||||
last_humidity = humidity;
|
||||
CURR_READOUT.temperature = temperature;
|
||||
CURR_READOUT.pressure = pressure;
|
||||
CURR_READOUT.humidity = humidity;
|
||||
printf("Pressure: %.2f Pa, Temperature: %.2f C", pressure, temperature);
|
||||
if (bme280p)
|
||||
printf(", Humidity: %.2f\n", humidity);
|
||||
|
||||
@@ -106,23 +106,24 @@ char* ygg_send_post(const char *url, char *post_data) {
|
||||
int ygg_get_sensor_id(const char *sensor_name,
|
||||
const char *url);
|
||||
|
||||
void ygg_send_sensor_redouts(float temp, float press, float hum) {
|
||||
void ygg_send_sensor_readouts(const char *sensor_name,
|
||||
ygg_sensor_readout readout) {
|
||||
char post_data[64];
|
||||
int sensor_id = ygg_get_sensor_id("super_hiper_bmp280", "http://192.168.0.236:5000");
|
||||
int sensor_id = ygg_get_sensor_id(sensor_name, "http://192.168.0.236:5000");
|
||||
char url[128];
|
||||
snprintf(url, sizeof(url),
|
||||
"http://192.168.0.236:5000/api/sensors/%d/readouts", sensor_id);
|
||||
|
||||
snprintf(post_data, sizeof(post_data),
|
||||
"{\"type\":\"temperature\", \"value\":%.2f}", temp);
|
||||
"{\"type\":\"temperature\", \"value\":%.2f}", readout.temperature);
|
||||
ygg_send_post(url, post_data);
|
||||
|
||||
snprintf(post_data, sizeof(post_data),
|
||||
"{\"type\":\"pressure\", \"value\":%.2f}", press);
|
||||
"{\"type\":\"pressure\", \"value\":%.2f}", readout.pressure);
|
||||
ygg_send_post(url, post_data);
|
||||
|
||||
snprintf(post_data, sizeof(post_data),
|
||||
"{\"type\":\"humidity\", \"value\":%.2f}", hum);
|
||||
"{\"type\":\"humidity\", \"value\":%.2f}", readout.humidity);
|
||||
ygg_send_post(url, post_data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef YGG_HTTP_REQ_H
|
||||
#define YGG_HTTP_REQ_H
|
||||
|
||||
void ygg_send_sensor_redouts(float temp, float press, float hum);
|
||||
#include "ygg_state.h"
|
||||
|
||||
void ygg_send_sensor_readouts(const char *sensor_name,
|
||||
ygg_sensor_readout readout);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#include "esp_http_server.h"
|
||||
#include "ygg_http_routes.h"
|
||||
|
||||
extern float last_temperature;
|
||||
extern float last_pressure;
|
||||
extern float last_humidity;
|
||||
#include "ygg_state.h"
|
||||
|
||||
esp_err_t ygg_get_handler(httpd_req_t *req)
|
||||
{
|
||||
@@ -21,7 +18,7 @@ esp_err_t ygg_get_handler(httpd_req_t *req)
|
||||
|
||||
static ygg_http_user_ctx temp_ctx = {
|
||||
.param_name = "temperature",
|
||||
.param_val = &last_temperature
|
||||
.param_val = &CURR_READOUT.temperature
|
||||
};
|
||||
|
||||
const httpd_uri_t ygg_temp_uri = {
|
||||
@@ -33,7 +30,7 @@ const httpd_uri_t ygg_temp_uri = {
|
||||
|
||||
static ygg_http_user_ctx press_ctx = {
|
||||
.param_name = "pressure",
|
||||
.param_val = &last_pressure
|
||||
.param_val = &CURR_READOUT.pressure
|
||||
};
|
||||
|
||||
const httpd_uri_t ygg_press_uri = {
|
||||
@@ -45,7 +42,7 @@ const httpd_uri_t ygg_press_uri = {
|
||||
|
||||
static ygg_http_user_ctx hum_ctx = {
|
||||
.param_name = "humidity",
|
||||
.param_val = &last_humidity
|
||||
.param_val = &CURR_READOUT.humidity
|
||||
};
|
||||
|
||||
const httpd_uri_t ygg_hum_uri = {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "ygg_state.h"
|
||||
|
||||
ygg_sensor_readout CURR_READOUT;
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef YGG_STATE_H
|
||||
#define YGG_STATE_H
|
||||
|
||||
typedef struct {
|
||||
float temperature;
|
||||
float pressure;
|
||||
float humidity;
|
||||
} ygg_sensor_readout;
|
||||
|
||||
extern ygg_sensor_readout CURR_READOUT;
|
||||
static const char *SENSOR_NAME = "BMP_280_SENSOR_001";
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user