I am trying to set up a Raspberry PI 3b to run a simple Python script to watch for a motion sensor then turn on a power supply ("led") and then play a wav file (see script below)
I have the PI set to boot to CLI. I can execute the script on the CLI: python \home\micgin<me instead of pi>\photosensor_rev1.py and the power supply turns on and the .wav file plays.
Now I want to python script to auto run after power on/boot. I have tried rclocal, bashrc and crontab as described in https://www.dexterindustries.com/howto/ ... t-startup/.
Using rclocal or bashrc or crontab per the website, The photosensor is working and the power supply turns on and off, but no wav file.
From looking at logs I think the error: xdg_runtime_dir not set in the environment
Any ideas what I am doing wrong.
Python script: photosensor_rev1.py
from gpiozero import MotionSensor
from gpiozero import LED
from time import sleep
import glob
import random
import pygame
pygame.init()
howdyfiles = glob.glob("/home/micgin81/Music/*.wav")
led = LED(17)
pir = MotionSensor(4)
while True:
pir.wait_for_motion()
print("You moved")
led.on()
pygame.mixer.Sound(random.choice(howdyfiles)).play()
pir.wait_for_no_motion()
led.off()
print("time out over")
I have the PI set to boot to CLI. I can execute the script on the CLI: python \home\micgin<me instead of pi>\photosensor_rev1.py and the power supply turns on and the .wav file plays.
Now I want to python script to auto run after power on/boot. I have tried rclocal, bashrc and crontab as described in https://www.dexterindustries.com/howto/ ... t-startup/.
Using rclocal or bashrc or crontab per the website, The photosensor is working and the power supply turns on and off, but no wav file.
From looking at logs I think the error: xdg_runtime_dir not set in the environment
Any ideas what I am doing wrong.
Python script: photosensor_rev1.py
from gpiozero import MotionSensor
from gpiozero import LED
from time import sleep
import glob
import random
import pygame
pygame.init()
howdyfiles = glob.glob("/home/micgin81/Music/*.wav")
led = LED(17)
pir = MotionSensor(4)
while True:
pir.wait_for_motion()
print("You moved")
led.on()
pygame.mixer.Sound(random.choice(howdyfiles)).play()
pir.wait_for_no_motion()
led.off()
print("time out over")
Statistics: Posted by micgin81 — Wed Sep 04, 2024 12:33 am