Howto: wake up with RTC

sudo bash -c "echo date '+%s' -d '+ 10 seconds' > /sys/class/rtc/rtc0/wakealarm"

how do I rewrite the line above in order to get RTC wake up every day at 00:00 ? at a certain day at 00:00?
will it be something like the line below? are there any native means?

"echo 08/08/2020 ' 00:00'   > /sys/class/rtc/rtc0/wakealarm"

"echo '2020-08-09:00:00'  > /sys/class/rtc/rtc0/wakealarm" 
" echo "2020-08-09 15:11:40"  > /sys/class/rtc/rtc0/wakealarm" 

Will any of the commands above work?
How to get it executed everyday? without cron?
NX by default soesn’t have the battery? Does it? for RTC?, as AGX does?
Thanks

I can’t answer the rest of it, but I would try an echo command similar to this:

bash -c "echo $(date '+%s' -d '+ 10 seconds')" > /sys/class/rtc/rtc0/wakealarm

(I only tested to a temp file, I did not test anything to “/sys”, nor when sleeping, nor with sudo…an sudo shell might be better because the redirect might end up being from your default user even if the date command echo is from root)

hi @linuxdev ,

sudo bash -c "echo date '+%s' -d '+ 10 seconds' > /sys/class/rtc/rtc0/wakealarm"

the quoted command is the exact one from the documentation,
It seems to set the wakeup timer for 10 seconds in the future.

I think the documents have an error. To demonstrate, go somewhere you won’t worry about random files, and try this:
sudo bash -c "echo date '+%s' -d '+ 10 seconds' > deleteme.txt

You’ll find that the quoting is not balanced and it drops into a prompt for the rest of the content (the “^C” is me hitting control-c):

> sudo bash -c "echo date '+%s' -d '+ 10 seconds' > deleteme.txt
> ^C

Then compare to:
sudo bash -c "echo $(date '+%s' -d '+ 10 seconds')" > deleteme.txt
…and check the permissions of file “deleteme.txt”. The change to syntax causes correct balance of quotes, but the sudo won’t work because only the echo command is run sudo, and nobody needs sudo to echo. The redirect to a file with that syntax will run as the original user despite root being the one who produced the date stamp. So instead of using sudo, if you first drop into an sudo shell (e.g., “sudo -s”), then the echo itself will also be owned by root. Without this “/sys” will refuse the change to wakealarm.

1 Like

I think you can use the rtcwake tools like below command line.

rtcwake -l -t $(date +%s -d ‘tomorrow 02:00’)

Thank you for your reply!
First attempt to try the suspend state with

sudo bash -c "echo `date '+%s' -d '+ 10 seconds'` > /sys/class/rtc/rtc0/wakealarm"
sudo bash -c "echo mem > /sys/power/state"

seem failed in a way: a) the first command did not seem to wake up; Then after trying power button, the fan started spinning, but the display/keyboard never resumed; Trial used AGX though; as NX doesn’t have RTC batery by default, does it?
ref: https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/power_management_jetson_xavier.html
On the second attempt; however, interruption from keyboard has woken up the system, despite the fact that until I detached/ reattached the usb-c display it wouldn’t display anything.
Upd:

sudo rtcwake -l -t $(date +%s -d ' + 10 seconds')
rtcwake: wakeup from "suspend" using /dev/rtc0 at Thu Aug 20 10:05:01 2020
rtcwake: write error

rtcwake -l -t $(date +%s -d 'tomorrow 02:00')
rtcwake: wakeup from "suspend" using /dev/rtc0 at Fri Aug 21 06:00:00 2020
rtcwake: write error
root@

tried on AGX
UPD: after few trials despite the write error system seem to resume including display output.
The question wheither NX has rtc battery at the default carrier board remains. It seems doesn’t have a battery by defalt so that AGX devkit is more handy for RTC wakeup experiments as it has the battery.
ref: RTC battery

OK, just verify below command.

sudo rtcwake -t $(date +%s -d ’ + 10 seconds’) -m mem -v

nvidia@nvidia-desktop:~$ sudo rtcwake -t $(date +%s -d ' + 10 seconds') -m mem -v
rtcwake: assuming RTC uses UTC ...
Using UTC time.
        delta   = 0
        tzone   = 0
        tzname  = UTC
        systime = 1597920964, (UTC) Thu Aug 20 10:56:04 2020
        rtctime = 1597920964, (UTC) Thu Aug 20 10:56:04 2020
alarm 1597920974, sys_time 1597920964, rtc_time 1597920964, seconds 0
rtcwake: wakeup from "mem" using /dev/rtc0 at Thu Aug 20 10:56:14 2020
suspend mode: mem; suspending system

@ShaneCCC

It works perfectly well.
-m mem
seems to set up the suspension mode state until it resumes further in 10-30 seconds
Maybe you also know how to tell the device to wake up every day at certain time? without using the crontab? with just rtcwakeup somehow?

Thank you very much!

My idea is write a script in the /etc/init.d/ to set it up.

1 Like

Hi @Andrey1984,

You would just try such a basic script at startup as @ShaneCCC mentioned from init.d, or use in a one-shot systemd init service, or do it before suspending. Using integer division of 86400 seconds per day to get time at 0:00. To be run as root (at least for last command):

cursec=`date '+%s'`
lastwakeday=`expr $cursec / 86400`
nextwakeday=`expr $lastwakeday + 1`
nextwakesec=`expr $nextwakeday \* 86400`
echo $nextwakesec > /sys/class/rtc/rtc0/wakealarm
1 Like