Created
June 5, 2023 09:28
-
-
Save Nickztar/d5e90a33f8abff6a8821088af44dfe41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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