endpoints for pressure and humidity
This commit is contained in:
@@ -2,23 +2,55 @@
|
||||
#include "ygg_http_routes.h"
|
||||
|
||||
extern float last_temperature;
|
||||
extern float last_pressure;
|
||||
extern float last_humidity;
|
||||
|
||||
esp_err_t ygg_get_temp_handler(httpd_req_t *req)
|
||||
esp_err_t ygg_get_handler(httpd_req_t *req)
|
||||
{
|
||||
float current_temp = last_temperature;
|
||||
char response_json[64];
|
||||
snprintf(response_json, sizeof(response_json), "{\"temperature\": %.1f}", current_temp);
|
||||
ygg_http_user_ctx *user_ctx = req->user_ctx;
|
||||
float current_val = *user_ctx->param_val;
|
||||
snprintf(response_json, sizeof(response_json),
|
||||
"{\"%s\": %.1f}", user_ctx->param_name, current_val);
|
||||
|
||||
httpd_resp_set_type(req, "application/json");
|
||||
|
||||
httpd_resp_send(req, response_json, HTTPD_RESP_USE_STRLEN);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static ygg_http_user_ctx temp_ctx = {
|
||||
.param_name = "temperature",
|
||||
.param_val = &last_temperature
|
||||
};
|
||||
|
||||
const httpd_uri_t ygg_temp_uri = {
|
||||
.uri = "/temp",
|
||||
.method = HTTP_GET,
|
||||
.handler = ygg_get_temp_handler,
|
||||
.user_ctx = NULL
|
||||
.handler = ygg_get_handler,
|
||||
.user_ctx = &temp_ctx
|
||||
};
|
||||
|
||||
static ygg_http_user_ctx press_ctx = {
|
||||
.param_name = "pressure",
|
||||
.param_val = &last_pressure
|
||||
};
|
||||
|
||||
const httpd_uri_t ygg_press_uri = {
|
||||
.uri = "/press",
|
||||
.method = HTTP_GET,
|
||||
.handler = ygg_get_handler,
|
||||
.user_ctx = &press_ctx
|
||||
};
|
||||
|
||||
static ygg_http_user_ctx hum_ctx = {
|
||||
.param_name = "humidity",
|
||||
.param_val = &last_humidity
|
||||
};
|
||||
|
||||
const httpd_uri_t ygg_hum_uri = {
|
||||
.uri = "/hum",
|
||||
.method = HTTP_GET,
|
||||
.handler = ygg_get_handler,
|
||||
.user_ctx = &hum_ctx
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user