# STM32 HiveMQ connection issue

**URL:** <https://community.hivemq.com/t/stm32-hivemq-connection-issue/3890>\
**Category:** Uncategorized\
**Created:** [August 14, 2025, 2:21am UTC](https://community.hivemq.com/t/stm32-hivemq-connection-issue/3890 "2025-08-14T02:21:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cleonb32](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@cleonb32](https://community.hivemq.com/u/cleonb32)\
**Post date:** [August 14, 2025, 2:21am UTC](https://community.hivemq.com/t/stm32-hivemq-connection-issue/3890/1 "2025-08-14T02:21:28Z")

</div>

Hi all, I am using a custom board with STM32F7. I can connect to a local Mosquito server with certificate and username/password enabled; However, when I try to connect with HiveMQ using the generated Certificate, it is rejecting my connection with error code 5 (_MQTT\_CONNECT\_REFUSED\_NOT\_AUTHORIZED\__). I read on a forum that the reason it is rejecting the connection because I am connecting with HiveMQ’s IP Address (obtained using DNS) and not connecting directly with the HiveMQ domain name: (1ff096ae7f524a0f978cabaca991e8ca.s1.eu.hivemq.cloud), if this is the case, can i regenerate HiveMQ certificate with the IP address or is there a way I can use the domain name directly to connect using MQTT LWIP library?

---

<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:** [August 14, 2025, 7:07am UTC](https://community.hivemq.com/t/stm32-hivemq-connection-issue/3890/2 "2025-08-14T07:07:13Z")

</div>

Hi @cleonb32! Thanks for being here. The HiveMQ Community is always open to new users and your curiosity is very welcome.

The issue is **not** that you are resolving the domain name to an IP address yourself. The problem is that your device is likely not supporting **TLS-SNI (Server Name Indication)**. HiveMQ Cloud requires a TLS-SNI capable client to establish a connection.

You can find more details in our documentation: [https://hivemq.atlassian.net/wiki/spaces/HCSP/pages/2693857294](https://hivemq.atlassian.net/wiki/spaces/HCSP/pages/2693857294)

Best,

Dasha from The HiveMQ Team

---

<div class="post-metadata">

**Author:** ![cleonb32](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@cleonb32](https://community.hivemq.com/u/cleonb32)\
**Post date:** [August 15, 2025, 3:18am UTC](https://community.hivemq.com/t/stm32-hivemq-connection-issue/3890/3 "2025-08-15T03:18:15Z")

</div>

Thank you for your speedy reply. So, is it possible to connect to HiveMQ with a system running LWIP? In my case, I am using an STM32F7

---

<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:** [August 15, 2025, 12:44pm UTC](https://community.hivemq.com/t/stm32-hivemq-connection-issue/3890/4 "2025-08-15T12:44:41Z")

</div>

Hello @cleonb32 ,

Thank you for the follow-up!

We would first recommend utilizing the documentation attached from @Daria_H above to confirm that you do indeed have TLS-SNI enabled. This will allow you to ensure that the device is compatible with the TLS mechanisms utilized by HiveMQ Cloud.

If this is the case, and TLS-SNI is properly enabled, the next step would be to confirm if you are able to connect using just the Server certificate, available [here](https://letsencrypt.org/certs/isrgrootx1.pem), using one-way TLS. If successful, you can then use a custom certificate for client-based certificate authentication (mTLS) using our guide here : [Enhance Your IoT Security with Client Certificate Authentication on HiveMQ Cloud Starter](https://www.hivemq.com/blog/enhance-iot-security-client-certificate-authentication/)

Let us know if you have any additional questions - we are always happy to help!

Best,

Aaron from the HiveMQ Team

---

<div class="post-metadata">

**Author:** ![cleonb32](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@cleonb32](https://community.hivemq.com/u/cleonb32)\
**Post date:** [August 15, 2025, 10:34pm UTC](https://community.hivemq.com/t/stm32-hivemq-connection-issue/3890/5 "2025-08-15T22:34:13Z")

</div>

Thank you for the help. I confirm that the issue was with TLS\_SNI.

In the **altcp\_mbedtls\_setup** function after **mbedtls\_ssl\_init** (&state-\>ssl\_context); I added **mbedtls\_ssl\_set\_hostname** (&state-\>ssl\_context, “1ff096ae7f524a0f978cabaca991e8ca.s1.eu.hivemq.cloud”); for testing and it works. it is silly because I have to modify the 3rd party library for it to work.
