Arduino cannot connect to Cayenne Cloud

Hi, new user here, I am trying to connect my Arduino Uno with ESP8266 Wifi Shield to the Cayenne Cloud, with no success so far.
Followed the tutorials, got the code running, but I am getting this error over and over:
“[4135259] Network connect failed
basically it cannot connect to the Cayenne cloud.
I think it’s something related to the internet connection, but tested with both my fixed fiber internet connection and my 4G mobile network through Wifi hotspot, with different ISPs, and I get the same result.
Pinging “” result in “Request timed out” 100% packet loss all the time.
Is the Cayenne cloud down ?, is the 1883 port blocked (but on both connections) ?
Already used this exact configuration with Blynk and it worked only after I used the IP address of the cloud instead of the hostname, and it also used port 80.
Is it possible I can give the Cayenne Library the IP address of “” ?
Any help would be much appreciated !

arduino uno and esp as shield is not the most stable way for connection for this code. you may want to try with arduino mega instead.

you can get it using

$ host has address has address

it is good to troubleshoot, but not long term fix. IP addresses change over time,

Thanks for your answer.
It may not be the most stable connection, but being on the hardware serial and with very new AT firmware on the ESP it should work. And it worked fine with Blynk, like I said.
So, I try to debug this issue, and connected just the ESP to my laptop and started giving it AT commands.
It turns out it’s some sort of bug in the ESP AT firmware related to the DNS resolution.
It cannot resolve the DNS query for the host “”, but it works perfectly with the direct IP address. You can check the log below:
AT version: 13 2018 11:10:59)
SDK version:2.2.1(6ab97e9)
compile time:Jun 7 2018 19:34:26
Bin version(Wroom 02):1.6.2
Link type ERROR

Link type ERROR

Link type ERROR


DNS Fail



So now my question is: how can I change the hostname of the MQTT server with the IP address
when starting Cayenne:
“Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);”
Is there a version of the begin function with the server as a parameter ?

OK, so managed to get past the DNS issue by replacing the host with the IP address in the CayenneDefines.h. Now the web dashboard recognized my Arduino Uno device, and I added
a widgeton channel 0 to show the running time and a photoresistor on channel 1 and analog pin 0.
But the device keeps going “offline” every couple of seconds and even if the data is sent from my device (see the logs below), no data is received in the web dashboard.
Any advice ?
[6484] Connected to WiFi
[6486] Connecting to
172a4b4d4/cmd/+7875] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key
[12892] Publish: topic 6, channel 65534, value ATmega328P, subkey , key
[17911] Publish: topic 7, channel 65534, value 16000000, subkey , key
[27728] Publish: topic 8, channel 65534, value ESP8266Shield, subkey , key
[27798] Publish: topic 1, channel 1, value 530, subkey , key
[32815] Publish: topic 1, channel 0, value 32815, subkey , key
[37831] Connection ok
[42802] Publish: topic 1, channel 1, value 531, subkey , key

Can you try commenting all serial print lines. It is not the best practise to use one single hardware serial for both communication and serial printing.

Yes, the serial print line were just for debugging purposes, I never leave them upon deployment.
Turn out the problem was in my Arduino code, I had some channels mixed up, or they did not correspond to the widgets on the web dashboard, this is why I think the device was disconnecting very often and not receiving data.
Re-wrote all my channel functions and not it works correctly with a photoresistor, a termistor and a button controlled LED.
I now have 4 questions:

  1. Is it possible to change the MQTT server hostname from the Arduino code, so I can use the IP address ?
  2. When adding a widget I can only select Virtual from the Connectivity field, why aren’t there the Analog and Digital options ?
  3. It seems the sensors are sending data every 15 seconds. Where is this configured?, can I change this value ? Or add some sort of timer or trigger for sending the data from the device to the cloud ?
  4. When using a Line Chart, is it possible to define a threshold for the data, so that it generates an ON/OFF chart, OS when the data is above and OFF when the data is below ?
    Thank you!

i guess you solved this by changing it in CayenneDefines.h.

virtual channel are MQTT channels used to send data between device and cayenne server. There are not related to analog or digital connective. but then you can use the data received from this channel to do whatever you want.

have a look at this topic Sending MQTT messages within rate limits

i did not understand this

//#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>

