Timer and BLYNK_WRITE

Hi, can somebody help. In setup() i have this line timer.setInterval(2000, sensCheck); and in the loop i have this two Blynk.run(); timer.run();.

And when i push the button in the app (it called the BLYNK_WRITE()), the timer stop working.

Thank you for your asnwers

I’m guessing that you have a delay or a while loop in your BLYNK_WRITE function, or called from that function.

You should post your full sketch, correctly formatted with triple backticks at the beginning and end.
Triple backticks look like this:
```

Pete.

#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <SimpleTimer.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>

#define BLYNK_PRINT Serial
#define DIST_TRIG_PIN 18 //ultrazvukovy sensor vzdálenosti (trigger pin)
#define DIST_ECHO_PIN 19 //ultrazvukovy sensor vzdálenosti (echo pin)
#define MOIST_PIN 34 //senzor vlhkosti zeminy
#define LIGHT_PIN 35 //senzor intenzity světla
#define WATER_RELAY 16 //rele 1
#define LIGHT_RELAY 17 //rele 2
#define RELAY_PIN3 25 //rele 3
#define RELAY_PIN4 26 //rele 4
#define TEMP_MOIST_PIN  13 // teplota a vlhkost vzduchu

#define DHT_SENSOR_TYPE DHT11
DHT dht_sensor(TEMP_MOIST_PIN, DHT_SENSOR_TYPE);

const String BLYNK_BLACK =   "#000000";
const String BLYNK_GREEN =  "#23C48E";

//parametry pro Blynk komunikaci 
char auth[] = "xxxxx"; //OAuth kod
char ssid[] = "2.4ghz"; //SSID (název) Wifi AP
char pass[] = "EgHLLk9nsW"; //heslo k Wifi

int Minutes;
int TimerLight;
int LightMode = 1;
bool WaterMode;
int LIntensity;

BlynkTimer timer;

BLYNK_WRITE(V0) //vyber spousteciho rezimu svetel
{
  modeChanger(param.asInt());
}
void modeChanger(int mode){
   switch(mode) {
  case 1: //auto rezim
    
    LightMode = 1;
    timer.deleteTimer(TimerLight);
    digitalWrite(LIGHT_RELAY, HIGH);
    Blynk.setProperty(V12, "color", BLYNK_BLACK);
    Blynk.setProperty(V13, "color", BLYNK_BLACK);

    Blynk.setProperty(V11, "onLabel", "disabled");
    Blynk.setProperty(V11, "offLabel", "disabled");
    
    Blynk.setProperty(V10, "onLabel", "SET");
    Blynk.setProperty(V10, "offLabel", "SET");
    break;
  case 2: // manualni rezim
    LightMode = 2;
    timer.deleteTimer(TimerLight);
    digitalWrite(LIGHT_RELAY, HIGH);
    Blynk.setProperty(V12, "color", BLYNK_BLACK);
    Blynk.setProperty(V13, "color", BLYNK_BLACK);
    
    Blynk.setProperty(V10, "onLabel", "disabled");
    Blynk.setProperty(V10, "offLabel", "disabled");
    
    Blynk.setProperty(V11, "onLabel", "ON");
    Blynk.setProperty(V11, "offLabel", "OFF");

    break;
  case 3: //rezim casovace
    LightMode = 3;
    timer.deleteTimer(TimerLight);
    digitalWrite(LIGHT_RELAY, HIGH);
    Blynk.setProperty(V10, "onLabel", "disabled");
    Blynk.setProperty(V10, "offLabel", "disabled");
    
    Blynk.setProperty(V11, "onLabel", "disabled");
    Blynk.setProperty(V11, "offLabel", "disabled");
    
    Blynk.setProperty(V12, "color", BLYNK_GREEN);
    Blynk.setProperty(V13, "color", BLYNK_GREEN);
    break;
 }
 return;
}

BLYNK_WRITE(V10)
{
  lightAuto(param.asInt());
  
  
}
void lightAuto(int mode) {
  //pokud je aktivni auto rezim osvetleni, po stisknuti tlacitka (V10) se zaznamena hodnota ktera se pote bude porovnavat
  if(LightMode == 1) {
    LIntensity = analogRead(LIGHT_PIN);
    Serial.print(LIntensity);
    return;
  }
  return;
}

BLYNK_WRITE(V11) {
  lightManual(param.asInt());
}
void lightManual(int press) {
  //pokud mame zvoleny manualni rezim (pouze zpristupnime tlacitko, aby mohlo spinat)
  if(LightMode == 2) {
    digitalWrite(LIGHT_RELAY, press);
    return;
  }
  return;
}

BLYNK_WRITE(V12) {
  lightTimeMode(param.asInt());
  
  
}

void lightTimeMode(int mode) {
  //rezim casovace osvetleni
  //pokud zadame hodnotu casu tak spustime casovac, ktery bude volat kazdou minutu funkci lighTimer()
  if(LightMode == 3) {
    timer.deleteTimer(TimerLight);
    digitalWrite(LIGHT_RELAY, LOW);
    Minutes = mode;
    TimerLight = timer.setTimer(200, lightTimer, Minutes);
    return;
  }
  return;
}

BLYNK_WRITE(V14)
{
  waterManual(param.asInt());
}

void waterManual(int press) {
  if(WaterMode == 0){
    
    digitalWrite(WATER_RELAY, press);
    return;
  }
  return;
}

BLYNK_WRITE(V15) {
  waterAuto(param.asInt());
}

void waterAuto(int mode) {
  WaterMode = mode;
  if(WaterMode == 1) {
    Blynk.setProperty(V14, "onLabel", "disabled");
    Blynk.setProperty(V14, "offLabel", "disabled");
    return;
  }
  else {
    Blynk.setProperty(V14, "onLabel", "WATERING");
    Blynk.setProperty(V14, "offLabel", "WATER");
    return;
  }
}


void sensCheck() { //metoda, která sbira data ze sensoru je volaná časovačem 
  //kod pro ovladani ultrazvukového senzoru
  //generovani pulsu
  digitalWrite(DIST_TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(DIST_TRIG_PIN, LOW);
  //měření délky času, za ktery se pulz vrati
  float duration_us = pulseIn(DIST_ECHO_PIN, HIGH);
  //vypocitani vzdálenosti z casu
  float distance_cm = 0.017 * duration_us;
  
  Serial.println(distance_cm);

  //kod pro cteni DHT11 senzoru (teplota a vlhkost vzduchu)
  //vlhkost
  float humi  = dht_sensor.readHumidity();
  //teplota
  float tempC = dht_sensor.readTemperature();

  
  
  Serial.println(humi);
  Serial.println(tempC);

  //ziskani parametru ze senzoru vlhkosti zeminy
  int soilm = analogRead(MOIST_PIN);
  Serial.println(soilm);

  //ziskani parametru ze senzoru intenzity světla
  int light = analogRead(LIGHT_PIN);
  Serial.println(light);

  //podmínka, ktera porovnava hodnotu nahranehe intenziy svetla a okolni, pokud je mensi, tak zapne svetla (pokud je LightMode = 1 -> automaticke zapinani osvetleni)
  if(LightMode == 1) {
    if(LIntensity >= light) {
      digitalWrite(LIGHT_RELAY, LOW);
    }
    else {
      digitalWrite(LIGHT_RELAY, HIGH);
      }
  }
  
  //Odeslani hodnot ze senzoru do virtualnich pinu v aplikaci Blynk
  Blynk.virtualWrite(V1, tempC);  //V5 is for Humidity
  Blynk.virtualWrite(V2, humi);  //V6 is for Temperat
  Blynk.virtualWrite(V3, light);
}

void lightTimer() {
  //casovac pro osvetleni (volani pomoci casovace, ktery je v BLYNK_WRITE(V12)
  Blynk.virtualWrite(V13,map(Minutes, 0, 86400, 0, 1440));
  Minutes -= 1;
  
  if(Minutes == 0){
    digitalWrite(LIGHT_RELAY, HIGH);
    //Serial.print("Minutes0" + IsRunning);
    return;
  }
  return;
}


void setup() {
  Serial.begin(9600);
  dht_sensor.begin();
  timer.setInterval(2000, sensCheck);
xxxx
  // konfigurace pinu pro ultrazvukovy senzor
  pinMode(DIST_TRIG_PIN, OUTPUT);
  pinMode(DIST_ECHO_PIN, INPUT);

  pinMode(LIGHT_RELAY, OUTPUT);
  pinMode(WATER_RELAY, OUTPUT);
  
}

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

I searched and found that i could be BLYNK_WRiTE() doesnt work with timer, so created method for every BLYNK_WRITE() and call in it, ive had it in before.

What is this line of code intended to achieve?

Pete.

This sets the timer to the entered value that the user enters in Blynk, but it doesnt matter because i deleted this part of code and its still doing that thing.

You should post the modified code then, along with details of the symptoms you are observing.

Pete.

I repaired you were, it was because this timer. Thank you