Timed events at specific time?

I was more concerned with would the site even allow that many characters in a single post.

Just try. If You get the message "too large, more than 9000 chars" Your option is to include a .ino file.

My apolgies, I did not realize I could upload files here, id have done that well before...BG1248.ino (119.1 KB)

Fine. Now it's possible to search criss cross the code. Compiling is not possible due to missing libs.
Late here, high time for sleeping but tomorrow offers new possibilities.

Ok, no worries...Rest well!

Found this.... : I2C BM8563 RTC - Arduino Reference

Any good for You?

I looked at it but didn't fully understand it.....im gonna look again tonight maybe a better look and i'll understand it more. What i didn't get was how to call time on it. like for a if statement ie: hour=8 do xyz

I did just try and program the rtc over ntp using that library and it programmed correctly. So it's defiantly that library now just gotta figure out calling time hour and minutes are all im concerned about.

The lib provides functions You can call. Mostly You can read, hours, minutes, seconds, day of the week, month and year.
Then You use those entities in the logic of Your code.
Poke around in that folder, read whatever is possible to read. Sometimes "class member".hour gives the hour, and so on. Sometimes the function is accessed in another way...

Maybe when you have time you can glance over them? Nothing is popping out to me..

I've tried putting hours minutes hour minute but it says it's not valid

Update, I've tried timestruct. Hours, hour, hours nothing wants to work. I'm at a c
Omplete loss here

Seems like it is something with the whole project, Because I decided to test a blank slate, run just the needed stuff to test and although the file did not play, it tried too....I've used the same timestruct.hours/minutes before and nothing happened....

working sketch

#include "I2C_BM8563.h"
#include <WiFi.h>

#include <Arduino.h>
  #include <M5Core2.h>
  #include <driver/i2s.h>
   
//////AUDIO FUNCTION/////
#include "SPIFFS.h"
#include "AudioFileSourceSPIFFS.h"
#include "AudioFileSourceSD.h"
#include "AudioFileSourceID3.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2S.h"

AudioGeneratorWAV *wav;
AudioFileSourceSD *file;
AudioOutputI2S *out;
AudioFileSourceID3 *id3;
bool playing = false;
#define OUTPUT_GAIN 100

enum soundEffects {
    general_alarm,
     warning,
     warningsound,
lowwarningstillvoice,
lowwarningvoice,
highwarningvoice,
highwarningstillvoice,
updatevoice,
persistenthigh,
noreadingsvoice,
nightmodereminder,
nightmodeon,
nightmodeoff,
inrangestillvoice,
lowalarmstillvoice,
lowalarmvoice,
highalarmvoice,
normalrangevoice,
highalarmstillvoice,
lowalarm,
highalert,
noreading,

   
};

