Hivemq mqtt_client: MQTT connect failed

I have implemented a project to connect to a the HiveMQ broker via MQTT. However I constantly receive the message:
mqtt_client: Connection refused, not authorized
mqtt_client: MQTT connect failed

I have set the CA certificate to ISGR Root X1 as it is instrcuted by the HiveMQ Team members in these posts:

I have also followed the example on

github. com /platformio/platform-espressif32/tree/examples/espidf-aws-iot

I m sending below my repo

I had similar issues, it turned out that the esp_mqtt_client_config_t structure allows for 2 different server setups:

  1. you specify a complete URI starting with mqtt:// or mqtts:// followed by server : port

Then set the transport to so the framework parses the uri and figure out what to do: MQTT_TRANSPORT_UNKNOWN

  1. you specify Hostname (not uri), port and set the transport to your desire MQTT_TRANSPORT_OVER_SSL

If you mix that up the connection fails.

I have tried both configurations:

mqtt_cfg.broker.address.port = MQTT_PORT;

mqtt_cfg.broker.address.transport = MQTT_TRANSPORT_OVER_SSL;

mqtt_cfg.broker.address.hostname = MQTT_HOST;

mqtt_cfg.broker.address.uri = MQTT_BROKER_URI;

In both cases I received:

esp-tls: couldn’t get hostname for :xxxxx.s1.eu.hivemq.cloud: getaddrinfo() returns 202, addrinfo=0x0