Open seamusdemora opened 3 years ago
This repo is old, you can do everything with the standard-driver now.
You should have a look at two of my other repos: one is https://github.com/bablokb/pcb-pi-batman (scroll to the bottom for the complete /boot/config.txt
) which has a much simpler hardware-solution. The second is the repo https://github.com/bablokb/uptime-manager. This repo does not yet have a readme, but if you look at the code in the files/usr/local/sbin
directory, you will find a small script um_set_boot
which sets the alarm. The uptime-manager lets you configure times when the Pi should be up, but this is probably not suited for your use-case.
Be sure to add the wakeup-source parameter to the overlay
dtoverlay=i2c-rtc,ds3231,wakeup-source
Doing a
cat /proc/driver/rtc
will give you the current state of your rtc.
I'm overwhelmed :) Let me try to digest this & I'll follow up here if that's OK?
No problem. Maybe to sum up things
wakeup-source
to the overlaydate -d "tomorrow 08:00" +%s > /sys/class/rtc/rtc0/wakealarm
cat /proc/driver/rtc
You need root-permissions for the command that sets the alarm time. See the man-page of date
for details on how to specifiy the date (the %s-format is important). Note that if you manually reboot before the alarm fires, the alarm is deleted automatically and has to be reset.
Helpful summation! Just so I am clear - is this a summation for this repo ("pi-wake-on-rtc"), and not the "batman" or "uptime-manager" repos?
wakealarm
must be set in this way: date -d '+ 2 minutes' +%s | sudo tee /sys/class/rtc/rtc0/wakealarm
Once wakealarm
has been set, I do see the INT
pin transition from "HIGH" to "LOW". Tonight, I see it remain LOW for a long time. I took 3 measurements on my o'scope & got 3 different values:
While the INT
pin is LOW, the wakealarm
value remains set, and cannot be overwritten. Eventually, the wakealarm
value is cleared, and I can set it again.
This behavior is different from last night - the wakealarm
value was cleared immediately (or almost immediately anyway). Two things have changed between last night & tonight: I re-installed fake-hwclock
, and ran apt update & upgrade
.
Is there a "control" to clear the alarm?? Could the re-installation of fake-hwclock
) have caused this?
This is for the newer repos, not pi-wake-on-rtc, which uses a python-lib to set the alarms.
To clear the alarm-date, write a zero to the wakealarm file. This might also clear the alarm-state, but I haven't tried. It is usually the driver at boot which resets the alarm. The code in this repository can do all this, that is the reason I wrote it.
And you should not use fake-hwclock together with a real rtc, this won't work.
Dear Bernhard,
I really appreciate this project and i use this method intead of hwclock on some of my rpi computers.
Unfortunatelly I faced that it doesn't work with the newest raspbian OS due to the version of python. (I tried to force python2, but the smbus library seems missing, and seems to be no longer available for python2. ). In the end I updated your code to python3 on my computer. I am still testing it, it looks to be okay. Are you interested the updated files (rtcctl and ds3231.py)?
Thank you for your effort on this project again! Best Wishes: Janos
Hi Janos,
that would be great. Could you fork the repo, update the python-files and create a pull-request? I will be happy to merge the changes, since python2 is outdated. The only reason I haven't updated this is that the standard driver now does everything I need. (but I do have some older systems still using this).
Thanks, Bernhard
@bablokb :
The only reason I haven't updated this is that the standard driver now does everything I need. (but I do have some older systems still using this).
Could you tell us which standard driver are you referring to?
Thanks!
That is written above in the commands:
dtoverlay=i2c-rtc,ds3231,wakeup-source
This is the standard driver. With the command
date -d "date-time-spec" +%s > /sys/class/rtc/rtc0/wakealarm
You can set the alarm (see comments above about variation if sudo is needed).
cat /proc/driver/rtc
will let you query datetime, alarm-state and time and so on of your rtc. All of this also works for other RTCs, as long as the driver implements the standard kernel-interfaces for RTCs.
The python-lib here allows a different level of control over the RTC, e.g. it also supports alarm2. But most of the time I only need the standard functionality.
@bablokb,
Ah - yes... I knew of that & have used it for a while now. I'm sorry to have troubled you, but when you said it was new I assumed it was one I wasn't aware of.
Thanks
Hello Bernhard,
Great! I've tried to fork the repo and upload the files according to tutorials, I don't know wether it was succesful. I made a folder named python3 with the new files. Can you see that ones? If yes, please take a look, and test it if you have chance.
Thanks
Well, I can see your fork here: https://github.com/UtolsoLoteriKutya/pi-wake-on-rtc But it seems you have not changed anything, it still tells me it is up to date with my branch.
Normally, you would download your fork to your pc
git clone https://github.com/UtolsoLoteriKutya/pi-wake-on-rtc.git
and then change/add files. The changed/new files need to be added to the clone on your PC
cd pi-wake-on-rtc
edit/create files
git add file1 file2 file3...
and commited, e.g.
git commit -m"ported to python3"
Then you would push this to your fork
git push
Once you have pushed the code, it is visible on github and you can create a pull request using the github website.
I hope this helps.
Bernhard
For info: very nicely done (the install script is way past my ability). It appears to me that the only changes necessary for Rpi 4B, Ubuntu 20.04.1, and python3 are: 1) after an ssu: 2to3 -w for all the python files. and 2) change line 75 of ds3231.py to return int(out / 10) Note: it also works for ds3232 (same as ds3231 but also has some static storage - useful for persistent keys).
Sorry, I spoke too quickly. It is also necessary to put comment lines in /etc/wake-on-rtc.conf on separate lines and the chang shebangs (#!) to #!/use/bin/python3 or equivalently make /usr/bin/python a symbolic link to python.
Sorry, I spoke too quickly. It is also necessary to put comment lines in /etc/wake-on-rtc.conf on separate lines and then change the shebangs (#!) to #!/use/bin/python3 or equivalently make /usr/bin/python a symbolic link to python3. (Yech!)
This is the repo I have been looking for - and you have done it extremely well!
I am working on something very similar: I want to use my RPi 3B in an "off-grid" application. The system is powered by a 30 watt solar panel, and therefore the RPi must be powered OFF when it is not required. I have worked out a method that should work to remove power from the RPi, but I have been struggling to devise a method to restore power. It seems you found an answer - even before I thought of the problem :)
My question has to do with setting the DS3231 alarm: As my DS3231 is set up now (using
dtoverlay=i2c-rtc,ds3231
), the DS3231 registers cannot be accessed when the RPi is running. But I need to be able to set the alarm time based on inputs from the system's sensors. I've seen that you do not use the system driver, but replace it with your software. And so my question is, "Does your design allow the RPi to set the alarm time while the DS3231 is maintaining time for the system?"