hoping someone can help. i'm new to python and trying to start a script on boot on raspbian. Nothing i try seems to work and just seeing what I am missing. A very basic script to play an audio file when it receives a UDP command.
I have so far tried - starting it from rc.local, starting it in .bashrc (this work when i start a new terminal via ssh, staring from init.d, below is the init.d script, the .py standard script is the same minus the Init info....
#! /usr/bin/python3
# /etc/init.d/UDP_Python_Omxplayer.py
### BEGIN INIT INFO
# Provides: UDP_Python_Omxplayer.py
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
import socket
import os
UDP_IP = "192.168.123.10"
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print ("received message:", data)
command = str(data.decode('ASCII'))
if command == "Play":
os.system("omxplayer -o both --no-osd /home/pi/Doc*/Air*")
As above, the scripts work, i just cannot get this to autmate and run int he background on boot?
thanks in advance...
Have tried in a cron job with the following:
sudo crontab -e
and added
@reboot sudo python /home/pi/UDP_Python_Omxplayer.py
also have made this into a service, which if i start the service manually then it works fine, but again from boot does not..