Problems triggering an event using localtimeinfo

Hello, I have been trying for a few days now to get time triggered events to work. Using localtimeiinfo, I am able to get the time to trigger, but it triggers every millisecond. I am not sure how to proceed with fixing this. I am attaching my sketch, This is not all my work, upon aproval from the author, I have been tasked with adding new features and if they work he will implement them into master. Anyways, I hope someone can assist me. Maybe im missing something obvious?

Error log from time trigger. Note: Device crashes and reboots.

is_https_Heroku 0
JSON query NSurl = 'https://api/v1/entries.json'
http.begin OK
Returning with error -1 after 46 ms :-(
connection refused
Battery 4.17 V = 100%
Local time: 12:44:29 DST 0
Sensor time difference = 1634147069 sec
Glyk:  0.0
Last 10 values: 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 
Alarm time difference = 66 sec
Snooze time remaining = 0 sec, Snooze until 0
WARNING NO READINGS
Battery 4.17 V = 100%
Local time: 12:44:44 DST 0
Sensor time difference = 1634147084 sec
Glyk:  0.0
Last 10 values: 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 
Alarm time difference = 81 sec
Snooze time remaining = 0 sec, Snooze until 0
WARNING NO READINGS
Battery 4.17 V = 100%
Local time: 12:44:59 DST 0
Sensor time difference = 1634147099 sec
Glyk:  0.0
Last 10 values: 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 
Alarm time difference = 96 sec
Snooze time remaining = 0 sec, Snooze until 0
WARNING NO READINGS
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
Entered playWAV
volumeGain:2.34
AudioGeneratorWAV::begin: file not open
ntry 0x400806a8

REBOOT

�M5Core2 initializing...axp: vbus limit off
axp: gpio1 init
axp: gpio2 init
axp: rtc battery charging enabled
axp: esp32 power voltage was set to 3.35v
axp: lcd backlight voltage was set to 2.80v
axp: lcd logic and sdcard voltage preset to 3.3v
axp: vibrator voltage preset to 2v
touch: FT6336 ready (fw id 0x10 rel 1, lib 0x300E)
OK
E (1502) SPIFFS: mount failed, -10025
M5Stack CORE2 code starting
Free Heap: 236320
SD Card Type: SDHC
SD Card Size: 15193 MB
Ini file exists
section 'config' has an entry 'nightscout' with value 
section 'config' has an entry 'token' with value
bootpic =
name = dev_unit

BG1248.ino (126.2 KB)

Example trigger code

if(localtimeinfo.tm_hour == 12 && localtimeinfo.tm_min == 45){playwav(test, 6)}

Thank you for your time.

You might be doing this already (4000 lines of code is too much to dig through) but the usual way is to keep track if something is done; below just as an example.

if(localtimeinfo.tm_hour == 12 && localtimeinfo.tm_min == 45)
{
  if(wavPlayed == false)
  {
    wavPlayed = true;
    playwav(test, 6);
  }
  else
  {
    wavPlayed = false;
  }
}

Notes:

  1. It's highly advisable to start splitting your code over more functions. A function should basically fit on a sheet of A4. And in the next step split your code over multiple files.
  2. This basically indicates a design flaw; it will also make your code very difficult to follow; again, more functions.
              }
            }
          }
        }
      }
    }
  }

Thank you, I will definetly try that example. Yes I know the code is messy, the original author left a mess. I'm trying to clean up but it breaks a lot.

Even with this its calling the file multiple times. I cant figure out why.

d.wav
volumeGain:3.51
AudioGeneratorWAV::begin: file not open
E (88960) vfs_fat: open: no free file descriptors
/wav/warningsound.wav
volumeGain:3.51
AudioGeneratorWAV::begin: file not open
E (89031) vfs_fat: open: no free file descriptors
/wav/warningsound.wav
volumeGain:3.51
AudioGeneratorWAV::begin: file not open
E (89102) vfs_fat: open: no free file descriptors
/wav/warningsound.wav
volumeGain:3.51
AudioGeneratorWAV::begin: file not open
E (89173) vfs_fat: open: no free file descriptors
/wav/warningsound.wav
volumeGain:3.51
AudioGeneratorWAV::begin: file not open
E (89244) vfs_fat: open: no free file descriptors
/wav/warningsound.wav
volumeGain:3.51
AudioGeneratorWAV::begin: file not open
E (89315) vfs_fat: open: no free file descriptors
/wav/warningsound.wav
volumeGain:3.51
AudioGeneratorWAV::begin: file not open
E (89386) vfs_fat: open: no free file descriptors
/wav/warningsound.wav
volumeGain:3.51
AudioGeneratorWAV::begin: file not open
E (89457) vfs_fat: open: no free file descriptors
/wav/warningsound.wav
volumeGain:3.51
AudioGeneratorWAV::begin: file not open
E (89528) vfs_fat: open: no free file descriptors
/wav/warningsound.wav
volumeGain:3.51
AudioGeneratorWAV::begin: file not open
E (89599) vfs_fat: open: no free file descriptors
/wav/warningsound.wav
volumeGain:3.51

