todo_list
This commit is contained in:
@@ -165,6 +165,43 @@ class MQTTManager:
|
||||
logger.info(f"已取消订阅设备 {device_id} 状态")
|
||||
except Exception as e:
|
||||
logger.error(f"取消订阅设备状态失败: {str(e)}")
|
||||
|
||||
def send_todo_command(self, device_id: str, action: str, todo_data: Dict[str, Any]) -> bool:
|
||||
"""
|
||||
发送待办事项命令
|
||||
|
||||
Args:
|
||||
device_id: 设备ID
|
||||
action: 动作类型 (create, update, delete)
|
||||
todo_data: 待办事项数据
|
||||
|
||||
Returns:
|
||||
是否发送成功
|
||||
"""
|
||||
if not self.connected:
|
||||
logger.error("MQTT未连接,无法发送待办事项命令")
|
||||
return False
|
||||
|
||||
try:
|
||||
topic = f"esp32/{device_id}/todo"
|
||||
payload = {
|
||||
"type": "todo",
|
||||
"action": action,
|
||||
"data": todo_data,
|
||||
"timestamp": int(time.time())
|
||||
}
|
||||
|
||||
result = self.client.publish(topic, json.dumps(payload))
|
||||
if result.rc == mqtt.MQTT_ERR_SUCCESS:
|
||||
logger.info(f"成功向设备 {device_id} 发送待办事项命令: {action}")
|
||||
return True
|
||||
else:
|
||||
logger.error(f"向设备 {device_id} 发送待办事项命令失败,错误码: {result.rc}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"发送待办事项命令失败: {str(e)}")
|
||||
return False
|
||||
|
||||
# 全局MQTT管理器实例
|
||||
mqtt_manager = MQTTManager()
|
||||
Reference in New Issue
Block a user