Skip to content

Instantly share code, notes, and snippets.

@Nickztar
Created June 5, 2023 09:28
Show Gist options
  • Select an option

  • Save Nickztar/d5e90a33f8abff6a8821088af44dfe41 to your computer and use it in GitHub Desktop.

Select an option

Save Nickztar/d5e90a33f8abff6a8821088af44dfe41 to your computer and use it in GitHub Desktop.
var options = new MqttClientOptionsBuilder()
.WithWebSocketServer("some ws server")
.WithTls(new MqttClientOptionsBuilderTlsParameters { UseTls = true, SslProtocol = SslProtocols.Tls12 })
.WithCredentials("some credential", "some credential")
.WithClientId("some clientid")
.WithCleanSession()
.WithTimeout(TimeSpan.FromSeconds(100))
.Build();
try
{
await mqttClient.ConnectAsync(options, CancellationToken.None);
}
catch (Exception ex)
{
_logger.LogError(ex, "Connecting to MQTT WebSocket Server failed");
}
_logger.LogInformation("MQTT Connected: " + mqttClient.IsConnected);
return mqttClient.IsConnected;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment