When i read my time alarm it outputs not what i set it as

here is the repositry becouse the code base is big.

This all happens in the src/classes.times_manager.hpp

I set one of the alarms to 00:00 and the other to 14:39 (on line 4, timestate constructor, movetimes constructor), but when I read them with Alarm.read() in the begin method they both return 6:28.

I use an esp32s3 and platformio

Then can you create an MCVE? Oftentimes you'll find your own problem in the process.

Hmm, i have never heard of a MCVE, I'll try to create one

here is the MCVE, it still dose the same thing:

#include <TimeLib.h>
#include <TimeAlarms.h>
#include <Arduino.h>

void alarm_callback()
{
  Serial.println("did something");
}

void setup()
{
    Serial.begin(115200);
    Alarm.delay(100);
    tmElements_t tm;
    tm.Hour=7;
    tm.Minute=34;
    int alarmID=Alarm.alarmRepeat(0, alarm_callback);
    Alarm.write(alarmID,makeTime(tm));
    breakTime(Alarm.read(alarmID),tm);
    Serial.println(tm.Hour);
    Serial.println(tm.Minute);
}

void loop()
{

}

the serial output is:

6
28

instead of:

7
34

Is this the output always, or a sample of that single compile? Are you setting and expecting an alarm and the code is giving you a time or a length of time until the alarm?

It gave me the same output in both the mcve and the full codebase, over multiple compiles. There is a lack of documentation for these functions, so i am asuming, the library is called 'TimeAlarms' by paul stoffregen

I think tmElements_t is from TimeAlarms.h. I read that in the examples and .CPP in the libraries.

If you set the time in TimeLib, and populate all the fields in your tm struct with valid values, your code produces what you are expecting to see.

Replace

    tm.Hour=7;
    tm.Minute=34;

with

    setTime(13, 5, 0, 25, 12, 2023);
    breakTime(now(), tm);
    tm.Hour=7;
    tm.Minute=34;

and you'll get your expected output.

tanks this worked

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.