refactor(vd960DBN): 去掉 heartbeat JSON 上报, MQTT PINGREQ 已保活

heartbeat 是单向设备上报, 平台不回复; MQTT PINGREQ/PINGRESP
已是双向保活。loop_data 按 g_report_cfg.interval 上报即可。

删除: iot_send_heartbeat() 函数 (省 ~40行 + BSS payload[512]→栈)
This commit is contained in:
wangfq
2026-07-23 15:28:10 +08:00
parent bdc2720d96
commit 29d1f6a783
@@ -38,7 +38,7 @@ extern uint8_t SocketId_TCP; // from net_srv.c, MQTT socket created by WC
uint8_t g_iot_socket = 0xFF; // MQTT TCP socket ID
IotMqttState g_iot_state = IOT_STATE_DISCONNECTED;
uint8_t g_iot_msg_id = 0; // MQTT packet identifier
static uint32_t _iot_last_heartbeat = 0; // 上次心跳时刻 (ms)
static uint32_t _iot_last_heartbeat = 0; // 上次 PINGREQ 时刻 (ms), MQTT 保活
static uint32_t _iot_reconnect_deadline = 0;
static uint32_t _iot_reconnect_backoff = 0;
static uint32_t _iot_connect_start = 0; // TCP connect 开始时刻
@@ -814,35 +814,6 @@ void iot_mqtt_publish_sensor(void) {
}
}
/*===========================================================================
* 心跳上报
*===========================================================================*/
static void iot_send_heartbeat(void) {
if (g_iot_state != IOT_STATE_READY) return;
char payload[512];
uint8_t loop_ok[4] = {1, 1, 1, 1};
uint8_t i;
for (i = 0; i < 4; i++) {
/* 简化: 读取线圈状态 */
loop_ok[i] = 1; // TODO: 从 Loop MCU 获取实际状态
}
snprintf(payload, sizeof(payload),
"{\"msg_id\":%lu,\"cmd\":\"heartbeat\","
"\"ts\":%lu,\"data\":{"
"\"uptime\":%lu,\"loop_status\":[%s,%s,%s,%s],"
"\"net_status\":true,\"iot_status\":true}}",
(unsigned long)(g_iot_msg_id + 1), dev_time_now(),
mstick() / 1000,
loop_ok[0] ? "true" : "false", loop_ok[1] ? "true" : "false",
loop_ok[2] ? "true" : "false", loop_ok[3] ? "true" : "false");
char topic[IOT_MQTT_TOPIC_MAX_LEN];
snprintf(topic, sizeof(topic), "dld960/%s/dev", g_iot_dev_serial);
iot_mqtt_publish(topic, payload, strlen(payload), 0);
}
/*===========================================================================
* 连接管理
*===========================================================================*/
@@ -964,7 +935,8 @@ void iot_mqtt_poll(void) {
g_iot_state = IOT_STATE_MQTT_CONNECTING;
}
/* MQTT Keepalive — PINGREQ */
/* MQTT Keepalive — PINGREQ (60s, broker 不回 → TCP 超时 → 重连)
loop_data 按平台下发 g_report_cfg.interval 上报, 无需额外 heartbeat JSON */
if (g_iot_state == IOT_STATE_READY) {
uint32_t now = mstick();
if (now - _iot_last_heartbeat > IOT_MQTT_HEARTBEAT_MS) {
@@ -972,8 +944,6 @@ void iot_mqtt_poll(void) {
int ping_len = MQTTSerialize_pingreq(ping_buf, sizeof(ping_buf));
iot_mqtt_send(ping_buf, (uint16_t)ping_len);
_iot_last_heartbeat = now;
// 心跳上报
iot_send_heartbeat();
}
}
}