Hello,
I have created a script that plays a random mp3 when motion is detected. It uses VLC to play the file. It works fine when starting the script from the terminal or running it in Thonny. I then wanted it to run at startup. I tried various ways to have it run at startup, local.rc, bash, systemd… but none seemed to work. After investigating I realized the script was starting, but I don’t believe that VLC is starting properly. Is there any reason VLC would work when manually starting the script but not when attempting to have it run at startup? Thank you!
Here is my script:
from gpiozero import MotionSensor
import random
import os
pir = MotionSensor(23)
while True:
pir.wait_for_motion()
songs = [f for f in os.listdir("/home/jasonc/Music") if f.endswith(".mp3")]
song = random.choice(songs)
os.chdir("/home/jasonc/Music")
os.system("vlc " + song)
I have created a script that plays a random mp3 when motion is detected. It uses VLC to play the file. It works fine when starting the script from the terminal or running it in Thonny. I then wanted it to run at startup. I tried various ways to have it run at startup, local.rc, bash, systemd… but none seemed to work. After investigating I realized the script was starting, but I don’t believe that VLC is starting properly. Is there any reason VLC would work when manually starting the script but not when attempting to have it run at startup? Thank you!
Here is my script:
from gpiozero import MotionSensor
import random
import os
pir = MotionSensor(23)
while True:
pir.wait_for_motion()
songs = [f for f in os.listdir("/home/jasonc/Music") if f.endswith(".mp3")]
song = random.choice(songs)
os.chdir("/home/jasonc/Music")
os.system("vlc " + song)
Statistics: Posted by jasonco — Sun Apr 28, 2024 4:40 am