Is wavPlayed a global (or local static) variable?

It's a global variable. Part of an enum.

The errors do not indicate that triggering of events is not working. It seems the event trigger works just fine and the error is with opening the file.

Sorry if I didn't make it clear, its not that it won't trigger its that it triggers every ms, and I can't figure out why.

How long does 1245 last? One minute? That if statements 'says' for one minute trigger this event.

Now let's say you created a bool alreadyplayed = false

if(localtimeinfo.tm_hour == 12 && localtimeinfo.tm_min == 45 && !alreadyplayed)
in the if statement turn already played to true

add an else statement to the if that turns already played back to false.

OK, I guess I was thinking wrong that it would trigger once. Do you have any guidance on how I'd trigger just once?

I've tried true false tags but that didn't work

post you tried and did not work code.

adding a second check might work especially of the sound byte played is longer then a second.

if((!testrun)(localTimeInfo.tm_hour == 8 && localTimeInfo.tm_min == 7 && localTimeInfo.tm_sec == 3){
  testrun = true;
  helloworld();
}

That may not be a very good way of doing it, sorry. (and yes I just put a second statement in this morning) decided to try helloworld print instead of crashing the device every time.

your code had issue.

Doesn't surprise me :slight_smile: Thank you for correcting it. I will try that right now.

Didn't even trigger with this code....

log:

http.begin OK
[HTTP] GET... code: 200 after 5843 ms
GET() response JSON length = 3045
Free Heap = 119632
JSON deserialized OK
JSON array size = 10
sensDev = xDrip-DexcomG5
sensTime = 1634217915 (JSON 1634217915577) = Thu Oct 14 08:25:15 2021
sensSgv = 11.00
sensDir = Flat
Sensor time: 8:25:15 DST 0
Properties query NSurl = *******
http.begin propertires OK
[HTTP] GET properties... code: 200 after 86 ms
GET() properties response JSON length = 593
Deserialized the second JSON and OK
Battery 4.17 V = 100%
Local time: 8:26:5 DST 0
Sensor time difference = 50 sec
Glyk: 11.0 Flat
Last 10 values: 8.67 8.50 8.83 9.61 10.22 10.33 10.39 10.67 10.89 11.00 
Alarm time difference = 1634217965 sec
Snooze time remaining = 0 sec, Snooze until 0
Battery 4.17 V = 100%
Local time: 8:26:21 DST 0
Sensor time difference = 66 sec
Glyk: 11.0 Flat
Last 10 values: 8.67 8.50 8.83 9.61 10.22 10.33 10.39 10.67 10.89 11.00 
Alarm time difference = 1634217981 sec
Snooze time remaining = 0 sec, Snooze until 0
Battery 4.17 V = 100%
Local time: 8:26:37 DST 0
Sensor time difference = 82 sec
Glyk: 11.0 Flat
Last 10 values: 8.67 8.50 8.83 9.61 10.22 10.33 10.39 10.67 10.89 11.00 
Alarm time difference = 1634217997 sec
Snooze time remaining = 0 sec, Snooze until 0
Battery 4.17 V = 100%
Local time: 8:26:53 DST 0
Sensor time difference = 98 sec
Glyk: 11.0 Flat
Last 10 values: 8.67 8.50 8.83 9.61 10.22 10.33 10.39 10.67 10.89 11.00 
Alarm time difference = 1634218013 sec
Snooze time remaining = 0 sec, Snooze until 0
Battery 4.17 V = 100%
Local time: 8:27:10 DST 0
Sensor time difference = 115 sec
Glyk: 11.0 Flat
Last 10 values: 8.67 8.50 8.83 9.61 10.22 10.33 10.39 10.67 10.89 11.00 
Alarm time difference = 1634218030 sec
Snooze time remaining = 0 sec, Snooze until 0
Battery 4.17 V = 100%
Local time: 8:27:26 DST 0
Sensor time difference = 131 sec
Glyk: 11.0 Flat
Last 10 values: 8.67 8.50 8.83 9.61 10.22 10.33 10.39 10.67 10.89 11.00 
Alarm time difference = 1634218046 sec
Snooze time remaining = 0 sec, Snooze until 0
Battery 4.17 V = 100%
Local time: 8:27:42 DST 0
Sensor time difference = 147 sec
Glyk: 11.0 Flat
Last 10 values: 8.67 8.50 8.83 9.61 10.22 10.33 10.39 10.67 10.89 11.00 
Alarm time difference = 1634218062 sec
Snooze time remaining = 0 sec, Snooze until 0

I'm wondering because Millis works also.. I'm wondering can a time trigger activate a Millis timer?

On an ESP32 millis() is just a function. An ESP32 uses several cycle timers, one cycle timer is a micros timer instead of a millis() timer. If you have hardware timers setup on the ESP32 they are completely separate from the cycle timers.

Code snippets are hard to troubleshoot. Yea, I know 100000 of millions of lines of code your project is. Only you know your codes interactions.

Actually no I don't. As stated in post 1 not all of it is my work I'm just adding additional features.