I am running Really Small Message Broker (RSMB) 1.3.0.2 with support for MQTT-SN. I have a Arduino client talking to it via MQTT-SN protocol.
Arduino is a sleeping client - battery operated device. Here is how it works:
- after startup, connects to broker
- for each sensor value it registers topic and publishes first measurement in QOS 1 (in this example there are 3 sensor values) 2.1 each register and publish message is acknowledged by the broker
- disconnects from broker with duration - indicating it is just going to sleep
- after wake up it reconnects again with clean session 0 (or false)
- publishes one sensor value in QOS 1
- waits publish acknowledgement from the broker - Here is problem, it does not come.
Problem is that message sent in step 5 is not acknowledged by the broker. Arduino tries to resend that message couple of times and the it gives up.
My understanding is that after re-connect with cleansession 0 all previous subscriptions are valid and also topicID to topic name mappings.
Here is RSBM log with my comments:
Client connects
20150227 152211.587 132 127.0.0.1:55701 <- MQTT-S CONNECT cleansession: 0
20150227 152211.587 1998536376 127.0.0.1:55701 XinoRf_1 -> MQTT-S CONNACK returncode 0 (0)
20150227 152211.588 CWNAN0000I Client connected to udp port 1885 from XinoRf_1 (127.0.0.1:55701)
Here start 1st topic registration and acknowledgment - its id is 1
20150227 152211.678 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S REGISTER msgid: 1 topicid: 0 topicname: net/mf/ha/
20150227 152211.678 132 127.0.0.1:55701 XinoRf_1 -> MQTT-S REGACK msgid: 1 topicid: 1 returncode: 0 (0)
Here starts send and acknowledge of a 1st message in topic 1
20150227 152211.753 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S PUBLISH msgid: 2 qos: 1 retained: 0
20150227 152211.753 1998536376 127.0.0.1:55701 XinoRf_1 -> MQTT-S PUBACK msgid: 2 (0)
Here start 2nd topic registration and acknowledgment - its id is 2
20150227 152211.753 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S REGISTER msgid: 3 topicid: 0 topicname: net/mf/ha/
20150227 152211.846 132 127.0.0.1:55701 XinoRf_1 -> MQTT-S REGACK msgid: 3 topicid: 2 returncode: 0 (0)
Here starts send and acknowledge of a 1st message in topic 2
20150227 152211.921 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S PUBLISH msgid: 4 qos: 1 retained: 0
20150227 152211.921 1998536376 127.0.0.1:55701 XinoRf_1 -> MQTT-S PUBACK msgid: 4 (0)
Here start 3rd topic registration and acknowledgment - its id is 3
20150227 152212.005 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S REGISTER msgid: 5 topicid: 0 topicname: net/mf/ha/
20150227 152212.005 132 127.0.0.1:55701 XinoRf_1 -> MQTT-S REGACK msgid: 5 topicid: 3 returncode: 0 (0)
Here starts send and acknowledge of a 1st message in topic 3
20150227 152212.080 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S PUBLISH msgid: 6 qos: 1 retained: 0
20150227 152212.080 1998536376 127.0.0.1:55701 XinoRf_1 -> MQTT-S PUBACK msgid: 6 (0)
Here Arduino sends disconnect request with duration 4000 (it does not matter what value is sent here, behaviour is same)
20150227 152212.080 1998536376 127.0.0.1:55701 XinoRf_1 <- MQTT-S DISCONNECT duration: 4000
20150227 152212.461 CWNAN0038I Disconnection request received from client XinoRf_1
20150227 152212.461 132 127.0.0.1:55701 XinoRf_1 -> MQTT-S DISCONNECT duration: 0 (0)
At this point Arduino sleeps appprox. 4 seconds
Arduino reconnects with clean session 0 - I believe all previous registrations should be kept by the broker
20150227 152217.519 132 127.0.0.1:55701 <- MQTT-S CONNECT cleansession: 0
20150227 152217.519 1998536376 127.0.0.1:55701 XinoRf_1 -> MQTT-S CONNACK returncode 0 (0)
20150227 152217.519 CWNAN0000I Client connected to udp port 1885 from XinoRf_1 (127.0.0.1:55701)
At this point Arduino is connecte
Here starts send a 2nd message in topic 1 - message never gets acknowledged by the broker.
20150227 152217.603 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S PUBLISH msgid: 7 qos: 1 retained: 0
Following messages are resent by the client
20150227 152232.595 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S PUBLISH msgid: 7 qos: 1 retained: 0
20150227 152247.575 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S PUBLISH msgid: 7 qos: 1 retained: 0
20150227 152301.577 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S PUBLISH msgid: 7 qos: 1 retained: 0
20150227 152317.536 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S PUBLISH msgid: 7 qos: 1 retained: 0
20150227 152332.516 132 127.0.0.1:55701 XinoRf_1 <- MQTT-S PUBLISH msgid: 7 qos: 1 retained: 0
Subsequently I have found there are few reported bugs on eclipse.org (where RSMB is being maintained now) which are cause of this behaviour:
- Bug 424704 - MQTT-SN broker forgets published topics
- Bug 430788 - When a client reconnects it don't receive queued messages
- Bug 430828 - If persistence is true on RSMB a MQTT-SN client don't receive messages published before its connection
Michal