ds3231 alarm2 not triggering

hello
i’m using an esp32, a ds3231 and a 4 channel rellay (which control a lamp and a air pump)
i set two alarms using the rtc alarm1 and alarm2, alarm1 triggers ok, alarm2 never triggers

here’s part of the code regarding the alarms:

#include "time.h"
#include "RTClib.h"
#include <Wire.h>

#define CLOCK_INTERRUPT_PIN 13
RTC_DS3231 rtc;

// ...

void setup() {
  // ...

  if (!rtc.begin()) {
    timeError = 1;
    Serial.println("Couldn't find RTC");
  }

  rtc.disable32K();
  rtc.writeSqwPinMode(DS3231_OFF);
  pinMode(CLOCK_INTERRUPT_PIN, INPUT_PULLUP);
  rtc.clearAlarm(1);
  rtc.clearAlarm(2);
  rtc.setAlarm1(DateTime("", "15:00:00"), DS3231_A1_Hour);
  rtc.setAlarm2(DateTime("", "22:00:00"), DS3231_A2_Hour);
}

void loop() {
  if(rtc.alarmFired(1)) { 
    rtc.clearAlarm(1); 
    // turn on devices connected on the relay ON
    operateDispositive("all", true);
    Serial.println("alarm 1 have been triggered");
  } 
  
  if(rtc.alarmFired(2)) { 
    rtc.clearAlarm(2); 
    // turn on devices connected on the relay OFF
    operateDispositive("all", false);
    Serial.println("alarm 2 have been triggered");
  }
}

what could be the issue?

ps: through this past 7 days, alarm2 triggered once

Did You start the project and let it run for 7 days without interruption? Restarting it close to alarm2 time could possibly make loss of alarm. Start up takes a few seconds.

no it did run for 7 days straight, but had very few interrupts
i really don't think that's the issue, i set it up and let it be, i don't mess with it constantlynot

here's part of the code

...that probably doesn't contain the error

Okey. It' looks like a strange problem but we will nail it.
Supply the complete code, not parts of it. I can't se any access of the realy board.

I ask You to show the wiring diagram inluding power supply.

Give us links for the relay board and the pump.
I can think of a few troubeling things.

Railroader:
Okey. It’ looks like a strange problem but we will nail it.
Supply the complete code, not parts of it. I can’t se any access of the realy board.

I ask You to show the wiring diagram inluding power supply.

Give us links for the relay board and the pump.
I can think of a few troubeling things.

the pump is an old aquarium pump, i couldn’t provide much about it
the relay i bought on aliexpress, the product is no longer available so the link doesn’t work, i will attach a picture of it

#include "time.h"
#include "RTClib.h"
#include <Wire.h>

#define CLOCK_INTERRUPT_PIN 13
RTC_DS3231 rtc;

const int relayLight = 15;
const int relayFilter = 4;
bool lightState = false;
bool filterState = false;

void operateDispositive(String name, bool state);

void setup() {
  Serial.begin(115200);
  Serial.println();

  digitalWrite(relayLight, HIGH);
  digitalWrite(relayFilter, HIGH);
  pinMode(relayLight, OUTPUT);
  pinMode(relayFilter, OUTPUT);

  if (!rtc.begin()) {
    timeError = 1;
    Serial.println("Couldn't find RTC");
  }

  if(rtc.lostPower())
    Serial.println("rtc lost power");

  rtc.disable32K();
  rtc.writeSqwPinMode(DS3231_OFF);
  pinMode(CLOCK_INTERRUPT_PIN, INPUT_PULLUP);
  rtc.clearAlarm(1);
  rtc.clearAlarm(2);
  rtc.setAlarm1(DateTime("", "15:00:00"), DS3231_A1_Hour);
  rtc.setAlarm2(DateTime("", "22:00:00"), DS3231_A2_Hour);
}

void loop() {
  if(rtc.alarmFired(1)) {
    rtc.clearAlarm(1);
    // turn on devices connected on the relay ON
    operateDispositive("all", true);
    Serial.println("alarm 1 have been triggered");
  }
 
  if(rtc.alarmFired(2)) {
    rtc.clearAlarm(2);
    // turn on devices connected on the relay OFF
    operateDispositive("all", false);
    Serial.println("alarm 2 have been triggered");
  }
}

