emqx / emqx-sn

EMQX MQTT-SN Gateway
https://www.emqx.com
Apache License 2.0
30 stars 20 forks source link

qos -1 issue #54

Closed cyqsign closed 6 years ago

cyqsign commented 6 years ago

I am using the paho.mqtt-sn.embedded-c and emqtt/emq-sn on Linux platform . In my test platform,there are two clients.Client A is used to publish message,and Client B is used to subscribe message. Client A public info: topic:"hello" payload:"test" qos:-1

I find Client B can not receive any message.So I trace log :

In client A Serialize publish message is :10 0C 60 00 05 00 00 68 65 6C 6C 6F 74 65 73 74 10:lenth 0C:PUBLISH FLAG 60: qos is -1 00 05:qos -1,it is topic length 00 00: packet id 68 65 6C 6C 6F : hello 74 65 73 74 :test

log in emq-sn:

14:42:21.648 [info] MQTT-SN(172.21.128.54:54279): RECV "mqtt_sn_message SN_PUBLISH, \"mqtt_sn_flags{dup=false, qos=3, retain=false, will=undefined, clean_session=undefined, topic_id_type=0}\", TopicId=5, MsgId=0, Payload=<<104,101,108,108,111,116,101,115,116>>" at state connected 14:42:21.648 [debug] MQTT-SN(172.21.128.54:54279): Receive a publish with Qos=-1

So I find problem that Emq-sn parse Topic len(00 05) into TopicId(5).And payload is changed to "hellotest"(topic+payload).This Cause Client B can not receive any message(topic is hello).Emq-sn may parse wrong.

grutabow commented 6 years ago

image From the mqtt-sn spec, there is no topic length field, 0x0005 should be topic id. So emq-sn parse the PUBLISH message in a correct way.

cyqsign commented 6 years ago

Thank you for the reply.From the mqtt-sn spec, there no topic length field. But i find the tipic length(qos = -1) in MQTTSNSerialize_publish(paho.mqtt-sn.embedded-c/MQTTSNPacket/src/MQTTSNSerializePublish.c) like this: if (topic.type == MQTTSN_TOPIC_TYPENORMAL && qos == 3) { / special arrangement for long topic names in QoS -1 publishes. The length of the topic is in the topicid field / writeInt(&ptr, topic.data.long.len); / topic length / }

I will try seeking confirmation from icraggs . Thank you again.