From 555cdb741d7d8294e44fdd836d842b077cd642ed Mon Sep 17 00:00:00 2001 From: wangfq Date: Wed, 8 Jul 2026 09:11:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(iot=5Fmqtt):=20g=5Fiot=5Fsocket=20=E6=9C=AA?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=AF=BC=E8=87=B4=20WCHNET=5FSocket?= =?UTF-8?q?Send(0xFF)=20=E7=A1=AC=E6=95=85=E9=9A=9C=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: iot_mqtt_srv.c 中 g_iot_socket 初始化为 0xFF, 仅 iot_connect_broker() 中设为 SocketId_TCP. 但内联 MQTT 模式(iot_mqtt_poll 从未调用)下该赋值永不执行. iot_mqtt_publish_sensor() 调用 iot_mqtt_send() → WCHNET_SocketSend(0xFF, ...) → HardFault → 设备重启. 修复: iot_mqtt_init() 中设置 g_iot_socket = SocketId_TCP, 该函数在 net_srv_init() flag==1 时被调用(含首次启动和每次重连). --- vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c index 874b409..acb09e7 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c @@ -587,6 +587,9 @@ void iot_mqtt_poll(void) { * 初始化 *===========================================================================*/ void iot_mqtt_init(void) { + /* 复用 net_srv.c 创建的 MQTT socket (SocketId_TCP) */ + g_iot_socket = SocketId_TCP; + /* 初始化设备序列码 (12 hex chars) */ snprintf(g_iot_dev_serial, sizeof(g_iot_dev_serial), "%02X%02X%02X%02X%02X%02X",