feat(vd960DBN): MQTT/TCP report_config 支持完整7参数配置

- 新增 ReportConfig 结构体 (sensor_type/enable/once/env_eval/interval/ack_required/timeout)
- net_srv.c: MQTT report_config handler — 查询/设置均返回完整配置JSON
- tcp_json_srv.c: TCP JSON handle_report_config 同步升级,兼容旧 active_report
- iot_mqtt_srv.c: g_report_active → g_report_cfg.enable
- g_report_active 全局变量替换为 g_report_cfg 结构体
This commit is contained in:
wangfq
2026-07-07 18:39:45 +08:00
parent cd92f3e0c3
commit a7de4dfcde
4 changed files with 162 additions and 26 deletions
@@ -1251,7 +1251,74 @@ void manage_mqtt_recv_message(char * msg, int length)
NVIC_SystemReset();
return;
}
// --- report_config ---
if(strcmp(cmd_str, "report_config") == 0) {
char *data_buf = (char *)malloc(512);
if(data_buf) {
memset(data_buf, 0, 512);
simple_parse_json(msg, "\"data\"", data_buf);
if(strlen(data_buf) > 0) {
// sensor_type (int)
memset(tmp, 0, sizeof(tmp));
simple_parse_json(data_buf, "\"sensor_type\"", tmp);
if(strlen(tmp) > 0) g_report_cfg.sensor_type = (uint8_t)strtoul(tmp, NULL, 10);
// enable (bool)
memset(tmp, 0, sizeof(tmp));
simple_parse_json(data_buf, "\"enable\"", tmp);
if(strlen(tmp) > 0) g_report_cfg.enable = (uint8_t)(strstr(tmp, "true") ? 1 : 0);
// once (bool)
memset(tmp, 0, sizeof(tmp));
simple_parse_json(data_buf, "\"once\"", tmp);
if(strlen(tmp) > 0) g_report_cfg.once = (uint8_t)(strstr(tmp, "true") ? 1 : 0);
// env_eval (bool)
memset(tmp, 0, sizeof(tmp));
simple_parse_json(data_buf, "\"env_eval\"", tmp);
if(strlen(tmp) > 0) g_report_cfg.env_eval = (uint8_t)(strstr(tmp, "true") ? 1 : 0);
// interval (int)
memset(tmp, 0, sizeof(tmp));
simple_parse_json(data_buf, "\"interval\"", tmp);
if(strlen(tmp) > 0) g_report_cfg.interval = (uint16_t)strtoul(tmp, NULL, 10);
// ack_required (bool)
memset(tmp, 0, sizeof(tmp));
simple_parse_json(data_buf, "\"ack_required\"", tmp);
if(strlen(tmp) > 0) g_report_cfg.ack_required = (uint8_t)(strstr(tmp, "true") ? 1 : 0);
// timeout (int)
memset(tmp, 0, sizeof(tmp));
simple_parse_json(data_buf, "\"timeout\"", tmp);
if(strlen(tmp) > 0) g_report_cfg.timeout = (uint16_t)strtoul(tmp, NULL, 10);
}
free(data_buf);
}
char resp[400];
snprintf(resp, sizeof(resp),
"{\"msg_id\":%lu,\"cmd\":\"report_config\","
"\"ts\":%lu,\"code\":0,\"msg\":\"success\","
"\"data\":{"
"\"sensor_type\":%d,\"enable\":%s,\"once\":%s,\"env_eval\":%s,"
"\"interval\":%u,\"ack_required\":%s,\"timeout\":%u}}",
msg_id, mstick() / 1000,
g_report_cfg.sensor_type,
g_report_cfg.enable ? "true" : "false",
g_report_cfg.once ? "true" : "false",
g_report_cfg.env_eval ? "true" : "false",
g_report_cfg.interval,
g_report_cfg.ack_required ? "true" : "false",
g_report_cfg.timeout);
mqtt_publish(resp_topic, resp, 1);
PRINT("IOT: report_config enable=%d interval=%u sensor=%d\n",
g_report_cfg.enable, g_report_cfg.interval, g_report_cfg.sensor_type);
return;
}
// --- 未支持的命令 ---
{
char resp[256];