Hi Blynkers,
i`m using a lambda function inside a timer function and having trouble with timer delete and conditions.
The function is to watch a state of an inverter which is controlled by a relais that is connected to pin2 of an esp32.
If the inverter is switched on and the measured current is under a defined value a counter should start. If the current stays below the value and the timer ends, the inverters should switch off. But if the current raises over the value and the timer is running, the timer should stop and restart if the low current conditions match again.
It is running fine until the current raises. Then it seems that all other timers are deleted. What is wrong with that code?
void help_of_Jarvis() {
status_inverter = digitalRead(2);
status_pump = digitalRead(15);
status_boiler = digitalRead(18);
//Disable Inverter when no Device is in use
if (status_inverter == 0) {
if (atm_amp_uni150A * -1 <= 1.5) {
if (!timer.isEnabled(delayedOff)) {
delayedOff = timer.setTimeout(30000L, []() { // Run following command(s) after set time.
digitalWrite(2, HIGH);
Blynk.virtualWrite(V27, 0);
terminal.println("ALARM - Inverter deactivated - no device in use");
}); // END Lambda Function
}
} else {
if (timer.isEnabled(delayedOff)) {
timer.deleteTimer(delayedOff);
}
}
}
}