How to auto run a pidog example script on startup?

Hi Lovely People :slightly_smiling_face:

I have a Pidog V2 on a Raspberry Pi 5 and I would love to have the 20_voice_active_dog_gpt.py script autorun when I boot up the Raspberry Pi, so that effectively the Pidog boots up as an AI enabled voice activated right from the start, similar to the way that you can enable the App control script to autorun. Any help/hints on how I might best do this?

Many thanks for any help anyone may be able to give

Create and edit a service file such as RobApp.service like this

sudo systemctl --force --full edit RobApp.service

Add following to file, swapping names for your own paths etc

[Unit]
After=network.target
[Service]
ExecStart=/usr/bin/python /home/robot/pidog/examples/20_voice_active_dog_gpt.py 
[Install]
WantedBy=multi-user.target

Save and quit the above file edits then run the following commands in terminal

sudo systemctl daemon-reload
sudo systemctl enable RobApp.service
sudo systemctl start RobApp.service

You will still then need a clean shutdown method such as via ssh, as just turning off via the switch could corrupt your sd card. For example you could trap a gpt command, or the head touch sensor etc then shutdown via

import os
os.system("sudo shutdown now")

That’s really helpful, thank you so much; I’ll give it a try :slightly_smiling_face::folded_hands: