Cloudmqtt and Arduino connection

i’m trying to connect arduino to cloudmqtt with help of given example from pubsub library in arduino ide.

  • As i can see my ip address is reflected in cloudmqtt log , so literally its pinging cloudmqtt. but pub/sub service is not established . below im attaching screenshot and code . please let me know the mistake i have made in code.
    cloudmqtt log
    arduino mon

Basic MQTT example

This sketch demonstrates the basic capabilities of the library.
It connects to an MQTT server then:

  • publishes “hello world” to the topic “outTopic”
  • subscribes to the topic “inTopic”, printing out any messages
    it receives. NB - it assumes the received payloads are strings not binary

It will reconnect to the server if the connection is lost using a blocking
reconnect function. See the ‘mqtt_reconnect_nonblocking’ example for how to
achieve the same result without blocking the main loop.


#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>

// Update these with values suitable for your network.
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(10,0,0,5);
const char* server = “”;
const int mqttPort = 19405;
const char* mqttUser = “vkkmkzbf”;
const char* mqttPassword = “gpFiBO-lvd9t”;

void callback(char* topic, byte* payload, unsigned int length) {
Serial.print(“Message arrived [”);
Serial.print("] ");
for (int i=0;i<length;i++) {

EthernetClient ethClient;
PubSubClient client(ethClient);

void reconnect() {
// Loop until we’re reconnected
while (!client.connected()) {
Serial.print(“Attempting MQTT connection…”);
// Attempt to connect
if (client.connect("")) {
// Once connected, publish an announcement…
// … and resubscribe
} else {
Serial.print(“failed, rc=”);
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying

void setup()

client.setServer(server, 19405);

Ethernet.begin(mac, ip);
// Allow the hardware to sort itself out

void loop()
if (!client.connected()) {

Although i don’t know about what the internal library is doing, I think it is something to do with formation of MQTT packets. You might not be setting the correct flags needed for connection with CloudMQTT. Since you are using Ethernet, use WireShark to see whats being sent to server over TCP. It will be way easy to figure it out by observing the data going out from Arduino.