The Python script needs to be run on startup so we do not need to instantiate it every time. We will make a shell script and let crontab run it on reboot. To do this, first make the shell script.

create a new file inside the folder along with radio.py and predefines.py and name it launcher.sh and add this code:

cd /var/www/flask_dev sudo python radio.py

cd (change directory) will navigate to the folder with your radio.py file in it. I placed mine under /var/www/, but you can place yours in home directory if you want. Just make sure to navigate to it.

Then execute the file as root using sudo.

Now your Raspberry Pi needs to run this little script on startup. First it has to be made executable.

chmod 755 radio.py

The 7, 5, 5 are the permissions for the "owner", "group" and "all users" groups respectively. These numbers are a combination of the numbers 4, 2, 1 and 0.

4 is "read"

2 is "write"

1 is "execute"

0 is "no permission"

so 7 is 4+2+1 for the owner, meaning it has read, write and execute access. the group and all users have no write permissions.

Now we will add this script to crontab.

sudo crontab -e

And enter the following:

@reboot sh /var/www/flask_dev/launcher.sh

This will add your script to crontab, and it will execute it upon each system reboot.

Test it out and see if it all works:

sudo reboot

And that should give you the bread and butter of a simple internet radio! There are plenty of things you can improve and expand upon of course. Im new to Flask, so my code may not have been as efficient as it could have been.

So any criticism and suggestions, please leave them in the comments below. :)

Thanks for reading!