[Solved] RTC timespecific data to table, too many entries to table

I have RealTimeClock widget running, and every 24th hour at 23:59.59 it adds a variable value to table and resets the variable values.

It works but it adds about 70 entries to the table within that second.

Any idea to only make one entry to the table.

Here’s the specific par of the code:

void loop()
{
  Blynk.run();
  timer.run();
  
  //option for timespecific reset of kWhcounter like every 24 hour
  if (hour() == 23 && minute() == 59 && second() == 59)
  {
    //send data to tabel before resetting
    String CurrentDate = String(day()) + '-' + monthShortStr(month()) + '-' + year();
    Blynk.virtualWrite(V12, "add", rowIndex, CurrentDate, elapsedkWh24hour);
    Blynk.virtualWrite(V12, "pick", rowIndex);
    rowIndex++;

    //resetting counters
    elapsedkWh24hour = 0;
    pulseCount24hour = 0;
  }

}

I think, adding a pause in the loop, will obstruct other functions for that second, but are there other ways to do it?

Just add a flag.

Also you should check for the change in day() and record the last-day as a var

int yester_day;

void loop() {
  Blynk.run();
  timer.run();
  
  //option for timespecific reset of kWhcounter like every 24 hour
  if (day() != yester_day) {
    //send data to tabel before resetting
    String CurrentDate = String(day()) + '-' + monthShortStr(month()) + '-' + year();
    Blynk.virtualWrite(V12, "add", rowIndex, CurrentDate, elapsedkWh24hour);
    Blynk.virtualWrite(V12, "pick", rowIndex);
    rowIndex++;

    //resetting counters
    elapsedkWh24hour = 0;
    pulseCount24hour = 0;

    yester_day = day(); // set flag so the code doesnt repeat
  }
}

Also you should move the entire function behind a SimpleTimer for every second.

sounds interesting but dont know how to (Im only learning)

sorry didnt see your code or it was not shown before :slight_smile:

Thats because I found it too difficult typing hte code changes on my phone lol … had to post it then finish on my pc :stuck_out_tongue:

See the changes in the code? You will not have a repearing issue because you are only looking at the change of state.

Great solution, never thought it this way, then I dont have to fight with seconds.

will try it out

1 Like

Same goes for month() and year()… just create a new var for each to store the comparison value.