aliyun / iotkit-embedded

高速镜像: https://code.aliyun.com/linkkit/c-sdk
Apache License 2.0
496 stars 252 forks source link

當上傳的message size在設定內(512), IOT_MQTT_Publish有機會無法上傳 #116

Open StuartChenMoxa opened 5 years ago

StuartChenMoxa commented 5 years ago

在mqtt_example.c中 將MQTT_MSGLEN改為512

define MQTT_MSGLEN (512)

將int mqtt_client(void)的msg_pub size改為512 char msg_pub[512];

將原本要上傳的字串data: hello! start!改為以下字串 strcpy(msg_pub, "[{\"timestamp\":\"2018-12-20T04:29:13.780Z\",\"srcName\":\"My_Test_Device_1\",\"tagName\":\"di2\",\"value\":37},{\"timestamp\":\"2018-12-20T04:29:14.781Z\",\"srcName\":\"My_Test_Device_1\",\"tagName\":\"di3\",\"value\":86},{\"timestamp\":\"2018-12-20T04:29:15.782Z\",\"srcName\":\"My_Test_Device_1\",\"tagName\":\"di0\",\"value\":35},{\"timestamp\":\"2018-12-20T04:29:16.783Z\",\"srcName\":\"My_Test_Device_1\",\"tagName\":\"di1\",\"value\":96},{\"timestamp\":\"2018-12-20T04:29:11.778Z\",\"srcName\":\"My_Test_Device_1\",\"tagName\":\"di0\",\"value\":15}]");

總上傳字串486個Bytes(低於設定的512), 會顯示以下錯誤 [err] MQTTPublish(476): MQTTSerialize_publish is error, len=-2, buf_size_send=512, payloadlen=486 [err] iotx_mc_publish(2144): MQTTPublish is error, rc = -21

但MQTT_MSGLEN改成1024就可以正常上傳

fenghr1219 commented 5 years ago

image @StuartChenMoxa 您好 这里的这个len不是简单相加起来的,还包含了别的数据,您看下图片这里