Create Image - Instructions
Requirements
- Raspberry Pi Imager
- Project available locally
1 Installing Raspberry Pi OS
Connect the SD card to your PC
Open Raspberry Pi Imager and select the correct model (printed on the board)
Select OS:
Raspberry Pi OS (other)→Raspberry Pi OS Lite (64bit)Select SD card → Next
Edit Settings:
Hostname:
raspberry-pi-sf-[room-number]Username and Password:
Username:smartfarming
Password:EspasZuerich2024Wifi:
SSID:itlab
Password:25$0=ICTbm
Wifi country:chLanguage Settings:
Timezone:Europe/Zurich
Keyboard layout:chUnder Services enable SSH and allow password authentication
Save and apply
After the process is complete, insert the SD card back into the Raspberry Pi.
2 Connecting to the Raspberry
To connect to the Raspberry Pi, run the following command in cmd with the correct IP:
ssh smartfarming@your-ip-here
Example:
ssh smartfarming@192.168.10.100
On the first connection, you will be asked if you want to add the host to the known hosts. Type yes.
Then enter the password (same as the user password).
Common Issues
Format:
Problem
a. Solution 1
b. (Solution 2)Raspberry Pi has local IP 127.0.0.1 / Raspberry is not in the network
a. (only for new Raspberry Pis) MAC address must be registered with support
b. Wrong WiFi name or passwordRaspberry has an IP but refuses connection (connection refused)
a. Connect the PC to the "itlab" WiFi
3 Smartfarming Python Script Installation
Copying the file
To copy the Python file to the Raspberry Pi, run the following command on your PC with adjusted parameters:
file.py: File to copy (with path if necessary)
smartfarming: User on Raspberry Pi
192.168.10.100: Raspberry Pi IP
/path-on-raspberry/file.py: Path where the file should be saved
scp file.py smartfarming@192.168.10.100:/path-on-raspberry/file.py
Making the file executable
Run:
chmod +x file.py
Convert file to Linux format
- Open file with nano
- Press Ctrl+o
- Disable DOS format using alt+d, then press enter
- Exit nano with Ctrl+x
Downloading Packages
To install required Python packages, there are 2 options:
- Using a virtual environment (recommended by Debian)
- Safer
- More time needed
- More complex
- Installing packages globally
- Faster
- Easier
- May cause instability
Option 1
Update apt and install pip:
sudo apt update
sudo apt install pip
Create the virtual environment to avoid system conflicts:
python3 -m venv myenv
Then update the shebang in the Python file to point to the interpreter inside the virtual environment:
Example:
#!/usr/bin/env python3
becomes:
#!/home/smartfarming/smartfarming/sf-env/bin/python
Activate the virtual environment:
source sf-env/bin/activate
Install packages:
pip install [package-name]
Exit the virtual environment:
deactivate
Option 2
Update apt and install pip:
sudo apt update
sudo apt install pip
Install packages globally:
pip install [package-name] --break-system-packages
Add script to autostart
Make script executable
chmod +x /home/pi/scripts/sensor_script.pyCreate a systemd service file
sudo nano /etc/systemd/system/sensor-data.serviceAdd the following content:
[Unit]
Description=Run My Python Script
After=network.target
[Service]
ExecStart=/path/to/your_script.py
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
- Start the service
sudo systemctl enable sensor-data.service
sudo systemctl start sensor-data.service