i have tried to connect my arduino mega and esp8266-01 to my blynk, it work and can connect, but after 1 cycle of setup sending 8 value of sensor reading it automatically disconnect and then connect again, thats happen again and again.
I saw the serial monitor, written heartbeat timeout when it disconnect, and my ping reach up to 8000, i think there is something wrong with my code in timer.setinterval, but i dont know how to fix it, Please write me any tips.
Thank you
this is my code,
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#define EspSerial Serial
#define ESP8266_BAUD 115200
#include <SimpleTimer.h>
ESP8266 wifi(EspSerial);
char auth[] = "xxx"; // Put your Auth Token here. (see Step 3 above)
int offset =0.1;// set the correction offset value
int volt1; //PIEZO
double voltage1;
int volt2; //WIND
double voltage2;
int volt3; //SOLAR
double voltage3;
int volt4; //BATERAI
double voltage4;
SimpleTimer timer;
void setup()
{
Blynk.virtualWrite(V0, HIGH);
Serial1.begin(9600); // See the connection status in Serial Monitor
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, "xxx", "xxx");
timer.setInterval(1000L, PiezoVoltageRead);
timer.setInterval(1000L, WindVoltageRead);
timer.setInterval(1000L, SolarVoltageRead);
timer.setInterval(1000L, PiezoCurrentRead);
timer.setInterval(1000L, WindCurrentRead);
timer.setInterval(1000L, SolarCurrentRead);
timer.setInterval(1000L, sumvoltage);
timer.setInterval(1000L, SumCurrent);
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
timer.run(); // Initiates BlynkTimer
}
void PiezoVoltageRead()
{
volt1 = analogRead(A1);// read the input
double voltage1 = map(volt1,0,1023, 0, 2500) + offset;// map 0-1023 to 0-2500 and add correction offset
voltage1 /=100;// divide by 100 to get the decimal values
Blynk.virtualWrite(V1, voltage1);
delay(500);
//int callFunction2 = timer.setTimeout(1000, WindVoltageRead);
}
void WindVoltageRead()
{
volt2 = analogRead(A2);// read the input
double voltage2 = map(volt2,0,1023, 0, 2500) + offset;// map 0-1023 to 0-2500 and add correction offset
voltage2 /=100;// divide by 100 to get the decimal values
Blynk.virtualWrite(V2, voltage2);
delay(500);
//int callFunction3 = timer.setTimeout(1000, SolarVoltageRead);
}
void SolarVoltageRead()
{
volt3 = analogRead(A3);// read the input
double voltage3 = map(volt3,0,1023, 0, 2500) + offset;// map 0-1023 to 0-2500 and add correction offset
voltage3 /=100;// divide by 100 to get the decimal values
Blynk.virtualWrite(V3, voltage3);
delay(500);
//int callFunction4 = timer.setTimeout(1000, PiezoCurrentRead);
}
void sumvoltage()
{
volt4 = analogRead(A4);// read the input
double voltage4 = map(volt3,0,1023, 0, 2500) + offset;// map 0-1023 to 0-2500 and add correction offset
voltage4 /=100;// divide by 100 to get the decimal values
Blynk.virtualWrite(V4, voltage4);
delay(500);
//int callFunction8 = timer.setTimeout(1000, SumCurrent);
}
void PiezoCurrentRead()
{
float current1 = 0;
for(int i = 0; i < 1000; i++) {
current1 = current1 + (.0264864864864865 * analogRead(A5) - 13.5135135135135);
delay(1);
}
Blynk.virtualWrite(V5, current1);
delay(500);
//int callFunction5 = timer.setTimeout(1000, WindCurrentRead);
}
void WindCurrentRead()
{
float current2 = 0;
for(int i = 0; i < 1000; i++) {
current2 = current2 + (.049 * analogRead(A6) - 25);
delay(1);
}
Blynk.virtualWrite(V6, current2);
delay(500);
//int callFunction6 = timer.setTimeout(1000, SolarCurrentRead);
}
void SolarCurrentRead()
{
float current3 = 0;
for(int i = 0; i < 1000; i++) {
current3 = current3 + (.049 * analogRead(A7) - 25);
delay(1);
}
Blynk.virtualWrite(V7, current3);
delay(500);
//int callFunction7 = timer.setTimeout(1000, sumvoltage);
}
void SumCurrent()
{
float current4 = 0;
for(int i = 0; i < 1000; i++) {
current4 = current4 + (.049 * analogRead(A8) - 25);
delay(1);
}
Blynk.virtualWrite(V8, current4);
delay(500);
}