Good day,
two years ago I started a project to regulate the heating of an electric boiler. In the project I use two arduino mega boards. One board is only to measure the value from dht 22 in one room and send it to the other device. The second device controls the relay and measures a few other values (dht 22 sensors and max 6675 thermometer). The current problem is that the arduino mega with the relay starts disconnecting from the server after about a day after startup. It always disconnects for a few seconds and then reconnects, board can’t be controlled in this time. When I tried the output in the serial monitor, the arduino writes the message “heartbeat timeout”. Thanks for help. I am attaching the code (board with relay):
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#define pinDHT 8
#define pinDHT1 9
#define DHTTYPE DHT22
#include <EthernetENC.h>
#include <BlynkSimpleEthernetENC.h>
#include <max6675.h>
#include <DHT.h>
int pinSO = 5; // tep pin
int pinCS = 4; //tep pin
int pinSCK = 3; //tep pin
int hlavni1 = 1; //main switch
float tepoby2; //tep from second device
float tepoby1; //tep from second device with decimals
int tepIN1; //tep from server for compare
float tepIN2; //regulation - not important
int tepOUT; //value to app for check
int kontrola1; //advanced automation
int kontrola2; //advanced automation
int zmena; //advanced automation
int i; //repetition
int led; //check in app (led)
float tep1; //out
float tep; //room
float teplotaC; //water
DHT mojeDHT(pinDHT, DHTTYPE);
DHT mojeDHT1(pinDHT1, DHTTYPE);
MAX6675 termoclanek(pinSCK, pinCS, pinSO);
BlynkTimer timer;
BLYNK_WRITE(V0) {
int hlavni (param.asInt());
hlavni1 = hlavni;
}
BLYNK_WRITE(V6) {
int tepIN (param.asInt());
tepIN1 = tepIN;
}
BLYNK_WRITE(V8) {
int kontrola (param.asInt());
kontrola1 = kontrola;
}
BLYNK_WRITE(V9) {
float tepoby (param.asInt());
tepoby2 = tepoby;
}
void setup()
{
Serial.begin(9600);
pinMode (7, OUTPUT);
mojeDHT.begin();
mojeDHT1.begin();
Blynk.begin(BLYNK_AUTH_TOKEN);
timer.setInterval(5000L, myTimer1);
}
void loop()
{
Blynk.run();
timer.run();
delay(1000);
tep1 = mojeDHT1.readTemperature();
delay(1000);
tep = mojeDHT.readTemperature();
delay(1000);
teplotaC = termoclanek.readCelsius();
tepoby1 = tepoby2 * 0.01;
delay(1000);
/*
if (tepoby1 == 0) {
if (tep > 2) { //hodnota
Blynk.logEvent("error", String("Nefunkcni cidlo v oby"));
Serial.println ("Error1");
digitalWrite(7, LOW);
Blynk.virtualWrite(V1, 0);
Blynk.virtualWrite(V6, 0);
Blynk.virtualWrite(V7, 0);
delay(10000);
}
if (tep < -2) { //hodnota
Blynk.logEvent("error", String("Nefunkcni cidlo v oby"));
Serial.println ("Error1");
digitalWrite(7, LOW);
Blynk.virtualWrite(V1, 0);
Blynk.virtualWrite(V6, 0);
Blynk.virtualWrite(V7, 0);
delay(10000);
}
}
else {
delay (1000);
}
if (kontrola1 == 1) {
kontrola2 = kontrola2 + 1;
kontrola1 = 0;
delay (2000);
}
if (kontrola2 == 1) {
zmena = teplotaC;
kontrola2 = kontrola2 + 1;
delay (2000);
}
if (kontrola2 == 3) {
zmena = zmena + 5; //hodnota
if (teplotaC <= zmena) {
Blynk.logEvent("vyp", String("Kotel nebyl dle teploty vody zapnut"));
Serial.println ("Error2");
}
kontrola1 = 0;
kontrola2 = 0;
}
*/
if (hlavni1 == 1) {
if (tepoby1 <= tepIN1) {
digitalWrite(7, HIGH);
led = 1; //Blynk.virtualWrite(V1, 1);
}
if (tepoby1 > tepIN1) {
digitalWrite(7, LOW);
led = 0; //Blynk.virtualWrite(V1, 0);
}
i = 0;
}
delay(1000);
if (hlavni1 == 0) {
digitalWrite(7, LOW);
led = 0; //Blynk.virtualWrite(V1, 0);
if (i == 0) {
Blynk.logEvent("zakaz", String("Činnost kotle byla upravena hlavním spínačem, toto lze zrušit pouze jeho opětovným přepnutím"));
i = 1;
}
}
/*
Serial.println (tep);
Serial.println (tep1);
Serial.println (teplotaC);
Serial.println (tepoby1);
Serial.println (tepoby2);
Serial.println (tepIN1);
Serial.println (tepoby1);
Serial.println (hlavni1);
*/
delay(1000);
}
void myTimer()
{
Blynk.virtualWrite(V2, tep1);
Blynk.virtualWrite(V5, tep);
Blynk.virtualWrite(V3, teplotaC);
Blynk.virtualWrite(V7, tepIN1);
Blynk.virtualWrite(V4, tepoby1);
if (led == 1) {
Blynk.virtualWrite(V1, 1);
}
if (led == 0) {
Blynk.virtualWrite(V1, 0);
}
}
Other device:
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#define pinDHT 12
#define DHTTYPE DHT22
#include <EthernetENC.h>
#include <BlynkSimpleEthernetENC.h>
#include <DHT.h>
DHT mojeDHT(pinDHT, DHTTYPE);
float tep;
float pomocna;
BlynkTimer timer;
void setup()
{
Serial.begin(9600);
mojeDHT.begin();
Blynk.begin(BLYNK_AUTH_TOKEN);
timer.setInterval(1000L, myTimer);
}
void loop()
{
Blynk.run();
timer.run();
float tep = mojeDHT.readTemperature();
pomocna = tep;
pomocna = pomocna * 100;
Serial.println(tep);
delay (2000);
}
void myTimer()
{
Blynk.virtualWrite(V4, tep);
Blynk.virtualWrite(V9, pomocna);
}