Create Image - Instructions


Requirements


1 Installing Raspberry Pi OS

  1. Connect the SD card to your PC

  2. Open Raspberry Pi Imager and select the correct model (printed on the board)

  3. Select OS:
    Raspberry Pi OS (other)Raspberry Pi OS Lite (64bit)

  4. Select SD card → Next

  5. Edit Settings:

    Hostname:
    raspberry-pi-sf-[room-number]

    Username and Password:
    Username: smartfarming
    Password: EspasZuerich2024

    Wifi:
    SSID: itlab
    Password: 25$0=ICTbm
    Wifi country: ch

    Language Settings:
    Timezone: Europe/Zurich
    Keyboard layout: ch

  6. Under Services enable SSH and allow password authentication

  7. Save and apply

  8. 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:

  1. Problem
    a. Solution 1
    b. (Solution 2)

  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 password

  3. Raspberry 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

  1. Open file with nano
  2. Press Ctrl+o
  3. Disable DOS format using alt+d, then press enter
  4. Exit nano with Ctrl+x

Downloading Packages

To install required Python packages, there are 2 options:

  1. Using a virtual environment (recommended by Debian)
    • Safer
    • More time needed
    • More complex
  2. 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

  1. Make script executable
    chmod +x /home/pi/scripts/sensor_script.py

  2. Create a systemd service file
    sudo nano /etc/systemd/system/sensor-data.service

  3. Add 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
  1. Start the service

sudo systemctl enable sensor-data.service
sudo systemctl start sensor-data.service