hallard / everblu-meters-esp32

Fetch water usage data from Cyble meters for esp8266
8 stars 2 forks source link

Wake hours does not work as expected #3

Open morcus opened 1 month ago

morcus commented 1 month ago

Hello,

Thank you for this project.

I use the default setting in my ESP32: -D WAKE_HOUR=06 -D WAKE_MIN=15 ; wake and measure at this Local Time

And according to the documentation, after a successful reading of the water meter, the next wake should happen the day after at 06h15m. However I noticed that the next programmed wake is planned for the next day at 15h00m as shown bellow:

{ "seconds": 117884, "ts": 1721998807, "date": "Fri Jul 26 15:00:07 2024" }

I see in the code everblu-meters.cpp#L212 that the next wake hour take the WAKE_MIN as a parameter.

Is it done on purpose? If I want my reading to occur at 06:15, should I change WAKE_MIN to 6, or should I modify WAKE_MIN to WAKE_HOUR in line 212?

I also have another question regarding the "hours" information provided to MQTT:

{ "hours": "06:18" }

This information is extracted from the counter or is it provided as an information by this project? It seems my counter is only able to respond between 6AM and 4PM, so if it's read on the counter the information might be incorrect.

Thank you.

morcus commented 1 month ago

I was able to fix the behavior with the following modifications.

I also had to comment the portion of the code that was setting the next wake time for the same day, because the code was attempting to do two reading of the water meter in the morning.

    // We will calculate delay for next measure reading 
    // We passed programmed time for today schedule for tomorrow ?
    // if (nowinfo.tm_hour>WAKE_HOUR || (nowinfo.tm_hour==WAKE_HOUR && nowinfo.tm_min>=WAKE_MIN) ) {
        tominfo->tm_hour = WAKE_HOUR; // ---- changed from WAKE_MIN to WAKE_HOUR
        tominfo->tm_min = WAKE_MIN; // ----- changed from 0 to WAKE_MIN
        tominfo->tm_sec = 0;
        SerialDebug.print("Next wake tomorrow at ");
        SerialDebug.print(tominfo, "%B %d %Y %H:%M:%S");
        // Number of second to wait for wakeup
        next_wake = mktime(tominfo) - now ;
    // } else {
    //     nowinfo.tm_hour = WAKE_HOUR;
    //     nowinfo.tm_min = WAKE_MIN;
    //     nowinfo.tm_sec = 0;
    //     SerialDebug.print("Next wake today at ");
    //     SerialDebug.print(&nowinfo, "%B %d %Y %H:%M:%S");
    //     // Number of second to wait for wakeup
    //     next_wake = mktime(&nowinfo) - now ;
    // }
    SerialDebug.printf_P(PSTR(" (in %d seconds)" CRLF), next_wake);