修复mqtt消息历史分页问题

This commit is contained in:
2025-05-30 18:15:27 +08:00
parent 5612b2e782
commit d0a550cab6
4 changed files with 127 additions and 59 deletions

View File

@@ -196,22 +196,35 @@ void mqtt_publish_ack(
bool success,
const char* message,
RobotStatus current_robot_status_at_ack,
const char* ack_context_spot_id
const char* ack_context_spot_id,
const char* command_ack_chinese_value
) {
if (!task_id) {
Serial.println("无法发送ACK: taskId 为空");
return;
}
StaticJsonDocument<256> doc;
if (!command_ack_chinese_value) {
Serial.println("无法发送ACK: command_ack_chinese_value 为空");
// 或者根据实际情况决定是否发送一个不带 command_ack 的ACK但后端可能不认
return;
}
StaticJsonDocument<384> doc; // 适当调整JSON文档大小
doc["robotUid"] = DEVICE_UID;
doc["taskId"] = task_id;
doc["status"] = success ? "SUCCESS" : "FAILURE";
// 关键修改符合后端期望的ACK格式
doc["command_ack"] = command_ack_chinese_value; // 使用传入的中文描述
doc["task_id"] = atol(task_id); // 将 task_id (字符串) 转换为 long (数字类型)
// 注意:如果 task_id 本身就应该是数字类型传来,则更好
// 但当前task_id通常作为字符串处理这里做转换
// 后端期望 task_id 是数字
doc["success"] = success; // 布尔类型
if (message) doc["message"] = message;
doc["actualRobotStatus"] = robotStatusToString(current_robot_status_at_ack);
if (ack_context_spot_id) {
doc["spotId"] = ack_context_spot_id; // 在ACK上下文中关联spotId
doc["spotId"] = ack_context_spot_id;
}
// 根据之前的讨论ACK中不发送errorCode字段
String jsonBuffer;
serializeJson(doc, jsonBuffer);