ESP8266 connection problem to cayenne server

We are using the ESP8266 Wi-Fi shield to connect Arduino to the cayenne server. However once connect the chip to access point it will heat up and sometimes will lagging. After that, it shows some message but the Cayenne server didn’t connect to the Arduino. Every widget can not be operated (No response when click a button, temperature value unchanged, etc.). Can anyone solve this issue? It is important for my course work.

Arduino code:

#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266Shield.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <virtuabotixRTC.h>

//Real+Virtual
#define LED_PIN 5
#define temp_sensor 4
#define EspSerial Serial

//Virtual
#define Power_sensor 9
#define DayPower 10
#define MonthPower 11
#define LED_PWM 12

//SSID

char ssid = “”;
char password = “”;

char username = “”;
char mqtt_password = “”;
char client_id =“”;

ESP8266 wifi(&EspSerial);

//Temperature setup
OneWire oneWire(4);
DallasTemperature sensors(&oneWire);

//Power sensor
const int analogInPin = A0;
int sensorValue = 0; // value read from the pot
float MAXValue = 0; // value output to the PWM (analog out)
float Power = 0;
int PWM = 0;

//Time
int curSec = 0;
int curMin = 0;
int curHour = 0;
int curDay = 0;
virtuabotixRTC myRTC(6, 7, 8);
unsigned PowerInDay = 0;
unsigned PowerInMonth = 0;

void setup() {
// put your setup code here, to run once:
sensors.begin();
EspSerial.begin(115200);
delay(10);
Cayenne.begin(username, mqtt_password, client_id, wifi, ssid, password);

pinMode(LED_PIN, OUTPUT);
analogWrite(LED_PIN, PWM);

curSec = myRTC.seconds;
curMin = myRTC.minutes;
curHour = myRTC.hours;
curDay = myRTC.dayofmonth;

//test

}

void loop() {
Cayenne.loop();
myRTC.updateTime();
if ( curSec != myRTC.seconds ) {
PowerInDay += Power;
curSec = myRTC.seconds;
}
if (curDay != myRTC.dayofmonth) {
PowerInMonth += PowerInDay;
PowerInDay = 0;
curDay = myRTC.dayofmonth;
}
if (curDay > myRTC.dayofmonth) {
PowerInMonth = 0;
}
Serial.print(myRTC.dayofmonth);
Serial.print(‘/’);
Serial.print(myRTC.month);
Serial.print(‘/’);
Serial.print(myRTC.year);
Serial.print(‘/’);
Serial.print(’ ‘);
Serial.print(myRTC.hours);
Serial.print(’:‘);
Serial.print(myRTC.minutes);
Serial.print(’:‘);
Serial.print(myRTC.seconds);
Serial.print(’\n’);
Serial.print(PowerInDay);
Serial.print(’ ‘);
Serial.print(PowerInMonth);
Serial.print(’\n’);

}

CAYENNE_OUT(temp_sensor)
{
sensors.requestTemperatures();
Cayenne.celsiusWrite(temp_sensor, sensors.getTempCByIndex(0));
}

CAYENNE_OUT(Power_sensor)
{
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
if (sensorValue > 0)
MAXValue = sensorValue * 0.00007307;

Power = MAXValue * ((float)PWM / (float)255) * 3.3 * ((float)PWM / (float)255);
// change the analog out value:/

// print the results to the serial monitor:
Serial.print("sensor = “);
Serial.print(sensorValue); //RAW value from analog read :slight_smile:
Serial.print(”\t output = ");
Serial.println(MAXValue * ((float)PWM / (float)255), 3); //Output the current
Serial.print(“Power =”);
Serial.println(Power, 3);
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(50);
Cayenne.virtualWrite(Power_sensor, Power, “pow”, “w”);
}

CAYENNE_OUT(DayPower) {
Cayenne.virtualWrite(DayPower, PowerInDay, “pow”, “w”);
}

CAYENNE_OUT(MonthPower) {
Cayenne.virtualWrite(MonthPower, PowerInMonth, “pow”, “w”);
}

CAYENNE_IN(LED_PIN)
{
int currentValue = getValue.asInt();
if (currentValue == 1) {
PWM = 255;
digitalWrite(LED_PIN, HIGH);
} else {
PWM = 0;
digitalWrite(LED_PIN, LOW);
}
//digitalWrite(Relay, HIGH);
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}

CAYENNE_IN(LED_PWM)
{
int value = getValue.asInt(); // 0 to 255
PWM = value;
analogWrite(LED_PIN, value);
}

Serial monitor message:

AT
ATE0
AT+CIPMUX=1
AT+CWMODE?
AT+CWJAP=“TP-LINK_MWNg”,“mwngpass”
[5618] Connected to WiFi
[5619] Connecting to mqtt.mydevices.com:1883
AT+CIPSTART=1,“TCP”,“mqtt.mydevices.com”,1883
[15636] Network connect failed
AT+CIPSTART=1,“TCP”,“mqtt.mydevices.com”,1883
AT+CIPSEND=1,40
MQIsdp
9c6b2/things/2bb3afa0-5dc8-11ea-ba7c-716AT+CIPSEND=1,16
e7f5ba423/cmd/+
AT+CIPSEND=1,40
AT+CIPSEND=1,40
AT+CIPSEND=1,40
AT+CIPSEND=1,40
1i Zv1/ef1ccaa0-3dc3-11ea-b73d-1be39589cAT+CIPSEND=1,40
6b2/things/2bb3afa0-5dc8-11ea-ba7c-716e7AT+CIPSEND=1,27
f5ba423/data/4temp,c=28.125sensor = 0 output = 0.000
Power =0.000
AT+CIPSEND=1,40
1g

The interface of the Cayenne platform have attached in the post

in the intro it is clearly mentioned it is not stable and to avoid using only one serial pins. you will need to use it with arduino mega with serial1 pins.

So you mean this library need more than 1 serial pin to have a stable connection? Since I am using Arduino UNO so there are only 1 pair of Serial port. Is there any other library is stable for Arduino UNO use?

Not currently. It makes debugging hard since the serial port is used for the ESP.