We now need to make our wearableHat.py program run automatically when we switch our Pi Zero on. We are going to do this in the same way we did in the previous chapters:
First, we must make the Python program we just wrote executable:
chmod +x ./wearableHat.py
Now, we will create our service definition file:
sudo nano /lib/systemd/system/wearableHat.service
Now, type the definition into it:
[Unit]
Description=Wearable Hat Service
After=multi-user.target
[Service]
Type=idle ExecStart=/home/pi/WearableTech/Chapter4/wearableHat.py
[Install]
WantedBy=multi-user.target
Save and exit Nano by pressing Ctrl + O, followed by Enter, and then Ctrl + X. Now, change the file permissions, reload the systemd daemon and activate our service by typing this:
sudo chmod 644 /lib/systemd/system/wearableHat.service
sudo systemctl daemon-reload
sudo systemctl enable...