I am using cron to start a program on reboot for my Raspberry Pi (running Raspbian). This program rings a bell hourly based on the current time. When the program is run manually using:
the bell rings as it should and everything works fine. However, if my Pi is rebooted for some reason and the bell-ringer program is instead started automatically by cron, GPIO 18 does not activate and the bell does not ring. That said, I know the program has been started since it is shown in my list of processes and it writes to its log indicating when it has rung the bell. Any ideas why this might be occurring?
I'm thinking that for some reason the program is not getting permissions to use the GPIO. I also toyed with the idea that perhaps it needed more time before starting the process and tried adding a 60 second sleep, but this did not cause the bell to ring after a reboot either. My cron code, located at "/etc/cron.d/bell-ringer" is as follows:
SHELL=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin @reboot root start-bell-ringer.sh
Note that I am using the Debian features of cron which allow me to indicate the user in a file without having to go through crontab -e as root. Also, start-bell-ringer.sh is in /usr/local/bin along with the c++ program it actually starts, "bell-ringer".