Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required help on connecting Websocket MQTT deployed on Azure container #131

Open
Yuvaraja06 opened this issue Sep 22, 2020 · 0 comments
Open

Comments

@Yuvaraja06
Copy link

Yuvaraja06 commented Sep 22, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant