---
title: "MBedTLS W5500 TLS MQTT"
url: "https://maker.wiznet.io/forum/15313"
markdown_url: "https://maker.wiznet.io/forum/15313/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "gabrielsaavedra995"
created: "2024-10-17T23:38:39+09:00"
last_activity: "2024-10-17T23:38:39+09:00"
language: "en"
views: 4
replies: 0
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# MBedTLS W5500 TLS MQTT

## Question

Asked by gabrielsaavedra995 on 2024-10-17 in Ethernet Chips.

Hello everyone.

I have been having issues connecting to an MQTT broker with the "Serverless" service from EMQX. I am using an STM32F411 and a W5500. I am establishing a secure TLS connection using the MbedTLS library, and I am using the PahoMqtt-embedded-c library for the MQTT operations.

I am able to connect successfully to a local Mosquitto server. Similarly, I can connect to an MQTT broker using the "Dedicated" service from EMQX. However, when using the "Serverless" service, I receive an error "255" when calling the MQTTConnect function.

I am mainly following these examples:

- <https://github.com/eziya/STM32F4_HAL_ETH_MQTT_CLIENT_MBEDTLS/tree/master>

- <https://github.com/bangbh81/WIZnet-SSL-Example/tree/master>

- <https://github.com/WIZnet-ioLibrary/W5x00-TLS/tree/master>

Lastly, it's important to mention that I am not using a DNS service. I am using the IP address of my MQTT broker, obtained by passing the URL through Google’s DNS service (8.8.8.8). I noticed that all "serverless" brokers from EMQX share the same address. It seems related to SNI. From my research, I found the function `mbedtls_ssl_set_hostname()`.

I am using it as follows:
ret = mbedtls_ssl_set_hostname(tlsContext->ssl, "t0cabb21.ala.us-east-1.emqxsl.com");

However, the connection still fails, returning the same error 255.

I would appreciate any advice on how to configure a connection to a broker that requires SNI, or any suggestions on what might be going wrong.

---

Source: https://maker.wiznet.io/forum/15313
