Files
BotanicalBuddy/main/auto_alerts.h
Wang Beihong 5980e171c4 feat:新增MQTT控制组件和自动告警系统
- 实现MQTT控制功能,处理水泵和灯光控制指令
- 新增土壤湿度和光照强度自动告警系统,阈值可配置
- 新建MQTT控制、自动告警和阈值管理相关文件
- 更新主应用,集成MQTT和自动控制功能
- 新增传感器数据与控制状态遥测上报
- 引入NVS和应用存储分区配置
2026-03-07 02:43:30 +08:00

49 lines
1.2 KiB
C

#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "auto_ctrl_thresholds.h"
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
AUTO_ALERT_METRIC_SOIL_MOISTURE = 1,
AUTO_ALERT_METRIC_LIGHT_INTENSITY = 2,
} auto_alert_metric_t;
typedef enum {
AUTO_ALERT_STATE_NORMAL = 0,
AUTO_ALERT_STATE_ALARM = 1,
} auto_alert_state_t;
typedef struct {
auto_alert_metric_t metric;
auto_alert_state_t state;
float value;
float threshold;
int64_t timestamp_ms;
} auto_alert_event_t;
typedef void (*auto_alert_callback_t)(const auto_alert_event_t *event, void *user_ctx);
// Reset internal state at boot.
void auto_alerts_init(void);
// Register callback sink (e.g. MQTT publisher). Passing NULL clears callback.
esp_err_t auto_alerts_register_callback(auto_alert_callback_t callback, void *user_ctx);
// Evaluate current sensor values and emit edge-triggered alert events.
void auto_alerts_evaluate(bool soil_valid,
float soil_moisture_pct,
bool light_valid,
float light_lux,
const auto_ctrl_thresholds_t *thresholds);
#ifdef __cplusplus
}
#endif