mqttclient unable to establish a connection with broker

4 次查看(过去 30 天)
Hello, I am trying to connect to a HiveMQ broker with the mqttclient function. I am able to connect to the broker with other apps such as MQTTX or MQTT explorer, so I know the credentials are correct.
mqttClient = mqttclient("ssl://4d96d3eaeb474fd6a5121398823c69f7.s1.eu.hivemq.cloud", ...
"Port", 8883, ...
"Username", "matlabhelptest", ...
"Password", "testTEST1111");
The error I get is: Failed to establish a connection with broker "ssl://4d96d3eaeb474fd6a5121398823c69f7.s1.eu.hivemq.cloud".
Are there any known issues with mqttclient not establishing connections with secure brokers? I am able to connect to unsecure brokers such as mqtt://broker.hivemq.com with the port = 1883.
Thanks so much for your help on this topic.

回答(1 个)

Swastik Sarkar
Swastik Sarkar 2025-6-17
Since it has been confirmed that the broker connection works via MQTT Explorer, it can be assumed that the host is reachable and the credentials are valid. Given that the issue arises specifically when connecting to secure brokers, it is advisable to ensure the use of a valid CA root certificate in conjunction with the mqttclient command.
Further information on configuring the MQTT client in MATLAB can be found in the official documentation:
Additionally, a detailed MATLAB Central Answer provides guidance on obtaining a root certificate for use with api.thingspeak.com. This approach can be extended to work with the broker currently being connected to:
I hope this helps resolve the issue with connecting to the secure MQTT broker.

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

产品


版本

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by