Failed to establish a connection with TLS/MQTTS broker using mqttclient
조회 수: 10 (최근 30일)
이전 댓글 표시
I am attempting to make an application utilizing OpenF1's MQTT stream but am having issues creating a connection. The following information is provided by the documentation:
Connection Details
- MQTT server: mqtt.openf1.org
- MQTT port (TLS/MQTTS): 8883
- Websockets URL (WSS for MQTT over Websockets): wss://mqtt.openf1.org:8084/mqtt
Authentication
Both MQTT and Websocket connections use the OAuth2 access token as the password for authentication. The username can typically be any non-empty string, or your registered email if preferred/required by your client library for token-based auth.
after receiving a token I am able to establish a connection on MQTTX with settings:
Host: mqtts:// mqtt.openf1.org
SSL/TLS : Yes
SSL Secure: No
Certificate: CA signed server certificate
However in MATLAB, all variations of the following line are met with error message "Failed to establish a connection with broker"
mqttClient = mqttclient("ssl://mqtt.openf1.org", Username="example@email.com", Password=token, Port=8883, CARootCertificate="mqtt.openf1.org.crt")
The certificate was downloaded via the method described in https://www.mathworks.com/matlabcentral/answers/1889632-how-to-download-root-certificate-for-use-with-industrial-communication-toolbox-mqtt-functions.This is my first time using MQTT, please help me identify my error or suggest troubleshooting steps.
댓글 수: 0
답변 (2개)
Kautuk Raj
2025년 7월 22일
I was also seeing the same error in one of my workflows when trying to connect to a secure MQTT broker from MATLAB.
I found a discussion on a GitHub issue (https://github.com/eclipse-paho/paho.mqtt.c/issues/1385) which helped me resolve the issue, I will reproduce it below for your convenience.
You can resolve the issue by specifying the path after the port number in the URL in the following format:
protocol://hostname:port/path
instead of using protocol://hostname/path:port
댓글 수: 0
Govind KM
2025년 7월 22일
편집: Govind KM
2025년 7월 22일
I was facing a similar error message when trying to connect an MQTT client over websockets in MATLAB R2024b, but was able to connect successfully in R2025a. If possible, I would recommend upgrading to the R2025a release and trying out the same workflow.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MQTT Protocol Communication에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!