shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
548 stars 176 forks source link

Get old state from mqtt when app is destroyed #119

Closed guitar9 closed 4 years ago

guitar9 commented 5 years ago

Hello first thank you for this beautiful library. I build a app where I can show a state of my lamp. I connect to mqtt broker when I start the app an subscripe to the topic light. When I close the app an open it again and and the state of the lamp changed when i closed the app. Everything works fine. But when I destroy the app and connect again to mqtt broker, I dont get the new state. Only when I publish a new message. The state of the lamp changes again. Sombody can help me?

shamblett commented 5 years ago

Ok, can you turn on logging and post the log from when you reconnect again, remember that when you have reconnected you have to subscribe again, when the client is destroyed it loses its subscriptions, you shouldn't have to publish anything though.

guitar9 commented 4 years ago

I tested it with flutter build apk --debug. And I get dont get the new message. When I restart the app and subscribe the topic agian. Maybe is has something to do with qos? I am will turn on the logging and post the output

I published the new message when the app was closed

guitar9 commented 4 years ago

I found the error. I must publish the message with retained on. I tested it with mqtt.fx. Can I somehow publish the message with this library with retained on?

shamblett commented 4 years ago

There's a retain option flag on the publishMessage client method, set this to true when you publish. You can also reset the startClean() option on the connect message if you need it.