diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c index 5ac1b67..387824b 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/iot_mqtt_srv.c @@ -77,10 +77,12 @@ static int iot_mqtt_send(const uint8_t *buf, uint16_t len) { /* 发送 MQTT CONNECT */ static int iot_mqtt_send_connect(void) { - MQTTPacket_connectData opts = MQTTPacket_connectData_initializer; - uint8_t buf[256]; + static MQTTPacket_connectData opts; // static: 避免 85字节栈开销 + static uint8_t buf[256]; // static: 避免 256字节栈开销 int len; + opts = MQTTPacket_connectData_initializer; + opts.MQTTVersion = 4; // MQTT 3.1.1 opts.keepAliveInterval = IOT_MQTT_KEEPALIVE_SEC; opts.cleansession = 1; @@ -112,7 +114,7 @@ static int iot_mqtt_send_connect(void) { /* 发送 MQTT SUBSCRIBE */ static int iot_mqtt_send_subscribe(void) { - uint8_t buf[256]; + static uint8_t buf[256]; // static: 避免栈溢出 int len; char topic[IOT_MQTT_TOPIC_MAX_LEN]; MQTTString topics[3]; @@ -142,7 +144,7 @@ static int iot_mqtt_send_subscribe(void) { /* 发送 MQTT PUBLISH */ static int iot_mqtt_publish(const char *topic, const char *payload, uint16_t payload_len, uint8_t qos) { - uint8_t buf[IOT_MQTT_SEND_BUF_LEN]; + static uint8_t buf[IOT_MQTT_SEND_BUF_LEN]; // static: 避免 2KB 栈溢出 int len; MQTTString mqtt_topic = MQTTString_initializer; mqtt_topic.cstring = (char *)topic;