Where should we preferably put that script in the file hierarchy, and will it run as a deamon as soon as the device starts?
EDIT: Oh wow sorry for bringing an old topic back, I never noticed the year it was posted and it was what came from a search.
EDIT2:
I’ll answer my own question, in case it helps someone else figure out what to do.
In order to have the python script to run at boot, using “supervisor” on the Raspberry Pi:
-
Install supervisor (sudo apt install supervisor
)
-
Create a directory in /var/log/ called blinkstick_remote (sudo mkdir -p /var/log/blinkstick_remote
)
-
Create a python file called blinkstick_remote.py in /usr/local/bin/
-
Copy the script from Example: Control Remotely with your own access code included, but be careful to add the following at the top of the script:
#!/usr/bin/python
(this will be important later on)
-
Once the file is made, make sure to grant it execute rights (sudo chmod +x /usr/local/bin/blinkstick_remote.py
)
-
Create a file called blinkstick_remote.conf in /etc/supervisor/conf.d/ and put the following content
[program:blinkstick_remote.py]
command=/usr/local/bin/blinkstick_remote.py
autostart=true
directory=/tmp
autorestart=true
startsecs=10
startretries=36
redirect_stderr=true
stdout_logfile=/var/log/blinkstick_remote/log.txt
stderr_logfile=/var/log/blinkstick_remote/err.txt
-
run sudo service supervisor restart
to let it relaunch its service, or reboot the Raspberry Pi.
You can check if the service runs with htop (you’ll see an entry /usr/bin/python /usr/local/bin/blinkstick_remote.py as a process). If there’s any problem with the script, you can check the logs in /var/log/blinkstick_remote to troubleshoot the problem.
If the line #!/usr/bin/python
is missing in the python script, supervisor will not be able to execute the script with the following error message in the logs: supervisor: couldn't exec /usr/local/bin/blinkstick_remote.py: ENOEXEC
If all is well, you’ll be able to control your BlinkStick from the Dashboard
Pro-Tip: If you’re behind a restrictive firewall that doesn’t allow port 9292 to go through, replace it with port 80 and it will still work (thanks to the BlinkStick dev who opened it not too long ago!)