eclipse/paho.mqtt.m2mqtt

Required help on connecting Websocket MQTT deployed on Azure container

Yuvaraja06 opened this issue · 0 comments

Hi,

We deployed the mosquito mqtt con Azure cloud. Able to use Python script to connect to broker using Certificates.
Tried different approach on C# code. But unable to do it. Connection was happening but Received Ack is not valid so its throwing error as not received response packet.

` import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))

client.subscribe("#")

def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))

client = mqtt.Client(transport="websockets")
client.on_connect = on_connect
client.on_message = on_message

client.tls_set(ca_certs='ca.crt', certfile='client4.crt', keyfile='client4.key', cert_reqs=mqtt.ssl.CERT_NONE, tls_version=mqtt.ssl.PROTOCOL_TLS, ciphers=None)
client.connect("xxxx.azurecontainer.io", 443, 60)
client.publish("paho/temperature", 23.2)
client.publish("paho/temperature", 23.3)
client.publish("paho/temperature", 23.4) `

The C# code created a private key using CA certificate, Client.crt and Client4.key. Then used that Private key to connect.

` string testkey = @"C:\Certificates\ClientPrivate2.pfx";
string Broker = "xxxx.azurecontainer.io";
X509Certificate2 certificate2 = new X509Certificate2(testkey,"password");

var mqttClient = new MqttClient(Broker,
port,
true,
X509Certificate.CreateFromCertFile(CaFile),
//X509Certificate2.CreateFromCertFile(CertFile),
certificate2,
MqttSslProtocols.TLSv1_0, ValidateServerCertificate);
mqttClient.ProtocolVersion = MqttProtocolVersion.Version_3_1_1;
mqttClient.MqttMsgPublishReceived += MqttClient_MqttMsgPublishReceived;
mqttClient.ConnectionClosed += MqttClient_ConnectionClosed;
mqttClient.Connect("Testing");
`
Please help on this, thank you.