Closed trbenning closed 3 years ago
Couple things I recommend fixing/trying:
@JStuve @trbenning I also have SSL issue. Not idea what's happening.
I have similar issue. my broker is talking over ssl. On server side (broker side) I used self-signed cert signed by self-signed CA. On client side, I install the CA cert in the trusted authority. However, I always get the generic uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException in .net. I can connect to the broker via MQTT.fx.
{uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException: Exception of type 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException' was thrown. at uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(Byte[] msgBytes, Int32 timeout) at uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password, Boolean willRetain, Byte willQosLevel, Boolean willFlag, String willTopic, String willMessage, Boolean cleanSession, UInt16 keepAlivePeriod) at uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password)
The code to create the client is as below:
X509Certificate2 caCert = new X509Certificate2(Directory.GetCurrentDirectory() + "/Certs/Development/RootCA.crt");
MqttClient client = new MqttClient(brokerHostName, 443, true, caCert, null, MqttSslProtocols.TLSv1_2);
string clientId = Guid.NewGuid().ToString();
client.Connect(clientId, userName, password);
By checking the network trace, it seems the SSL channel has been established. However, after some time (few seconds) the connection is failed with communication error.
I also have SSL issue. Not idea what's happening.
Guys, Is there a resolution to the above problem? I'm receiving the same error
I don't think this package is being maintained anymore. I ended up converting my app to .net core, and I'm using the Microsoft.Azure.Devices package to communicate with iot hub. If .net core isn't an option, you could consider using the amqp protocol instead, and using the amqpnetlite package, which I believe is still actively supported.
Be sure that the mqtt version you set for the client is the same as what has been configured in the broker side.
xing zhou 邮箱:zhouxingapply@163.com |
---|
签名由 网易邮箱大师 定制
On 01/21/2018 14:27, sivshan wrote:
Guys, Is there a resolution to the above problem? I'm receiving the same error
ex {uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException: Exception of type 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException' was thrown.
at uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(Byte[] msgBytes, Int32 timeout) at uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password, Boolean willRetain, Byte willQosLevel, Boolean willFlag, String willTopic, String willMessage, Boolean cleanSession, UInt16 keepAlivePeriod) at uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId) at AWSIoT.Program.d__8.MoveNext() in C:\Personal\Paydatum\AWSIoT\AWSIoT\Program.cs:line 88} System.Exception {uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException}
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
Xing,
Thanks for the response. I'm using AWS MQTT as the device gateway. How do I find out that the MQTT Version for client is same as the server?
Below is my source code. I'm getting error in the bold line. Am I missing anything here?
private const string IotEndpoint = "
a2vf6ihlpxlxf6.iot.us-east-2.amazonaws.com";
///
var caCert =
X509Certificate.CreateFromSignedFile("C:\Personal\Paydatum\AWSIoT\amazonrootca.pem");
// create the client
var client = new MqttClient(IotEndpoint, BrokerPort, true,
caCert, clientCert, MqttSslProtocols.TLSv1_2); //message to publish - could be anything var message = "ganesh plz work"; string clientId = Guid.NewGuid().ToString(); //client naming has to be unique if there was more than one publisher
Thanks, Siva Manickam
On Mon, Jan 22, 2018 at 2:49 AM, xing zhou notifications@github.com wrote:
Be sure that the mqtt version you set for the client is the same as what has been configured in the broker side.
xing zhou 邮箱:zhouxingapply@163.com 签名由 网易邮箱大师 定制
On 01/21/2018 14:27, sivshan wrote:
Guys, Is there a resolution to the above problem? I'm receiving the same error
ex {uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException: Exception of type 'uPLibrary.Networking.M2Mqtt.Exceptions.MqttCommunicationException' was thrown.
at uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(Byte[] msgBytes, Int32 timeout) at uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password, Boolean willRetain, Byte willQosLevel, Boolean willFlag, String willTopic, String willMessage, Boolean cleanSession, UInt16 keepAlivePeriod) at uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId) at AWSIoT.Program.d__8.MoveNext() in C:\Personal\Paydatum\AWSIoT\AWSIoT\Program.cs:line 88} System.Exception {uPLibrary.Networking.M2Mqtt.Exceptions. MqttCommunicationException}
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eclipse/paho.mqtt.m2mqtt/issues/53#issuecomment-359359006, or mute the thread https://github.com/notifications/unsubscribe-auth/AGJ60vfOdz6NHkC_XYzDhWhOAG3iOzDGks5tNEuUgaJpZM4N5HXN .
-- Thanks Siva Manickam 312-800-3083
When using self-signed certificates, you will need to change
var client = new MqttClient(IotEndpoint, BrokerPort, true, caCert, clientCert, MqttSslProtocols.TLSv1_2);
to
var client = new MqttClient(IotEndpoint, BrokerPort, true, caCert, clientCert, MqttSslProtocols.TLSv1_2, client_RemoteCertificateValidationCallback);
with the callback looking like
bool client_RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors){
// logic for validation here
}
This will fix your TLS connection issues.
When using self-signed certificates, you will need to change
var client = new MqttClient(IotEndpoint, BrokerPort, true, caCert, clientCert, MqttSslProtocols.TLSv1_2);
to
var client = new MqttClient(IotEndpoint, BrokerPort, true, caCert, clientCert, MqttSslProtocols.TLSv1_2, client_RemoteCertificateValidationCallback);
with the callback looking like
bool client_RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors){ // logic for validation here }
This will fix your TLS connection issues.
This worked for me. Thanks.
It doesn't seem that there's anything left to do here, so I'm closing this issue.
client_RemoteCertificateValidationCallback
y como lo agregaste al codigo me puedes ayudar tengo el mismo problema
I'm trying the following code, but no messages are ever posted to IoT Hub
I've verified that my
device.pfx
file works with the IoT Hub Device SDK, but nothing I try with MqttClient is working.Additionally, there appears to be some sort of resource leak because my cpu creeps up every time I call
client.Publish
, but never comes back down.