• General
  • Triggering events based on time of day (SNTP or addition of an RTC)

Hi,

I have had a request for a Bela mini project which could start/stop at given dates, times of the day.

Assuming I will be using Puredata, a quick search online brought up [shell] [system.exec] and [time] as possible candidates of which [time] seems to be the most promissing. I realize Bela doesn't have a battery backed clock and that the system clock will reset after power cycling. If an Internet connexion is available could I synchronize the internal clock on boot using SNTP? If an Internet connexion is not available perhaps I could add an I2C RTC?

Anyone tried implementing either of these solutions?

Much appreciated,

    tohox If an Internet connexion is available could I synchronize the internal clock on boot using SNTP?

    Whenever it connects to the internet it automatically tries to synchronise to a remote server. We didn't do anything specific to obtain that, it's built into Debian somehow (I assume as a systemd service?).

    Depending on the use case (i.e.: if you don't need Pd to do anything while waiting for the right time), you can also wrap it all in a bash script:

    while sleep 1; do
      DATE=$(date '+myformat') #TODO: specify appropriate format
      if [  $DATE -ge $MIN_DATE -a $DATE -le $MAX_DATE ] # simple comparison, may be more complex in your case
      then
        # RUN THE PROGRAM
      endif
    done

    This won't put the board into any sort of low-power mode, but that shouldn't be a problem if you are mains-powered. If you are battery-powered, then an RTC with programmable interrupt is probably the best solution, assuming such a device exists ...

    Thanks for the quick reply @giuliomoro!

    I was thinking more along the lines of having the program itself loop while waiting for the appropriate time to arrive. This allows me to do other stuff in the meatime such as playing audio, blinking LEDs etc. I'll look into [time] although I have no idea how to install external objects as of yet.

    I was thinking of small battery backed I2C RTC boards such as those for the Raspberry Pi and Arduno. On the Pi it appears like a pretty straight forward process but I'm not sure how well this ports to Bela.

    Thanks again!

      tohox I'll look into [time] although I have no idea how to install external objects as of yet.

      See here for some examples https://github.com/BelaPlatform/Bela/issues/621 . Alternatively, you can average pd-on-bela's bela_system and call your external program to read the clock and sens it back into Pd (requires pdsend and the latest dev branch of Bela).

      Create a file like this called get_date.sh in the project folder:

       #!/bin/bash
       
       # do magic here to get time into variable TIME, e.g.:
       TIME=$(date +%Y.%m.%d-%T)
       # send TIME to Pd's netreceive
       echo $TIME | pdsend 9999 localhost udp 2>/dev/null

      and using this patch:

      tohox On the Pi it appears like a pretty straight forward process but I'm not sure how well this ports to Bela.

      The port should be pretty straightforward.