mirror of
https://git.beihong.wang/wangbeihong/iot-bedroom-environment-controller.git
synced 2026-04-23 15:13:05 +08:00
feat: 更新温度阈值至39.0°C,优化自动/手动模式联动功能
This commit is contained in:
@@ -130,10 +130,11 @@ static void safe_mqtt_start_task(void *pvParameters)
|
||||
ESP_LOGI(TAG, "WiFi连接成功 (IP获取可能需要更多时间),准备启动MQTT");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// 增加对 FAILED 的处理,避免死等
|
||||
if (wifi_status == WIFI_CONNECT_STATUS_FAILED) {
|
||||
ESP_LOGW(TAG, "WiFi连接明确失败,等待重连...");
|
||||
if (wifi_status == WIFI_CONNECT_STATUS_FAILED)
|
||||
{
|
||||
ESP_LOGW(TAG, "WiFi连接明确失败,等待重连...");
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
@@ -170,11 +171,11 @@ static void mqtt_app_start(void)
|
||||
// 这个任务只是等待,不需要大栈空间
|
||||
BaseType_t task_ok = xTaskCreate(safe_mqtt_start_task,
|
||||
"safe_mqtt_start",
|
||||
2048, // 修改这里:从 3072 降为 2048
|
||||
2048, // 修改这里:从 3072 降为 2048
|
||||
NULL,
|
||||
5,
|
||||
NULL);
|
||||
|
||||
|
||||
if (task_ok != pdPASS)
|
||||
{
|
||||
ESP_LOGE(TAG, "创建安全启动任务失败(内存不足),直接启动MQTT");
|
||||
@@ -441,8 +442,6 @@ extern "C"
|
||||
// MCU间的串口通信初始化
|
||||
serial_mcu_init();
|
||||
|
||||
|
||||
|
||||
mqtt_app_start(); // 启动 MQTT 客户端
|
||||
ESP_ERROR_CHECK(time_alarm_start());
|
||||
// 创建降温模式任务
|
||||
@@ -545,6 +544,15 @@ static void cooling_mode_task(void *pvParameters)
|
||||
|
||||
ESP_LOGW(TAG, "High temperature alert: %.1f°C (>%.1f°C)", current_temp, g_temperature_threshold);
|
||||
|
||||
// 延时3秒后自动关闭蜂鸣器
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
if (xControlFlagMutex != NULL && xSemaphoreTake(xControlFlagMutex, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
buzzer_control_flag = false;
|
||||
xSemaphoreGive(xControlFlagMutex);
|
||||
}
|
||||
ESP_LOGI(TAG, "蜂鸣器已自动关闭(3秒)");
|
||||
|
||||
// 发送MQTT提醒消息
|
||||
if (g_mqtt_client != NULL)
|
||||
{
|
||||
@@ -606,18 +614,7 @@ static void cooling_mode_task(void *pvParameters)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 自动通风控制模式任务
|
||||
* 监测空气质量,当空气质量大于50时自动开启风扇并发送提醒
|
||||
*/
|
||||
/* ventilation_mode_task 已移除,保留 README 文档说明,不再在代码中保留未使用的静态函数 */
|
||||
|
||||
// MQ135 task removed; provide a short stub to avoid undefined references
|
||||
void mq135_task(void *pvParameters)
|
||||
{
|
||||
ESP_LOGI("mq135_task", "mq135 task removed");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
// Remaining MQ135 implementation removed
|
||||
|
||||
@@ -643,7 +640,7 @@ extern "C"
|
||||
ESP_LOGE(TAG, "Failed to save cooling enabled: %s", esp_err_to_name(err));
|
||||
}
|
||||
|
||||
err = nvs_set_u32(nvs_handle, "temperature_threshold", (uint32_t)(g_temperature_threshold * 10));
|
||||
err = nvs_set_u32(nvs_handle, "temp_th", (uint32_t)(g_temperature_threshold * 10));
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to save temperature threshold: %s", esp_err_to_name(err));
|
||||
@@ -661,7 +658,7 @@ extern "C"
|
||||
{
|
||||
ESP_LOGI(TAG, "No cooling config found in NVS, using defaults");
|
||||
g_cooling_mode_enabled = false;
|
||||
g_temperature_threshold = 28.0f;
|
||||
g_temperature_threshold = 39.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -676,15 +673,15 @@ extern "C"
|
||||
g_cooling_mode_enabled = false;
|
||||
}
|
||||
|
||||
uint32_t temp_threshold = 280; // 28.0°C * 10
|
||||
err = nvs_get_u32(nvs_handle, "temperature_threshold", &temp_threshold);
|
||||
uint32_t temp_threshold = 390; // 39.0°C * 10
|
||||
err = nvs_get_u32(nvs_handle, "temp_th", &temp_threshold);
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
g_temperature_threshold = temp_threshold / 10.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_temperature_threshold = 28.0f;
|
||||
g_temperature_threshold = 39.0f;
|
||||
}
|
||||
|
||||
nvs_close(nvs_handle);
|
||||
|
||||
Reference in New Issue
Block a user