First: Thanks again to all the help from you guys.
What i am trying to do: I want to create a counter that is counting down. When the counter reaches zero an event should be triggered. It should also be possible to "refresh" the counter back to its starting value. When my ESP32 is unbplugged and replugged the counter should still be the same. So i have to store the current data into my "ESP-EEPROM".
I looked into diffrent threads. This is what i have so far:
The button that refrehs my counter back to its starting value:
void resetServiceIntervallPopCallback(void *ptr)
{
DateTime now = rtc.now();
DateTime future (now + TimeSpan(0,0,4,0)); //gives me the time 4 minutes into the future
GenInfo._serviceIntervall = future.unixtime(); //store seconds since1970 into _serviceIntervall
}
The counter (as far as i see) works as i want. The messages, when the counter reaches zero does also what i am expecting, but i have troubles with storing the data into EEPROM
The problem that i have: i cant handle it, that "write into EEPROM" just appears every minute (counter ). The idea behind it is , that in the future i dont want to write the data every second into EEPROM
What you describe will very quickly wear out any built-in EEPROM. EEPROM has a limited life, often as little as 10,000 writes, before it no longer works reliably. There are external, I2C or SPI, EEPROMs that are good for as many as 1,000,000 writes.
Since i store the counter into my copycounter (counter_copy = counter;) i would expect that IF
the minute changes (counter = (GenInfo._serviceIntervall - timeNow)/60;) the if clause should be triggered
if (counter_copy!=counter)
{
Serial.println("Write into EEPROM;");
}
So what i figured out.
in this part
if (counter_copy!=counter)
{
Serial.println("Write into EEPROM;");
}
It appears you initially set the counter to count at 4 minutes intervals from the current time, making the counter reach 0 at 4 minute intervals. Would be easier to save the initial time in eprom, then when restating get the current time, calculate where in the 4 minute cycle you are currently, and restart the timer from there.
thats why i store the counter at the end of the code into counter_copy. So that only when counter (that are days now) changes, the value will be written into eprom. But i dont know why
if (counter_copy!=counter)
{
Serial.println("Write into EEPROM;");
}
I don't see why you need to store the counter itself into EPROM, what you need is the original start time and the interval, that will allow you to restart the counter in sync with the original timing. Or am I misunderstanding what you are trying to accomplish.
What i try to accomplish: A timer (that can be reseted) that counts down. When i unplugg my ESP, the timer should not start again from the begining. So thats why i need the eprom
Lets say:
With this function i generate the seconds since 1970 until my future event
void resetServiceIntervallPopCallback(void *ptr)
{
DateTime now = rtc.now();
DateTime future (now + TimeSpan(0,0,4,0)); //gives me the time 4 minutes into the future
GenInfo._serviceIntervall = future.unixtime(); //store seconds since1970 into _serviceIntervall
}
My future event is for testing purpose 4 minutes into the future. ( in the endphase this will be days).