How do I do to connect Matlab App Designer GUI to HiveMQ cloud?

I have the following code section made in Matlab app designer, trying to connect to HiveMQ Cloud without success, any suggestion?
% Connection between MATLAB & MQTT broker
brokerAddress = ‘tcp://’;
port = 8883; % Secure MQTT port

MQTTSignal = mqtt(brokerAddress, ‘Port’, port, ‘Username’, ‘DCM_user001’, ‘Password’, ‘DCm0t0r2024’);

Hi @caveadventurer,

I would like to offer a suggestion for your consideration. Kindly consider using tls instead of tcp, and please let us know if this adjustment proves beneficial for your situation.

In the event that this recommendation does not resolve your issue, could you please take a moment to share the specific documentation you have been following? It’s possible that there may be documentation specifying the appropriate prefix to use for secure connections, and this information could aid you in providing you with more targeted assistance.

Thank you for your time and cooperation. We’re here to help and look forward to resolving any challenges you may be facing.

Best regards,
Dasha from HiveMQ Team

Hi Dasha,
I just used the tls instead of tcp and didn’t worked. I got the following error:
Error using mqttclient
The value of ‘BrokerAddress’ is invalid. Invalid connection protocol. For secure
connection specify ssl:// or wss://. For nonsecure connection specify tcp:// or
mqtt:// or ws://.

% Connection between MATLAB & MQTT broker
brokerAddress = ‘tls://’;
port = 8883;
clientID = ‘76271ae1a3094a9999d06f8ee5148686’;
MQTTSignal = mqttclient(brokerAddress,‘Port’,port,‘ClientID’,clientID,‘Username’,‘DCM_user001’,‘Password’,‘DCm0t0r2024’);
% Publish topic using MQTT in MATLAB
Topic = “ESP32/data”;

Hi @caveadventurer,

Thank you for reaching out. I appreciate your prompt response. Use the ssl instead of tls as suggested. Let us know if this adjustment proves beneficial for your situation.

If you encounter any challenges or have further questions, feel free to reach out. We’re here to assist you.

Best regards,
Dasha from HiveMQ Team

Hi Dasha,

I used both ssl and tls and wss and same error that cannot be connected; so I think that it needs a root certificate just like ESP32 (last example). But I’m not really sure about how to do that since I haven’t found any related information about it. If you could get some matlab example I’ll appreciate it.

Hi, @caveadventurer

What is matlab? If your device or library does not contain the Let’s Encrypt root certificate yet, you can download the root certificate here .
This will create a file called “isrgrootx1.pem”, which you can use as a “Server Certificate”.#

I hope it helps
Dasha from HiveMQ Team

Thanks Dasha! I already made my code used this root certificate, and apparently it worked, nono error was displayed.
I just only need to find out if it is subscribing and publishing.
I’ll be in touch. Thx

It worked perfectly, but I wonder if you can help me now to solve why my ESP32 is not receiving this topic, could be because of the root certificate that is different?

Hello @caveadventurer,

Thank you for reaching out and providing details about the issue you’re experiencing.

The server root CA certificate is intended for connection purposes only and not for subscribing or publishing. If your client is successfully connected but facing issues with subscribing or publishing, it’s advisable to review the ACCESS CREDENTIALS.

To assist you further, please navigate to and access the “Access Management” section. Kindly take a screenshot of the entire page, including permissions and users. This will help us analyze the settings and identify any potential issues.

Best regards,
Dasha from HiveMQ Team

Thanks a lot for your answer Dasha, now I see why is not working.
Here’re the images from the “Access Management”

Hello @caveadventurer,

Thank you for reaching out. I appreciate your proactive approach in providing screenshots of your permissions settings. Based on the information you’ve shared, it seems that your permissions are configured correctly, allowing MQTT clients using DCM_user001 to publish and subscribe to any topic (filter #).

To assist you further, could you please share the full version of your code? Specifically, I would like to review the sections where your device subscribes to the topic and where it handles received messages. This will enable me to analyze the code more effectively and provide you with targeted assistance.

Looking forward to your response and working together to resolve any issues you may be encountering.

Best regards,
Dasha from HiveMQ Team

1 Like

Hi Dasha,
I already solved the problem with the ESP32.
Thank you very much for your help! :slight_smile: