ESP8266_AlarmRepeat

Hello every one, i wonna make an alarm clock using ESP8266, OLED 1306.
I wrote this code but the alarm didn't work :o only the clock work normally :confused:

Duplicate topics merged

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Please post your code.
In code tags, of course.

#include <ESP8266TimeAlarms.h>
#include <ESP8266WiFi.h>
#include <time.h>
#include <SPI.h> 

// To control the OLED display we’ll need
#include <Wire.h> 
#include <Adafruit_GFX.h>  
#include <Adafruit_SSD1306.h>

#define OLED_RESET LED_BUILTIN  //4
Adafruit_SSD1306 display(OLED_RESET);


// so that ESP32 can establish a connection with existing network
const char* ssid = "Asus";
const char* password = "88888888";

// adjust the UTC offset for your timezone in milliseconds
// For UTC +1.00 : 1 * 60 * 60 : 3600
int timezone = 3600;

// If your country observes Daylight saving time set it to 3600. 
// Otherwise, set it to 0.
int dst = 0;

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

AlarmId id;

void setup() {

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C

  // Clear the buffer.
  display.clearDisplay();
  display.display();

  Serial.begin(115200);

  display.setTextSize(1);
  display.setTextColor(WHITE);
  
  display.setCursor(0,0);
  display.println("Wifi connecting to ");
  display.println( ssid );

  WiFi.begin(ssid,password);
 
  display.println("\nConnecting");

  display.display();

// The while() loop will keep looping as long as WiFi.status() is other than WL_CONNECTED. The loop will exit only if the status changes to WL_CONNECTED
  while( WiFi.status() != WL_CONNECTED ){
      delay(500);
      display.print("."); 
      display.display();       
  }

  // create the alarms, to trigger at specific times
  Alarm.alarmRepeat(8,30,0, MorningAlarm);  // 8:30am every day
  Alarm.alarmRepeat(12,34,20,EveningAlarm);  // 5:45pm every day
  Alarm.alarmRepeat(dowSaturday,8,30,30,WeeklyAlarm);  // 8:30:30 every Saturday

  // create timers, to trigger relative to when they're created
  Alarm.timerRepeat(15, Repeats);           // timer for every 15 seconds
  id = Alarm.timerRepeat(2, Repeats2);      // timer for every 2 seconds
  Alarm.timerOnce(10, OnceOnly);            // called once after 10 seconds
  

  // Clear the buffer.
  display.clearDisplay();
  display.display();
  display.setCursor(0,0);
  
  // Print out the IP address assigned to the ESP module by DHCP
  display.println("Wifi Connected!");
  display.print("IP:");
  display.println(WiFi.localIP() );

  display.display();

  //init and get the time
  configTime(timezone, dst, "pool.ntp.org");
  display.println("\nWaiting for NTP...");

  while(!time(nullptr)){
     Serial.print("*");
     
     delay(1000);
  }
  display.println("\nTime response....OK"); 
  display.display();  
  delay(1000);

  display.clearDisplay();
  display.display();
}

void loop() {

  // Time structure
  // Structure containing a calendar date and time broken 
  // down into its components.
  time_t now = time(nullptr);
  struct tm* p_tm = localtime(&now);
  
  Serial.print(p_tm->tm_mday); // day of the month 1-31
  Serial.print("/");
  Serial.print(p_tm->tm_mon + 1); // months since January 0-11
  Serial.print("/");
  Serial.print(p_tm->tm_year + 1900); // years since 1900
  
  Serial.print(" ");
  
  Serial.print(p_tm->tm_hour); // hours since midnight 0-23
  Serial.print(":");
  Serial.print(p_tm->tm_min); // minutes after the hour 0-59
  Serial.print(":");
  Serial.println(p_tm->tm_sec); // seconds after the minute 0-59
  
  // Clear the buffer.
  display.clearDisplay();
 
  display.setTextSize(3);
  display.setTextColor(WHITE);
  
  display.setCursor(0,0);
  display.print(p_tm->tm_hour);
  display.print(":");
  if( p_tm->tm_min <10)
    display.print("0"); 
  display.print(p_tm->tm_min);
  
  display.setTextSize(2);
  display.setCursor(90,5);
  display.print(".");
  if( p_tm->tm_sec <10)
    display.print("0"); 
  display.print(p_tm->tm_sec);

  display.setTextSize(1);
  display.setCursor(0,40);
  display.print(p_tm->tm_mday);
  display.print("/");
  display.print(p_tm->tm_mon + 1);
  display.print("/");
  display.print(p_tm->tm_year + 1900);

  display.display();

  Alarm.delay(1000); // update every 1 sec 
}

// functions to be called when an alarm triggers:
void MorningAlarm() {
  Serial.println("MorningAlarm: - In the morning, you should take ...");
}

void EveningAlarm() {
  Serial.println("EveningAlarm: - In the evening, yous should take ...");
}

void WeeklyAlarm() {
  Serial.println("WeeklyAlarm: - its Monday Morning");
}

void ExplicitAlarm() {
  Serial.println("ExplicitAlarm: - this triggers only at the given date and time");
}

void Repeats() {
  Serial.println("15 second timer");
}

void Repeats2() {
  Serial.println("2 second timer");
}

void OnceOnly() {
  Serial.println("This timer only triggers once, stop the 2 second timer");
  // use Alarm.free() to disable a timer and recycle its memory.
  Alarm.free(id);
  // optional, but safest to "forget" the ID after memory recycled
  id = dtINVALID_ALARM_ID;
  // you can also use Alarm.disable() to turn the timer off, but keep
  // it in memory, to turn back on later with Alarm.enable().
}

void digitalClockDisplay() {
  time_t tnow = time(nullptr);
  Serial.println(ctime(&tnow));

}