MQTTnet
MQTTnet copied to clipboard
ManagedClient does not auto reconnect after wifi is reestablished
Sample ManagedClientTest (3.0.8) below does not reconnect automatically after Wifi is disabled and reenabled. Any help will be appreciated.
Update: Actually ManagedClient only recovers mqtt connection successfully under dot net platform. Under UWP or Xamarin Forms / mono platform, recovery of mqtt connection fails when reestablishing the internet connection
public static async Task RunAsync()
{
var ms = new ClientRetainedMessageHandler();
var options = new ManagedMqttClientOptions
{
ClientOptions = new MqttClientOptions
{
ClientId = "MQTTnetManagedClientTest",
Credentials = new RandomPassword(),
ChannelOptions = new MqttClientTcpOptions
{
Server = "broker.hivemq.com"
}
},
AutoReconnectDelay = TimeSpan.FromSeconds(1),
Storage = ms
};
try
{
var managedClient = new MqttFactory().CreateManagedMqttClient();
managedClient.ApplicationMessageReceivedHandler = new MqttApplicationMessageReceivedHandlerDelegate(e =>
{
Console.WriteLine(">> RECEIVED: " + e.ApplicationMessage.Topic);
});
managedClient.UseConnectedHandler(e => {
Console.WriteLine("connected..."); // Unfortunately connected won't get called after wifi is reestablished
});
await managedClient.StartAsync(options);
await managedClient.SubscribeAsync(new TopicFilter { Topic = "xyz", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
await managedClient.SubscribeAsync(new TopicFilter { Topic = "abc", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
await managedClient.PublishAsync(builder => builder.WithTopic("Step").WithPayload("3"));
Console.WriteLine("Managed client started.");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
@JanEggers You're the expert for UWP I would say :D
@SeppPenner no sry I dont have a testenvironment for that. can you provide any logs?
no sry I dont have a testenvironment for that.
Same for me. I did use UWP some day but had to do a new setup of my computer and didn't install it anymore.
Problem still exists for me. Has anybody found a solution?
Please try version 4.1.2.350 from the myget feed and let me know if the issue is fixed.
The fix for this issue is now released.