在 IoT 设备信息表中增加:
AutoControlEnabled bit NOT NULL
CONSTRAINT DF_AutoControlEnabled DEFAULT (1);
字段含义:
字段名称:AutoControlEnabled
类型:bit
默认值:1
说明:Pico设备当前是否启用自动温控
1 = 已启用
0 = 已关闭
已有数据需要统一初始化为:
UPDATE 对应设备表
SET AutoControlEnabled = 1
WHERE AutoControlEnabled IS NULL;
public bool AutoControlEnabled { get; set; } = true;
接口 JSON 字段建议统一使用:
{
"autoControlEnabled": true
}
现有接口:
GET /api/EquipInfoApi/GetEquipInfoByIP?IPADDR=172.28.100.23
每条设备信息中增加:
{
"eid": "60efd6e1-4222-4c3b-8ab4-66a63d7c2a60",
"itemId": "1",
"standardMin": 22,
"standardMax": 28,
"autoControlEnabled": true
}
Pico 使用 itemId="1" 对应记录的 eid 作为设备 ID。
现有接口:
PUT /api/EquipInfoApi/{eid}
Pico 计划提交:
{
"Eid": "60efd6e1-4222-4c3b-8ab4-66a63d7c2a60",
"AutoControlEnabled": true,
"MUser": "SystemUser"
}
要求:
AutoControlEnabled 和修改信息;eid 必须和 Body 中的 Eid 一致。建议后端增加专用接口,避免完整实体 PUT 导致字段被清空,例如:
PUT /api/EquipInfoApi/{eid}/AutoControl
请求:
{
"autoControlEnabled": true,
"mUser": "SystemUser"
}
返回:
{
"success": true,
"code": "200",
"msg": "自动温控状态更新成功",
"data": {
"eid": "60efd6e1-4222-4c3b-8ab4-66a63d7c2a60",
"autoControlEnabled": true
}
}
使用现有远程命令表和任务获取接口,不需要新增命令表字段。
新增 commandtype:
set_auto_control
含义:
远程开启或关闭指定 Pico 的自动温控功能
开启自动温控:
{
"enabled": true
}
关闭自动温控:
{
"enabled": false
}
因为数据库的 commandparams 是字符串,完整远程任务记录示例为:
{
"remoteid": "远程任务GUID",
"ipaddr": "172.28.100.23",
"commandtype": "set_auto_control",
"commandparams": "{\"enabled\":false}",
"mStatus": "pending"
}
Pico 同时兼容 commandparams 直接返回 JSON 对象的情况,但建议接口统一返回 JSON 字符串。
收到:
{
"commandtype": "set_auto_control",
"commandparams": "{\"enabled\":false}"
}
Pico 执行流程:
1. 校验 enabled 必须是 JSON 布尔值;
2. 修改本机运行时的自动控制状态;
3. 使用 itemId=1 对应的 eid;
4. PUT 当前 AutoControlEnabled 状态到设备信息接口;
5. 调用原有 UpdateRemoteCommand 接口更新任务结果。
成功回写:
{
"mstatus": "completed",
"execresult": "自动温控功能已关闭"
}
或者:
{
"mstatus": "completed",
"execresult": "自动温控功能已开启"
}
失败回写示例:
{
"mstatus": "failed",
"execresult": "自动温控状态更新失败:未取得设备ID"
}
1. 每次 Pico 启动时,本机自动温控默认开启;
2. Wi-Fi 连接成功后查询设备信息;
3. 获取 itemId=1 对应的温度上下限和 eid;
4. 向服务器 PUT AutoControlEnabled=true;
5. 如果开机时 Wi-Fi 连接失败,Pico继续执行本地自动温控;
6. 后续低频重连成功后,再查询设备信息并回写当前状态。
服务器数据库中的状态主要用于显示和管理,Pico 开机时不会直接使用数据库中的旧状态覆盖“默认开启”规则。