refactor(vd960DBN): 缓冲区 2048→1024,单次交互不超 1KB
- IOT_MQTT_RECV_BUF_LEN: 2048 → 1024 - IOT_MQTT_SEND_BUF_LEN: 2048 → 1024 - data_json 改用宏 - iot_handle_publish 的 json[] 改 static 防栈溢出
This commit is contained in:
@@ -21,8 +21,8 @@
|
|||||||
#define IOT_MQTT_RECONNECT_MIN_MS 5000 // 最小重连间隔
|
#define IOT_MQTT_RECONNECT_MIN_MS 5000 // 最小重连间隔
|
||||||
#define IOT_MQTT_RECONNECT_MAX_MS 60000 // 最大重连间隔 (指数退避上限)
|
#define IOT_MQTT_RECONNECT_MAX_MS 60000 // 最大重连间隔 (指数退避上限)
|
||||||
#define IOT_MQTT_HEARTBEAT_MS 60000 // 心跳上报周期 (60s)
|
#define IOT_MQTT_HEARTBEAT_MS 60000 // 心跳上报周期 (60s)
|
||||||
#define IOT_MQTT_RECV_BUF_LEN 2048 // 接收缓冲区
|
#define IOT_MQTT_RECV_BUF_LEN 1024 // 接收缓冲区 (单次交互 ≤1024)
|
||||||
#define IOT_MQTT_SEND_BUF_LEN 2048 // 发送缓冲区
|
#define IOT_MQTT_SEND_BUF_LEN 1024 // 发送缓冲区 (单次交互 ≤1024)
|
||||||
#define IOT_MQTT_TOPIC_MAX_LEN 128 // Topic 最大长度
|
#define IOT_MQTT_TOPIC_MAX_LEN 128 // Topic 最大长度
|
||||||
|
|
||||||
/*===========================================================================
|
/*===========================================================================
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ static int iot_mqtt_publish(const char *topic, const char *payload,
|
|||||||
|
|
||||||
/* 处理一条收到的 MQTT PUBLISH 消息 */
|
/* 处理一条收到的 MQTT PUBLISH 消息 */
|
||||||
static void iot_handle_publish(const char *topic, uint8_t *payload, int payload_len) {
|
static void iot_handle_publish(const char *topic, uint8_t *payload, int payload_len) {
|
||||||
char json[IOT_MQTT_RECV_BUF_LEN];
|
static char json[IOT_MQTT_RECV_BUF_LEN]; // static: 避免 1KB 栈开销
|
||||||
int copy_len = payload_len < (int)sizeof(json) - 1 ? payload_len : (int)sizeof(json) - 1;
|
int copy_len = payload_len < (int)sizeof(json) - 1 ? payload_len : (int)sizeof(json) - 1;
|
||||||
memcpy(json, payload, copy_len);
|
memcpy(json, payload, copy_len);
|
||||||
json[copy_len] = '\0';
|
json[copy_len] = '\0';
|
||||||
@@ -392,7 +392,7 @@ void iot_mqtt_publish_sensor(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 构建 loop_data JSON */
|
/* 构建 loop_data JSON */
|
||||||
static char data_json[2048]; // static: 避免 2KB 栈溢出
|
static char data_json[IOT_MQTT_SEND_BUF_LEN]; // static: 避免栈溢出
|
||||||
char *p = data_json;
|
char *p = data_json;
|
||||||
int remaining = sizeof(data_json);
|
int remaining = sizeof(data_json);
|
||||||
int written;
|
int written;
|
||||||
|
|||||||
Reference in New Issue
Block a user