Error - Reconnect every time

Hi , i have problem with my project…

Check ->

Arduino Mega 2560 With Ethernet Shield W5100…

Monitor Show this.
 
 [0] Getting IP...
 [6689] IP:192.168.1.19
 [6690] 
 ___  __          __
/ _ )/ /_ _____  / /__
   / _  / / // / _ \/  '_/
  /____/_/\_, /_//_/_/\_\
 /___/ v0.6.1 on Arduino Mega
 
 [6808] Connecting to 192.168.1.14
 [6900] Ready (ping: 8ms).
 [12192] Connecting to 192.168.1.14
 [17193] Connecting to 192.168.1.14


Code:

 #define BLYNK_PRINT Serial
 #include <SPI.h>
 #include <Ethernet.h>
 #include <BlynkSimpleEthernet.h>
 #include <DHT.h>
 #include <Wire.h>
 #include <TimeLib.h>
 #include <WidgetRTC.h>
 
 #define DHTPIN 23
 #define DHTTYPE DHT11     // DHT 11
 
 char auth[] = "";
 
 #define W5100_CS  10
 #define SDCARD_CS 4
 
 BlynkTimer timer;
 WidgetTerminal terminal(V73);
 WidgetLED ledbomba(V72);
 DHT dht(DHTPIN, DHTTYPE);
 WidgetRTC rtc;
 
 const int BombaAgua = 22;
 const int ReflectorPatio = 24;
 const int Presurizadora = 26;
 const int NivelTanke = 28;
 const int SensorPorton = 52;
 const int BotonCuarto = 50;
 
 const int ReflectorPorton = 53;
 const int ReflectorTerreno = 51;
 const int AperturaPorton = 49;
 const int LuzCuarto = 47;
 
 int EstadoBombaAgua = LOW;
 int EstadoReflectorPatio = LOW;
 int EstadoPresurizadora = LOW;
 int EstadoNivelTanke = LOW;
 
 bool isFirstConnect = false;
 
 int EstadoLuzCuarto, EstadoBotonCuarto, EstadoReflectorPorton, EstadoReflectorTerreno, stadoAperturaPorton, EstadoSensorPorton;
 
 int HoraDia = 5;
 int HoraNoche = 20;
 
 void setup()
 {
   Serial.begin(9600);
 
   pinMode(SDCARD_CS, OUTPUT);
   digitalWrite(SDCARD_CS, HIGH);
   Blynk.begin(auth, IPAddress(192, 168, 1, 14), 8080);
 
   pinMode(BombaAgua, OUTPUT);
   pinMode(ReflectorPatio, OUTPUT);
   pinMode(Presurizadora, OUTPUT);
 
   pinMode(LuzCuarto, OUTPUT);
   pinMode(ReflectorPorton, OUTPUT);
   pinMode(ReflectorTerreno, OUTPUT);
   pinMode(AperturaPorton, OUTPUT);
 
   pinMode(BotonCuarto, INPUT_PULLUP);
   pinMode(SensorPorton, INPUT_PULLUP);
   pinMode(NivelTanke, INPUT_PULLUP);
 
 
   dht.begin();
   rtc.begin();
 
   setSyncInterval(10 * 60);
 
   terminal.clear();
   terminal.println(F("Jarvis Home Iniciado V2"));
   terminal.println(F("-------------"));
   terminal.println(F("Version: " BLYNK_VERSION));
   terminal.flush();
 
   timer.setInterval(1000L, botonluzcuarto);
   timer.setInterval(1000L, temperaturayhumedad);
 timer.setInterval(1000L, checkconnect);
   timer.setInterval(1000L, sensorporton);
   timer.setInterval(1000L, encendidoautomatico);
 }
 
 void loop()
 {
   Blynk.run();
   timer.run();
 }
 
 BLYNK_CONNECTED() {
 
   if (isFirstConnect) {
 Blynk.syncAll();
 isFirstConnect = false;
   }
 
   Blynk.syncVirtual(V1);
   Blynk.syncVirtual(V2);
   Blynk.syncVirtual(V3);
 }
 
 BLYNK_WRITE(V1) {
   EstadoBombaAgua = param.asInt();
   digitalWrite(BombaAgua, EstadoBombaAgua);
 
   if (EstadoBombaAgua == 0) {
 ledbomba.on();
 terminal.println(F("Bomba Encendida"));
 terminal.flush();
   }
   else {
 ledbomba.off();
 terminal.println(F("Bomba Apagada"));
 terminal.flush();
   }
 }
 
 BLYNK_WRITE(V2) {
   EstadoReflectorPatio = param.asInt();
   digitalWrite(ReflectorPatio, EstadoReflectorPatio);
   terminal.println(F("Reflector Patio: "));
   terminal.println(EstadoReflectorPatio);
   terminal.flush();
 }
 BLYNK_WRITE(V3) {
   EstadoPresurizadora = param.asInt();
   digitalWrite(Presurizadora, EstadoPresurizadora);
 
   if (EstadoPresurizadora == 0) {
 Blynk.virtualWrite(V103, "Presurizada");
   }
   else {
 Blynk.virtualWrite(V103, "Normal");
   }
 
 }
 
 BLYNK_WRITE(V4) {
   EstadoLuzCuarto = param.asInt();
   digitalWrite(LuzCuarto, EstadoLuzCuarto);
 }
 BLYNK_WRITE(V5) {
   EstadoReflectorPorton = param.asInt();
   digitalWrite(ReflectorPorton, EstadoReflectorPorton);
 }
 BLYNK_WRITE(V6) {
   EstadoReflectorTerreno = param.asInt();
   digitalWrite(ReflectorTerreno, EstadoReflectorTerreno);
 }
 
 BLYNK_WRITE(V7) {
   EstadoAperturaPorton = param.asInt();
   digitalWrite(AperturaPorton, EstadoAperturaPorton);
 }
 
 BLYNK_WRITE(V8)
 {
   HoraNoche = param.asInt();
   terminal.println("Hora Noche Modificada: ");
   terminal.println(HoraNoche);
   terminal.flush();
 }
 
 BLYNK_WRITE(V9)
 {
   HoraDia = param.asInt();
   terminal.println("Hora Dia Modificada: ");
   terminal.println(HoraDia);
   terminal.flush();
 }
 
 void sensorporton()
 {
 
   EstadoSensorPorton = digitalRead(SensorPorton);
 
   int hora = hour();
   if (hora >= HoraDia && hora <= HoraNoche) {
 terminal.println("Sensonr Porton Activo");
 terminal.flush();
 if (EstadoSensorPorton != 0) {
   Blynk.virtualWrite(V5, "1");
 }
 else
 {
   Blynk.virtualWrite(V5, "0");
 }
 
   }
 }
 
 void botonluzcuarto()
 {
   if (digitalRead(BotonCuarto) == LOW) {
 if (EstadoBotonCuarto != LOW) {
   EstadoLuzCuarto = !EstadoLuzCuarto;
   digitalWrite(LuzCuarto, EstadoLuzCuarto);
   Blynk.virtualWrite(V4, EstadoLuzCuarto);
 }
 EstadoBotonCuarto = LOW;
   } else {
 EstadoBotonCuarto = HIGH;
   }
 }
 
 void temperaturayhumedad()
 {
   float h = dht.readHumidity();
   float t = dht.readTemperature();
   if (isnan(h) || isnan(t)) {
 String currentTime = String(hour()) + ":" + minute() + ":" + second();
 String currentDate = String(day()) + "/" + month() + "/" + year();
 terminal.println("Error Temperatura Cuarto Kevin: ");
 terminal.print(currentTime);
 terminal.print(" ");
 terminal.print(currentDate);
 terminal.println();
 terminal.flush();
 return;
   }
   Blynk.virtualWrite(V10, h);
   Blynk.virtualWrite(V11, t);
 
 }
 void checkconnect()
 {
   bool result = Blynk.connected();
 
   if (result == false) {
 Blynk.connect();
 
   }
 }
 void sensortanque()
 {
   EstadoNivelTanke = digitalRead(NivelTanke);
 
   if (EstadoBombaAgua != 0) {
 Blynk.virtualWrite(V1, 1);
   } else
   {
 Blynk.virtualWrite(V1, 0);
   }
 }
 
 void encendidoautomatico()
 {
   int hora = hour();
   if (hora >= HoraDia && hora <= HoraNoche) {
 if (EstadoReflectorPatio != 0) {
   Blynk.virtualWrite(V2, "1");
 }
 else
 {
   Blynk.virtualWrite(V2, "0");
 }
 if (EstadoReflectorPorton != 0) {
   Blynk.virtualWrite(V5, "1");
 }
 else
 {
   Blynk.virtualWrite(V5, "0");
 }
 if (EstadoReflectorTerreno != 0) {
   Blynk.virtualWrite(V6, "1");
 }
 else
 {
   Blynk.virtualWrite(V6, "0");
 }
 if (EstadoPresurizadora != 0) {
   Blynk.virtualWrite(V3, "1");
 }
 else
 {
   Blynk.virtualWrite(V3, "0");
 }
 
   }
 }

Im using LOCAL Server with Raspberry pi 3.

Can you please put triple back-ticks around your code (```), instead of using the block quote?

1 Like

yes , Sorry.

I fixed the error , i change PINS

const int BombaAgua = 22;
const int ReflectorPatio = 24;
const int Presurizadora = 26;
const int NivelTanke = 28;
const int SensorPorton = 52;
const int BotonCuarto = 50;

i think 1 conflit with Ethernet Shield.

I have another question that I would like to resolve if I am wrong …

The idea is to change the status of pins within 1 hour.

That is to say.

If i set

Time Day = 5
HourNight = 20

I need to make between 5 and 20 some pins are set to 1.-

And the rest of the hours are in state 0.

But I only need it to run 1 time since if I do it in a loop I can’t turn anything on manually because the 2nd part of the IFF turns them off.