mqtt_client
mqtt_client copied to clipboard
MQTT Connection unstable when signal change between WiFi and Mobile
Every time I connect MQTT in the WiFi circumstance, it works very good. But when I close WiFi, even mobile signal is very good, my MQTT connection still get something wrong, I can not publish anything...
I've tried so many different ways to establish a stable connection. Like when my app founds signal is changed, it will disconnect the AWS MQTT and reconnect again in the new signal circumstance. But it's still not stable than I thought.
Does anyone have encountered this situation before? Or how can I fix it? Thanks a lot if anyone can help me!
You can set the client to auto reconnect if the network is lost, it will keep trying to connect until it gets a connection which from the above sounds as though you have done this.
However this is triggered on loss of network, say when you move from wireless and re establish on mobile, there is no way to avoid this as its the Dart/flutter runtime that triggers network connection/disconnection not the client. If your network is unstable then the client connection to your broker will be unstable.
Yes, I have done it before. Because I found that when I realized that my message could not be published, I checked the client and it showed "connected". So the client status cannot show the actual situation.... and I have no idea where can I get the actual connection status Still Thanks for your reply~
The status should be correct, you will have to refresh it before you use it of course, don't cache things like this.
You don't say why your message could not be published, what's in the client logs?
You should handle the disconnect and reconnect yourself by checking when the connection type changes. IT works 100% then.