// WiFi network info.
char ssid = “aaa”;
char wifiPassword = “aaa”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “aaa”;
char password = “aaa”;
char clientID = “aaa”;

// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
#define EspSerial Serial

ESP8266 wifi(&EspSerial);

void setup()

// Set ESP8266 baud rate

Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);


void loop()

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);

OK, so I’m still figuring out how to time the sending of my messages to the cloud.
I read the article you suggested “Sending MQTT messages within rate limits”,
but basically none of the examples provided there work for me.
I’ve narrowed it down to this: if I use only “CAYENNE_OUT(n)” functions with virtualWrite inside
it works perfectly, I get the messages in the cloud every 15 seconds.
But if I use any other kind of methods to send the messages, like “CAYENNE_OUT_DEFAULT()”,
of the if millis code in the loop, or a timer function, or the if state changed code in the loop, then I never get any messages in the cloud, and the device disconnects after about 50 seconds then reconnects after 30 seconds continually. In the code above, If I change just just the one line of code, from “CAYENNE_OUT(0)” to “CAYENNE_OUT_DEFAULT()” then it does not work anymore.
I’ve tried to debug it, and when it does not work in the console I see about 5 commands “AT+CIPSEND=1,40” one after another without anything in between,
but with the working code every command like that is followed my a message to the cloud.
Any advice ? Thank you.

it should work with CAYENNE_OUT_DEFAULT, i dont see any reason not to work. can you add a debug line inside the CAYENNE_OUT_DEFAULT function to verify that the function is called or not.

Used exactly the code in my previous post, added the debug message “Inside ” in “CAYENNE_OUT/_DEFAULT” functions, and saved the serial log from both versions: “CAYENNE_OUT(0)” - working and “CAYENNE_OUT_DEFAULT()” - not working.putty_not_working.log (3.2 KB) putty_working.log (3.2 KB)
Can you take a look at this log output ?
In the working version there are some additional messages (lines 20,21) that are missing in the not working version. Also when not working I get disconnected from the server, line 46, which is not happening in the other one. In the not working version I never receive any message on the server.

i tried to look into what was causing the issue but i was not able to reproduce it at my end. can you continue using only CAYENNE_OUT(0) and keep away from CAYENNE_OUT_DEFAULT for time being.

I’ve done a little bit of digging and debugging and what I saw was, that when it’s not working, the issue isn’t the sending of the regular data, but as you can see from the comparison of the putty logs,
the initial sending of the device information to the server is somehow wrong, so the device is not registering correctly to the cloud, and then it makes sense to go offline and not receive data.
On the serial, after the “Connected” message, this message should follow:
“Publish: topic 4, channel 65534, value Arduino Uno, subkey , key
2a4b4d4/sys/modelArduino Uno”, but instead, only this appears “Publish: topic 4, channel 65534, value Arduino Uno, subkey , key
AT+CIPSEND=1,40”, it’s missing the MTTQ authentication information.
And this happens for all the information from the “publishDeviceInfo” function that is called from
“Cayenne.begin()”, and every time.
Any advice ? Thanks!

well, as mentioned in the sketch this code is unstable for arduino uno and i guess that is what is producing this error. You may want to change over to an arduino mega to use the extra hardware serial

I am encountering a similar problem to the original issue raised in the earlier posts on this topic:

  • Running code on ESP8266 based device (Wemos D1 R2)
  • Connection to Cayenne works fine on home wifi network (normal terrestrial fibre internet).
  • Connection to Cayenne fails when going via LTE 4G router (which is how I want to connect the device for remote deployment). This appears to be the same problem described above where the DNS can’t resolve the IP for
  • Device connects fine to wifi, and have confirmed internet connection is ok from LTE router from computer.
  • Serial log shows following:

[hostByName] request IP for:
[hostByName] Host: IP:
pm open,type:2 0

  • If I hardcode the IP address for into the CayenneDefines.h file (as described above) then it works. But I don’t want to run with this long term as also discussed in thread above.

Any ideas?


Typical, after having tried a lot of different things, it occurred to me straight after posting this that maybe the dns server settings in the LTE router were causing the problem. So I changed them (to the google ones) and voila, it works. Leaving the post here in case anyone else has the same problem.

Thanks to myself for solving.


1 Like