Drop connection

Hello everyone
I wrote a ventilation control where the logic () processes the temperature obtained in the room, and compares it with the V0 and V1 values that I entered in the application on my smartphone, when I set the values 25 and 1, it means that when the temperature drops below 24, the ventilation will turn on, and when there is more than 26, it turns off, but often the connection is broken at around 23.94, this is the last value that the application displays, I think that I did something wrong with the connection, since the ventilation continues to work, the connection is simply broken

#include <Ethernet2.h>
#include <BlynkSimpleEthernet2.h>
#include <Arduino.h>          
#include <DallasTemperature.h>  
#include <OneWire.h>
#define ONE_WIRE_BUS 2  
#define term_power 4    
#define VENT 8
char auth[] = "";
OneWire oneWire(ONE_WIRE_BUS);        
DallasTemperature sensors(&oneWire);  

int need_temp = 0;  
int gester = 0;
void setup()
{
  sensors.begin();              
  pinMode(term_power, OUTPUT);  
  pinMode(VENT, OUTPUT);
  Blynk.begin(auth);
}
BLYNK_WRITE(V0){
  need_temp = param.asDouble();
}
BLYNK_WRITE(V1){
  gester = param.asDouble();
}

double get_tempetature()
{

  digitalWrite(term_power, HIGH);  
  delay(100);                      
  sensors.requestTemperatures();   
  delay(100);
  sensors.requestTemperatures();                          
  double real_temp = double(sensors.getTempCByIndex(0));  

  digitalWrite(term_power, LOW);  
  delay(100);                      

  return (real_temp);
}
void logic()   
{
  double t_value = get_tempetature();
 
 
  Blynk.virtualWrite(V2,t_value);
if (t_value < need_temp - gester)
  {
    digitalWrite(VENT,LOW);  
  }
  if (t_value > need_temp + gester)
  {
    digitalWrite(VENT,HIGH); 
    
  }  
  
}
void loop()
{
  Blynk.syncAll();
  Blynk.run();
  logic();
  delay(3700);
  
}


Hello to you too!
Your loop is a disaster :stuck_out_tongue: Use timers instead.

thanks, I tried to do as in the link, but I still can’t do something
I’m add
BlynkTimer timer;
in setup
timer.setInterval(1000,logic);
and update loop look like

 void loop()
{
  Blynk.syncAll();
  timer.run();
  Blynk.run();
  logic();
  
  
}

but it doesn’t work, connection drops on power up

This causes the Blynk server to push the current stored values for the widgets attached to all virtual and digital pins.
You cannot call this command in the void loop, and it serves no purpose anyway.

If you want to get the app values whenever the device connects or re-connects to the Blynk server then add this function:

BLYNK_CONNECTED()
{
  Blynk.syncAll();
}

This calls your 'logic()` function once every second, so

does not belong in your void loop either.

Why are you requesting the temperatures twice, and what are all these delays for?

Do you really need to run the logic() function once every second?

Pete.