Arduino cannot connect to Cayenne Cloud

Blockquote
//#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()
{
//Serial.begin(9600);
//delay(10);

// Set ESP8266 baud rate
EspSerial.begin(115200);
delay(10);

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

}

void loop()
{
Cayenne.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.
//CAYENNE_OUT_DEFAULT() //THIS DOES NOT WORK!!!
CAYENNE_OUT(0) //THIS WORKS!!!
{
// 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);
}

Blockquote
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.