To run the IoT Hub Dashboard when the Raspberry Pi boots up, you need to make the code.py file an executable. To do this, add a shebang to the first line of code.py, above the SPDX license.
#!/usr/bin/env python3 # SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries # # SPDX-License-Identifier: MIT
Then, in a terminal, change directories to the /azure_pi folder and mark the code.py file as an executable using chmod
.
cd /home/pi/azure_pi chmod a+x code.py
The code.py file needs both the graphical interface and a network connection to properly run. As a result, that needs to be considered when deciding on a method to have it run on boot. To make sure the GUI and network connections are ready before trying to run code.py, a .desktop file is going to be used in the autostart
system.
To create this file, in a terminal create a directory called /autostart in the /.config folder.
mkdir /home/pi/.config/autostart
Then, create the .desktop file using the nano
text editor. This file will be called azure-pi.desktop.
nano /home/pi/.config/autostart/azure-pi.desktop
In the text editor, enter the following text to run code.py.
[Desktop Entry] Type=Application Name=Azure-Pi Exec=/usr/bin/python /home/pi/azure_pi/code.py
Exit and save the new azure-pi.desktop file. Then, try rebooting your Raspberry Pi. After loading the desktop, you should see the code.py PyGameDisplay
window begin running.
Page last edited March 08, 2024
Text editor powered by tinymce.