void operateDispositive(String name, bool state) {
  if (name == "all") {
    filterState = state;
    lightState = state;
    if (state) {
      digitalWrite(relayLight, LOW);
      digitalWrite(relayFilter, LOW);
      Serial.println("Light and Filter ON.");
    } else {
      digitalWrite(relayLight, HIGH);
      digitalWrite(relayFilter, HIGH);
      Serial.println("Light and Filter OFF.");
    }
  } else if (name == "light"){
    lightState = state;
    if (state){
      digitalWrite(relayLight, LOW);
      Serial.println("Light ON.");
    } else {
      digitalWrite(relayLight, HIGH);
      Serial.println("Light OFF.");
    }
  } else if (name == "filter") {
    filterState = state;
    if (state) {
      digitalWrite(relayFilter, LOW);
      Serial.println("Filter ON.");
    } else {
      digitalWrite(relayFilter, HIGH);
      Serial.println("Filter OFF.");
    }
  } else {
    Serial.println("Invalid dispositive.");
  }
}

Okey but not what I would like to read.
Can You disconnect the relay board and any other hardware and run Your code in order to get some results?

Again, show the wiring of the project. You can't imagine how often this shows the problem.

here’s the wiring

i am planning on powering the relay with a phone charger, using the jd-vcc instead of power it with the esp32.
do you think it could be power related?
because the first alarm the power the devices on, works ok, no error no nothing
the second alarm that should turn them of, just don't do nothing

should i use a resistor as pullup on the sqw pin, or the input_pullup is ok?

Show the power supply connection.

Normal 5v relay card wiring:

larryd:

Show the power supply connection.

Normal 5v relay card wiring:

at the moment the project is powered with a phone charger (5v 500mA) connected to the esp32 micro usb port, the relay to the Vin pin of the esp32 (5v) and the ds3231 to the vcc pin of the esp32 (3v3)

Could it be a problem with the library?
Which alternative you guys recommend for me to try out?

Several years back, I used Jack christensen’s library and had no problem with it.

Jack has 15 or so examples in the library.

thanks @larryd, the ds3232rtc library seems to work very well.
i will continue to test it with new alarms for a couple of days to be sure everything is ok.

now i have a different problem the year is 50 instead of 2020 and the hour is 1 hour ahead.
i’m taking the time with ntp, and the time stored on the esp32 is correct, but when i save it on the rtc.
@larryd, have this ever happen to you, how did you fix it?

here’s my code:

#include "WiFi.h"
#include <DS3232RTC.h>
#include "time.h"

DS3232RTC RTC(false);
tmElements_t dt;

const char* ssid = "ssid";
const char* password =  "password";

const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec = -3600;
const int   daylightOffset_sec = 0;
char daysOfTheWeek[7][14] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
char months[12][14] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

void setup() {
  struct tm timeinfo;

  Serial.begin(115200);
  Serial.println();
 
  while ((WiFi.status() != WL_CONNECTED) || (WiFi.status() == WL_NO_SSID_AVAIL)) {
    delay(500);
    Serial.println("Connecting to WiFi..");
    WiFi.begin(ssid, password);
  }
  Serial.println();
  Serial.print("Connected to the WiFi network: ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  RTC.begin();

  Serial.println();
  Serial.println("Updating Time and Date from NTP server.");

  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;
  }

  Serial.println();
  Serial.println("Time from NTP stored on ESP32");
  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");

  RTC.set(mktime(&timeinfo));

  Serial.println();
  Serial.println("Time stored on DS3231");
  RTC.read(dt);
  Serial.print(daysOfTheWeek[dt.Wday - 1]);
  Serial.print(", ");
  Serial.printf(months[dt.Month - 1]);
  Serial.printf(" %02d %4d", dt.Day, dt.Year);
  Serial.printf(" %02d:%02d:%02d", dt.Hour, dt.Minute, dt.Second);
  Serial.println();
}

void loop() {
}

the output is:

Time from NTP stored on ESP32
Tuesday, September 15 2020 03:14:27

Time stored on DS3231
Tuesday, September 15   50 04:14:27