Autostart an app on reboot - Raspberry Pi

Option 1:

pi@raspberrypi:~ $sudo nano /etc/rc.local

#add path before exit 0 line:

su - pi -c "sleep 10 && export DISPLAY=:0 && cd "folderPath" && /usr/bin/python3 fileName.py" &

CTRL+O  // to save the changes
Enter
CTRL+X  // to close the file editor

pi@raspberrypi:~ $sudo reboot
(To check the autostart of the software app.)


Option 2:
go to /home/pi/.config
create an autostart folder
create a .desktop file into this.

add path of an autoreboot.sh file to it with delay : app.Desktop file
[Desktop Entry]

Exec=sh -c "sleep 15; /home/pi/on_reboot.sh"


Create a virtual environment myenv
add app folder to myenv
create a on_reboot.sh file in /home/pi/ folder.  Add following paths into this file:

#!/bin/bash
source /home/pi/Documents/myenv/bin/activate
cd /home/pi/Documents/myenv/MyApp
python3 app.py


sudo reboot to check the autostart of the software app.




Comments

Popular posts from this blog

Setting up a USB thermal printer with a Raspberry Pi 3B+

Basic Input/Output C Program