I have edited rclocal to include this line:
python3 /path/to/my/program.py &
I used an ampersand as my program has an infinite loop.
The program never runs though.
The program:
import RPi.GPIO as GPIO
from time import sleep
from datetime import datetime
import glob, sys, vlc, random
pir = 4
led = 24
GPIO.setmode(GPIO.BCM)
GPIO.setup(pir, GPIO.IN)
GPIO.setup(led, GPIO.OUT)
files = glob.glob("/home/pi/sad/*.mp3")
if len(files) == 0:
# todo: flash led
print("No mp3 files found. Exiting")
sys.exit(1)
random.shuffle(files)
player = vlc.MediaPlayer()
media_list = vlc.MediaList(files)
media_list_player = vlc.MediaListPlayer()
media_list_player.set_media_player(player)
media_list_player.set_media_list(media_list)
def play_audio(channel):
if media_list_player.is_playing():
return
print("Movement detected: " + str(datetime.now()))
media_list_player.play()
print("Detecting...")
try:
GPIO.add_event_detect(pir, GPIO.RISING, callback=play_audio)
GPIO.output(led, GPIO.HIGH)
while True:
sleep(100)
except KeyboardInterrupt:
print("Exiting...")
GPIO.cleanup()
Where would I find the error files to see why it might be going wrong?
As a side note, I have tried a few ways to get this program to run on boot and nothing works.
The program is a very simple 'burglar alarm', fun project which uses a local speaker and a PIR sensor.
Any help would be appreciated at this point.
Edit If I run another file which just flashes an led, it boots and runs fine:
import RPi.GPIO as GPIO
from time import sleep
led = 24
GPIO.setmode(GPIO.BCM)
GPIO.setup(led, GPIO.OUT)
try:
GPIO.output(led, GPIO.HIGH)
while True:
sleep(101)
except KeyboardInterrupt:
print("Exiting...")
GPIO.cleanup()
I have literally no idea why the led ones boots and runs fine but the pir/audio one doesn't.