I am trying to get a python script to run at startup. @adam has been working with me on this and has been instrumental in boosting my knowledge and knowing what to look for on forums etc. I decided a new thread would be best.The script is designed to look for an input on pin 22 and reboot the Rpi3 when detected. The purpose is to allow my backup solar PLduino to reboot the Rp3 in case I lose communication with it.
I did as adam suggested and added @reboot python /home/pi/reboot8.py to crontab -e but the crontab is empty otherwise as if cron services is ignoring doesnāt use crontab it or something about the script wonāt be allowed to run on startup. A forum Running a Python + OpenCV script on reboot - PyImageSearch talks about virtual console using pi root user sudo /bin/bash. When I get to workon cv it gives me command not found. Do I need to download something like open cv3 or other?
#!/bin/bash
source /home/pi/.profile
workon cv
cd /home/pi/pi-reboot (maybe leave this at /home/pi where my file resides or create that folder and move file there?)
python reboot8.py(changed to show my file)
Does the script work if you run it from the terminal? Running at reboot is not going to give you any output so if something is failing you will never know.
Hereās the output from:
chmod a+x reboot.py (your script)
./reboot.py
Is this the correct mode to run in terminal?
your script:
lines 1 thru 4 import: command not found. line 5 ./rā command not found. line 6 syntax error near unexpected token `(') def reboot(channel)
the other script (the one I found and modified pin assignment) gives the same basic " import: command not found " and lists some directories for mail process which may have been set up to email the coder the output when running the script for error checking. This makes me believe I need to trim down that one script or maybe yours needs tweaking?
If you post the output Iāll be able to tell you what you need to install. Without it itās just guessing 1/4 libraries that need installed. time, os, sys, and rpi.gpio should all be installed by default on Jessie full.
Iād say at that point you need to figure out why the pin isnāt changing value. Check your connectors, make sure there really is 3.3v where you think there is, check to see if the pin is the right pin, etc.
Iām connected with a cobbler and def has 3.3v. Verified correct pin. The other script I used will reboot when pull up on pin but like yours it will not work at reboot.
The other script is using bcm pin numbering and Iām using board numbering. If I had to guess you are on the wrong pin. Thereās no way one works and one doest, itās using the same exact library.
Ok so my old brain was being dumb. Using a hit and miss procedure I found gpio 23 is actually pin 16(pin I chose in your script).
I couldnāt get it to run on startup/reboot so I added sudo python /home/pi/reboot.py & just before the last line in /etc/rc.local. Works like a champ.
A thought crossed my mind, crontab didnāt work for me because I actually wrote a new file. Should have: sudo nano /etc/crontab -e to edit the actual file.
Thanks for your help. I was determined to find a way to prove your script works since obviously youāve been at this longer than I.
William
Treat me like a really young student or dense old geezer and I shall learn wellš
You shouldnāt have to use sudo nano /etc/crontab -e. When you use the command crontab -e it will ask you to choose your editor and create the new file for you when you save.
Finally getting around to adding This reboot python script in this thread.
Credit goes to @adam for helping write this code. Took some forehead smacking but adam came thru and I got the code in the right place and when I click button to reboot Rpi it works flawlessly.