I am creating this app to run on a raspberry pi so that my family can send pictures to my grandma more easily during the pandemic.
pipenv install
pipenv shell
python main.py- Install the latest version of python 3, whatever it may be at the time.
apt install python3
- The following libraries need to be a version 2.0-0 or higher:
apt install libsdl2-mixer-2.0-0apt install libsdl2-image-2.0-0apt install libsdl2-2.0-0apt install libsdl2-ttf-2.0-0
- Install pygame > 2.0.0
python3 -m pip install pygame=2
- Install dependencies
pip install
- Run the app
python3 main.py
If that works, we can set it up so it runs on boot using a service.
- Create a system service
sudo systemctl edit --force --full foto.service
- Insert the following:
I have no idea what portion in [Unit] actually works as it seems this is an ongoing issue for people trying to run scripts after the network is connected. What I do know works is the ExecStartPre in the [Service] section. Feel free to put up an MR if you can figure it out.
[Unit]
Description=Foto by iamstevedavis
Wants=network.target network-online.target
After=network.target network-online.target
[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi/git/foto
ExecStartPre=/din/sh -c 'until ping -c1 google.com; dosleep 1; done;'
ExecStart=python3 /home/pi/git/foto/main.py
[Install]
WantedBy=multi-user.target- Enable the service
sudo systemctl enable foto.service
At this point you can reboot and see if the service starts. If you need to edit:
sudo systemctl edit --full foto.service
If you want to debug (check if the network is properly connecting):
sudo systemctl status foto.service
Here are a few links on the topic covering the issue I mentioned above:
Improved (=reliable) Wait for Network implementation
systemd: start service at boot time after network is really up
launch program after network up with Stretch
Cause a script to execute after networking has started?
Running a script after an internet connection is established
One additional thing I did was wrote a shell script to automatically pull the latest code on boot. I did not include this in the repo because it's specific to me, you can copy and modify it for your pi. If you do, change your ExecStart to point to the script.
#!/bin/bash
cd ~/git/foto
echo "Pull latest foto"
git pull origin master
echo "Got latest foto"
echo "Starting foto"
python3 /home/pi/git/foto/main.pyThen in your service:
ExecStart=/bin/sh /home/pi/Desktop/foto.sh
Make sure you fill out the required fields in config. Alternatly, you can add a .env file that contains the following so you don't have to make changes to config (.env should be in .gitignore)
[EMAIL]
emailPassword = Password1!
emailHandle = mygreatemailhandle