Unable to connect using M2Mqtt Unity

I am currently trying to connect to my free cloud hivemq cluster using M2Mqtt Unity. However, I keep getting a connection exception. The cluster url, port, username, and password are correct. I tried using MQTTnet in another script and it worked.

I would like to know if there are any restrictions when it comes to M2Mqtt Unity? And how can I resolve this? Thank you!

Hello @YC-Michael ,

Thank you for the outreach!

While at this time we do not have known restrictions for M2MQTT Unity, there are some requirements when attempting a connection to a HiveMQ Cloud broker. Namely, the connecting client must support TLS, and TLS-SNI.

Additionally, some connecting clients require the provisioning of a server certificate file. This can be obtained directly through this link, or via our frequently asked questions page here.

If this does not resolve the issue you are encountering during connection, please feel free to provide the specific error you are receiving when attempting connection, or other supporting logs that may help us identify the reason for the connection failure.

Best,
Aaron from the HiveMQ Team

This was the error thrown.

Also, may I know where or how can i get the private key.pem as i will need to convert the server pem to pfx

Hello @YC-Michael,

Thank you for reaching out. To obtain the root certificate, you can download it here. However, it’s important to note that as a root CA certificate, there is no private key available.

In order to better assist you with the Unity-related issue, could you please provide the .cs file for your Unity project and share the instructions you followed for the PFX? This additional information will help us gain a clearer understanding of the challenges you are facing.

Thank you for your cooperation, and we look forward to resolving this matter for you.

Best regards,
Dasha from HiveMQ Team

I create cert file from: HiveMQ Platform How-Tos :: HiveMQ Documentation
and code:

var cert = X509Certificate.CreateFromCertFile(@"Assets/hivemq-server.crt");
client = new MqttClient(brokerAddress, brokerPort, isEncrypted, cert, null, MqttSslProtocols.TLSv1_2);

and then:
image

HiveMQ Team help this?

Hello @hmchau

It seems you are following the wrong path here, you don’t need to create the certificate to connect to HiveMQ Cloud, you need to obtain the root certificate that can be downloaded here and use it in your code.

Kind regards,
Diego from HiveMQ Team