Create a crontab job

  • A cron job is an automated program developed for Unix and Linux systems. It allows the user to execute several commands at a specific time on a precise date.
  • We need to run the python script scd30.py every minute. To do that, we use the command crontab.
  • “crontab –l” (that is, lowercase “L” lists what is in the file, and crontab –e lets us edit or add new jobs.
  • Type crontab –e
  • It now asks what editor to use.
  • /bin/nano works much like note pad.
  • vim is used mostly by gurus.
  • ed is an ancient editor.
  • If new to Unix, use nano.
  • For SCD30 Sensor add these lines at the end:
  • * * * * * python3 /home/pi/scd30.py > /home/pi/cron.log
    * * * * * python3 /home/pi/readCSV.py > /home/pi/CSV.log
    

    For the Aranet4 sensor add these lines at the end

    • * * * * * python3 /home/pi/aranet_MM.py > /home/pi/cron.log
      * * * * * python3 /home/pi/readCSV.py > /home/pi/CSV.log
      * * * * * python /home/pi/aranet/aranet.py D4:E3:1A:E6:D4:AD > /home/pi/aranet.txt
      
      For the aranet.py use the MAC address found for Aranet4 device.
  • This will run the python script every minute and update the following files “current.txt”, “left_current”, “aranet.txt which the Magic Mirror app reads. Also will update the daily history file in the data_folder.

NEXT