Jumat, 07 April 2017

Run python automatic in Raspi 3

To use crontab with your Raspberry Pi to automate your programs, follow these steps:
  1. Write your program and note down its location. We’ll be using a program called py_test.py and save it at /home/pi/Desktop/pyprogSave the file and note the location
  2. Now open crontab.  You may need to open crontab in root (add sudo before the command!).
    crontab -e
    Open crontab
  3. Add a new entry at the very bottom with @reboot to specify that you want to run the command at boot, followed by the command. Here we want to run the python program and save the output in log.txt, so our entry is 
    @reboot sudo python /home/pi/Desktop/pyprog/pytest.py
     /home/pi/Desktop/pyprog/log.txt
    Open crontab
  4. Now save the file and exit.Add the entry for reboot
  5. When you restart the pi, the command will be run and we will get the output log file.Program run and log createdBe a bit careful with the permissions and making sure that your program runs properly before you put it on boot: you can waste a lot of time trying to figure out what went wrong!
  6. Having trouble?  Check your bootlog:

grep cron /var/log/syslog
sumber :https://www.dexterindustries.com/howto/auto-run-python-programs-on-the-raspberry-pi/

Tidak ada komentar:

Posting Komentar