RT,或者說如何獲取消息來自哪個topic?
PS:我用 MQTTDeserialize_publish 解析數據的時候,得到的topicName.cstring打印出來是亂碼。
RT,或者說如何獲取消息來自哪個topic?
PS:我用 MQTTDeserialize_publish 解析數據的時候,得到的topicName.cstring打印出來是亂碼。
找到辦法了,寫出來供后來人使用:
?UINT8?????? *dup;
?UINT16????? *packetid;
?int???????? qos;
?int???????? payloadlen;
?UINT8?????? *payload;
?UINT8?????? *retained;
?MQTTString? topicName;
char topic[100];
MQTTDeserialize_publish( dup, &qos, retained, packetid, &topicName, &payload, &payloadlen, MyBuf, len );
?memcpy(topic, topicName.lenstring.data, topicName.lenstring.len);
?PRINT("topic:\"%s\"\n\r", topic);
????????????
感謝分享!