Android Question MQTT cleansession problem

DickD

Active Member
Licensed User
From my reading I see that setting MqttConnectOptions.cleansession = false should allow messages sent while the client was closed to be received. In testing I haven't gotten this to work. Everything else works fine for sending and receiving messages.

B4X:
Sub Process_Globals
 Private mqtt As MqttClient
 Private mytopic As String
 Private serializator As B4XSerializator
 Dim mo As MqttConnectOptions
....
End sub

Sub Activity_Create(FirstTime As Boolean)
 If FirstTime Then
  mqtt.Initialize("mqtt", "...mybroker address", "...my clientID")
  mo.Initialize("username", "password")
  mo.CleanSession = False
  mqtt.Connect2(mo)
  mytopic = "TestTopic/"
...
end sub
 

DickD

Active Member
Licensed User
Theresa is a good explanation
https://www.hivemq.com/blog/mqtt-essentials-part-7-persistent-session-queuing-messages

In short: cleansession flag is used in combination with persistent sessions.
I had already read and re-read all the mqtt essentials chapters. Chapter 7 doesn't make it terribly clear but I'm guessing now that a persistent session is created if the ClientID remains the same between closing and reconnecting. I'm also assuming that it means that each subscriber needs to have a different clientID (makes sense). If that's not it then I'm still missing the point. They could have made that clearer.
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
Nice to hear, that its not terribly clear - in this situtation i always think its my problem because my english is not good enough...
I think, your assumptions are right.
 
Upvote 0

DickD

Active Member
Licensed User
Nice to hear, that its not terribly clear - in this situtation i always think its my problem because my english is not good enough...
I think, your assumptions are right.
In testing I find this is correct. A unique (i.e. persistent) clientid plus .cleansession = false are what it takes.
 
Upvote 0
Top