• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Using CloudMQTT

Q&A Forum › Category: ESP32 › Using CloudMQTT
0 Vote Up Vote Down
Andy Kotowski asked 7 years ago

I followed this using CloudMQTT.
1.) I needed to load AsynchTCP-master.
2.) WHat is the reason that you removed master from the mqtt library name?  should I do that with all the -master libraries?
3.) CloudMQTT needs a url.  fortunately the connect function accepts a url.  I used whaat I got from CloudMQTT:
#define MQTT_HOST “http://m14.cloudmqtt.com”
4.) CloudMQTT needs user authentication which I also got from the CloudMQTT website: no user name and the password should be the API key:
mqttClient.setCredentials( “”, “75f27aca-2136-40ab-ac99-XXXXXXXXXXXX”);
5.) Running the program I get the message “Connecting to MQTT…”.  I never get the message “Connected to MQTT.”  The program thinks it’s publishing.  Then I get the message “Disconnected from MQTT.”  I dont know how to print out the disconnect reason.

Any suggestions?  I assume the MQTT server rejects the connection request.

Thanks for your help

3 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

Hello Andy, I’m sorry for taking so long to get back to you, but I was on holidays and unfortunately I had very low bandwidth to properly answer questions.

  1. Some versions of the Arduino IDE don’t recognize Arduino libraries with a dash “-“, so if your library is named “my-library”, the Arduino software doesn’t load that library. That’s why I always recommend removing the dash to avoid problems compiling your sketches.
  2. If you can compile your libraries with the dash, you don’t need to re-name them, you can keep the “-master”.
  3. Your MQTT_HOST should look like this:
#define MQTT_HOST "m14.cloudmqtt.com"

You can’t type the http.

4. Don’t use your MQTT API Key. Instead open the details of your MQTT instance: https://customer.cloudmqtt.com/instance
Copy your user/password and enter those details in the setCredentials method:

mqttClient.setCredentials( "zkk-----", "BtH------");

You also need to enter the right Port number of the cloud MQTT server, in my case:

#define MQTT_PORT 134---

5. Adding the HOST name properly formatted, MQTT username, MQTT password and MQTT server port number should solve your connection problem.

Thanks for your patience and let me know if this solution worked for you.

Regards,
Rui

0 Vote Up Vote Down
Andy Kotowski answered 7 years ago

Rui:  Yes that works! 
I had to add the “setCredentials” after the “setServer.”  Otherwise there is no reference to “MQTT_USER”
Thank You!
 
Andy

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

You’re welcome, I’m glad it worked! Thanks for letting me know,
Rui

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.