First post and also first time experimenting with a PI & Python.
I have a pi-3 model B with the 7" touchscreen and PIR sensor. My goal is to have it set up so that it constantly displays the stream from my IP camera. To save power consumption I also want to include a motion detection to toggle the display on/off when motion is detected.
My startup.py script is as follows:
import os, time, logging
logging.basicConfig(filename='Startup.log',level=logging.DEBUG)
logging.info('Logging started')
from gpiozero import MotionSensor
#Start stream
os.system("omxplayer --aspect-mode stretch rtsp://Username:Password@IPaddress:port/videoMain")
#Screen OFF
os.system("bash -c 'echo 1 > /sys/class/backlight/rpi_backlight/bl_power'")
#PIR sensor function, motion detected -> screen ON, wait x seconds, screen off
pir = MotionSensor(4)
while True:
if pir.motion_detected:
#Screen ON
logging.info('Motion detected')
os.system("bash -c 'echo 0 > /sys/class/backlight/rpi_backlight/bl_power'")
#Wait x seconds
time.sleep(180)
logging.info('timer reached')
#Screen OFF
os.system("bash -c 'echo 1 > /sys/class/backlight/rpi_backlight/bl_power'")
When running this script, omxplayer plays the stream, but it seems the python script does not continue. Only when killing omxplayer, the script continues, turning the screen on/off when motion is detected. How can I get the stream to play combined with the motion detection functionality?