# Unable to connect using M2Mqtt Unity

**URL:** <https://community.hivemq.com/t/unable-to-connect-using-m2mqtt-unity/2712>\
**Category:** HiveMQ Cloud\
**Created:** [February 15, 2024, 1:10pm UTC](https://community.hivemq.com/t/unable-to-connect-using-m2mqtt-unity/2712 "2024-02-15T13:10:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![YC-Michael](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/yc-michael/32/917_2.png) [@YC-Michael](https://community.hivemq.com/u/YC-Michael)\
**Post date:** [February 15, 2024, 1:10pm UTC](https://community.hivemq.com/t/unable-to-connect-using-m2mqtt-unity/2712/1 "2024-02-15T13:10:47Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![AaronTLFranz](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/aarontlfranz/32/638_2.png) [@AaronTLFranz](https://community.hivemq.com/u/AaronTLFranz)\
**Post date:** [February 15, 2024, 3:21pm UTC](https://community.hivemq.com/t/unable-to-connect-using-m2mqtt-unity/2712/2 "2024-02-15T15:21:25Z")

</div>

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](https://letsencrypt.org/certs/isrgrootx1.pem) link, or via our frequently asked questions page [here](https://community.hivemq.com/t/frequently-asked-questions/514).

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

---

<div class="post-metadata">

**Author:** ![YC-Michael](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/yc-michael/32/917_2.png) [@YC-Michael](https://community.hivemq.com/u/YC-Michael)\
**Post date:** [February 15, 2024, 4:28pm UTC](https://community.hivemq.com/t/unable-to-connect-using-m2mqtt-unity/2712/3 "2024-02-15T16:28:34Z")

</div>

![image](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/2d65c1d17cee8b112209a286b269b0925558000e.png)

This was the error thrown.

---

<div class="post-metadata">

**Author:** ![YC-Michael](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/yc-michael/32/917_2.png) [@YC-Michael](https://community.hivemq.com/u/YC-Michael)\
**Post date:** [February 16, 2024, 9:22am UTC](https://community.hivemq.com/t/unable-to-connect-using-m2mqtt-unity/2712/4 "2024-02-16T09:22:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daria\_H](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Daria\_H](https://community.hivemq.com/u/Daria_H)\
**Post date:** [February 23, 2024, 3:52pm UTC](https://community.hivemq.com/t/unable-to-connect-using-m2mqtt-unity/2712/5 "2024-02-23T15:52:09Z")

</div>

Hello @YC-Michael,

Thank you for reaching out. To obtain the root certificate, you can download it [here](https://letsencrypt.org/certs/isrgrootx1.pem). 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

---

<div class="post-metadata">

**Author:** ![hmchau](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hmchau](https://community.hivemq.com/u/hmchau)\
**Post date:** [April 20, 2024, 9:02am UTC](https://community.hivemq.com/t/unable-to-connect-using-m2mqtt-unity/2712/6 "2024-04-20T09:02:56Z")

</div>

I create cert file from: [HiveMQ Platform How-Tos :: HiveMQ Documentation](https://docs.hivemq.com/hivemq/latest/user-guide/howtos.html)  
and code:

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

```

and then:  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/df22c7dfb597a198f578b56d175f1911578ad57c.png)

HiveMQ Team help this?

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://community.hivemq.com/u/Diego)\
**Post date:** [April 24, 2024, 12:51pm UTC](https://community.hivemq.com/t/unable-to-connect-using-m2mqtt-unity/2712/7 "2024-04-24T12:51:30Z")

</div>

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](https://letsencrypt.org/certs/isrgrootx1.pem) and use it in your code.

Kind regards,  
Diego from HiveMQ Team