void playWAV (enum soundEffects effect, int volume)
{
    //Serial.println("Entered paciplay_day");
    //printf("Entered paciplay_day\n");

    switch (effect)
    {
        case general_alarm:
            file = new AudioFileSourceSD("/wav/alarm.wav");
            printf("/wav/alarm.wav\n");
            break;
        case warning:
            file = new AudioFileSourceSD("/wav/warning.wav");
            printf("/wav/warning.wav\n");
            break;
            
case warningsound:
            file = new AudioFileSourceSD("/wav/warningsound.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case lowwarningstillvoice:
            file = new AudioFileSourceSD("/wav/lowwarningstillvoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case lowwarningvoice:
            file = new AudioFileSourceSD("/wav/lowwarningvoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case highwarningvoice:
            file = new AudioFileSourceSD("/wav/highwarningvoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case highwarningstillvoice:
            file = new AudioFileSourceSD("/wav/highwarningstillvoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case updatevoice:
            file = new AudioFileSourceSD("/wav/updatevoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case persistenthigh:
            file = new AudioFileSourceSD("/wav/persistenthigh.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case normalrangevoice:
            file = new AudioFileSourceSD("/wav/normalrangevoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case noreadingsvoice:
            file = new AudioFileSourceSD("/wav/noreadingsvoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case nightmodereminder:
            file = new AudioFileSourceSD("/wav/nightmodereminder.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case nightmodeon:
            file = new AudioFileSourceSD("/wav/nightmodeon.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case nightmodeoff:
            file = new AudioFileSourceSD("/wav/nightmodeoff.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case inrangestillvoice:
            file = new AudioFileSourceSD("/wav/inrangestillvoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case lowalarmstillvoice:
            file = new AudioFileSourceSD("/wav/lowalarmstillvoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case lowalarmvoice:
            file = new AudioFileSourceSD("/wav/lowalarmvoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case highalarmvoice:
            file = new AudioFileSourceSD("/wav/highalarmvoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
      
case highalarmstillvoice:
            file = new AudioFileSourceSD("/wav/highalarmstillvoice.wav");
            printf("/wav/warningsound.wav\n");
            break;
            case lowalarm:
            file = new AudioFileSourceSD("/wav/lowalarm.wav");
            printf("/wav/warningsound.wav\n");
            break;
            case highalert:
            file = new AudioFileSourceSD("/wav/highalert.wav");
            printf("/wav/warningsound.wav\n");
            break;
case noreading:
            file = new AudioFileSourceSD("/wav/noreading.wav");
            printf("/wav/warningsound.wav\n");
            break;


    }
            float volumeGain = ((float)volume / 100.0) * 39.0;
  Serial.print("volumeGain:");
  Serial.println(volumeGain);
  id3 = new AudioFileSourceID3(file);
  out = new AudioOutputI2S(0, 0); // Output to builtInDAC
  out->SetPinout(12, 0, 2);
  out->SetOutputModeMono(true);
  out->SetGain(volumeGain);
  wav = new AudioGeneratorWAV();
  wav->begin(id3, out);
}

    


int main()
{
    //using direct numbers
    for (int i = 0; i<14; i++)
    {
        printf("enum value: %d\n", i);
        //playWAV(i, 50);
    }

    //directly calling
    //playWAV(startup, 100);

    // Other way of calling the value
    enum soundEffects sound;
   // sound = error;
    playWAV(sound, 100);
    return 0;
}


// RTC BM8563 I2C port
// I2C pin definition for M5Stick & M5Stick Plus & M5Stack Core2
#define BM8563_I2C_SDA 21
#define BM8563_I2C_SCL 22

// I2C pin definition for M5Stack TimerCam
// #define BM8563_I2C_SDA 12
// #define BM8563_I2C_SCL 14

I2C_BM8563 rtc(I2C_BM8563_DEFAULT_ADDRESS, Wire1);

const char* ntpServer = "time.cloudflare.com";

void setup() {
  // Init Serial
  Serial.begin(115200);
  delay(50);
M5.begin(true, true, true, true, kMBusModeOutput);
   
      M5.Axp.SetSpkEnable(true);
  // Connect to an access point
  //WiFi.begin();                 // Connect to the access point of the last connection
  WiFi.begin("********", "*********");  // Or, Connect to the specified access point

  Serial.print("Connecting to Wi-Fi ");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" CONNECTED");

  // Set ntp time to local
  configTime(-5 * 3600, 0, ntpServer);

  // Init I2C
  Wire1.begin(BM8563_I2C_SDA, BM8563_I2C_SCL);

  // Init RTC
  rtc.begin();

  // Get local time
  struct tm timeInfo;
  if (getLocalTime(&timeInfo)) {
    // Set RTC time
    I2C_BM8563_TimeTypeDef timeStruct;
    timeStruct.hours   = timeInfo.tm_hour;
    timeStruct.minutes = timeInfo.tm_min;
    timeStruct.seconds = timeInfo.tm_sec;
    rtc.setTime(&timeStruct);

    // Set RTC Date
    I2C_BM8563_DateTypeDef dateStruct;
    dateStruct.weekDay = timeInfo.tm_wday;
    dateStruct.month   = timeInfo.tm_mon + 1;
    dateStruct.date    = timeInfo.tm_mday;
    dateStruct.year    = timeInfo.tm_year + 1900;
    rtc.setDate(&dateStruct);
  }
}

void loop() {
  I2C_BM8563_DateTypeDef dateStruct;
  I2C_BM8563_TimeTypeDef timeStruct;

  // Get RTC
  rtc.getDate(&dateStruct);
  rtc.getTime(&timeStruct);

  // Print RTC
  Serial.printf("%04d/%02d/%02d %02d:%02d:%02d\n",
                dateStruct.year,
                dateStruct.month,
                dateStruct.date,
                timeStruct.hours,
                timeStruct.minutes,
                timeStruct.seconds
               );
if (timeStruct.hours == 10 && timeStruct.minutes == 24 && timeStruct.seconds == 0)
{playWAV(noreading, 6);  }
  // Wait
  delay(1000);
}

log:




2021/10/12 10:23:55
2021/10/12 10:23:56
2021/10/12 10:23:57
2021/10/12 10:23:58
2021/10/12 10:23:59
2021/10/12 10:24:00
/wav/noreading.wav
volumeGain:2.34
2021/10/12 10:24:01
2021/10/12 10:24:02
2021/10/12 10:24:03

Wait, you have a main(), a setup() and a loop()? That seems strange...

The original author put the main loop there, something about the finalizewav function....I have redone the main and loop section into one, now i can print the time from rtc, but have a problem where now the second it hits the event time (in this case say 12:30 to play file xyz) it crashes the system, its trying to open the file every ms even if the time is flagged for a certain second.

What happens when you comment out main() completely?

Also, looking at your "log" printout, it appears to be working, except for the actual sound interface.

Have you tried writing a simple sketch that only plays a file? Not all the other stuff?

Also I see this:

  out = new AudioOutputI2S(0, 0); // Output to builtInDAC

Who says, the output to builtinDAC? Can you reference the documentation on that?

This kind of obscure code is a good reason to develop a simple test sketch first.

The log above is from exactly that.

No, it is definitely not a simple test sketch. Get real. Simple means minimal, the least amount of code needed to play a file.

Fine, give me 5 do you want it time event based or just play a file period

Tailor it to test your problem. The time event code seems to work, that was my whole point. Are there no example sketches with the library or device?