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
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.
- 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.
- If you can compile your libraries with the dash, you don’t need to re-name them, you can keep the “-master”.
- 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.
Rui: Yes that works!
I had to add the “setCredentials” after the “setServer.” Otherwise there is no reference to “MQTT_USER”