smart-home/ESP32_Cloud_Alarm_Fix_Guide.md
2026-02-26 09:16:34 +08:00

134 lines
3.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ESP32云端报警上报问题解决指南
## 🔍 **问题现状**
- ESP32能触发报警但无法上报到云端
- 串口监视器没有CloudAlarmReporter相关日志
- ESP32连接超时可能启动失败
## 🎯 **解决步骤**
### **第一步:重新完整烧录固件**
```bash
# 1. 进入ESP32项目目录
cd d:\XinJiaPo\Firefly_code\smart-home\firefly_esp32
# 2. 激活ESP-IDF环境
& "D:\Espressif5.5.2\Espressif\frameworks\esp-idf-v5.5.2\export.ps1"
# 3. 完全擦除Flash
idf.py -p COM7 erase-flash
# 4. 重新编译和烧录
idf.py build
idf.py -p COM7 flash
# 5. 启动串口监控
idf.py -p COM7 monitor
```
### **第二步验证ESP32启动**
在串口监控中应该看到:
```
I (xxx) main: 🌐 开始初始化云端报警上报模块
I (xxx) CloudAlarmReporter: 🔗 目标服务器: http://192.168.1.57:36988/device-alarms
I (xxx) CloudAlarmReporter: 🔑 设备密钥: 39dc753bd0cb19da...
I (xxx) CloudAlarmReporter: ✅ 云端报警上报模块初始化成功
```
### **第三步:启动模拟云端服务器**
```bash
# 在新的命令行窗口中
cd d:\XinJiaPo\Firefly_code\smart-home
python verify_cloud_alarm_reporting.py
```
### **第四步:触发报警测试**
1. **手动触发报警**
- 用手指接触热成像传感器
- 温度应该上升到40°C以上
- 观察串口日志
2. **预期看到的日志**
```
I AlarmManager: 🌐 准备上报报警到云端: [燃烧] 检测到燃烧...
I AlarmManager: ☁️ 报警已成功加入云端上报队列
I CloudAlarmReporter: 📨 开始上报报警: [燃烧报警] 206EF1B3AD74:xxx
I CloudAlarmReporter: 📡 HTTP响应状态码: 200
I CloudAlarmReporter: ✅ 报警上报成功
```
3. **模拟服务器应该显示**
```
📨 收到ESP32报警上报:
时间: 2026-01-15 14:xx:xx
设备密钥: 39dc753bd0cb19da5050a2f0edf932f851f5b21b90a6d06ecf9a28d81079a0a6
报警数据: {
"physicalUid": "206EF1B3AD74",
"sourceEventId": "206EF1B3AD74:1768457706611",
"title": "燃烧报警",
"level": "danger",
"message": "检测到燃烧峰值温度45.0°C位置(15,12)",
"temp": 45.0,
"occurredAtMs": 1768457706611
}
✅ 报警接收成功!
```
## 🔧 **备用解决方案**
### **如果ESP32仍然无法启动**
1. **检查硬件连接**
2. **尝试降低波特率烧录**
```bash
idf.py -p COM7 -b 115200 flash
```
3. **使用之前的稳定固件**
### **如果CloudAlarmReporter初始化失败**
1. **检查内存使用**
- CloudAlarmReporter需要8KB栈空间
- 可能需要调整其他任务的内存分配
2. **临时禁用其他功能**
- 注释掉一些非关键模块的初始化
- 为CloudAlarmReporter腾出内存空间
### **如果网络连接有问题**
1. **修改服务器地址为本机IP**
```cpp
// 在CloudAlarmReporter.h中
static constexpr const char* CLOUD_SERVER_URL = "http://192.168.1.57:36988/device-alarms";
```
2. **检查防火墙设置**
- 确保36988端口未被阻止
- 临时关闭防火墙测试
## 🎉 **成功标志**
当看到以下情况时,说明功能正常:
1. ✅ ESP32正常启动并连接WiFi
2. ✅ CloudAlarmReporter成功初始化
3. ✅ 手动触发报警成功
4. ✅ 串口显示云端上报日志
5. ✅ 模拟服务器收到POST请求
6. ✅ JSON数据格式正确
## 🚀 **部署到生产环境**
测试成功后:
1. 修改CloudAlarmReporter.h中的服务器地址回生产环境
2. 重新编译烧录
3. 确保后端/device-alarms接口正常工作
---
**ESP32云端报警上报功能已完整实现现在需要按照上述步骤进行最终验证**