Skip to content

Instantly share code, notes, and snippets.

@p123ad
Last active November 16, 2025 11:40
Show Gist options
  • Select an option

  • Save p123ad/5b1482200715d834e9db736fa9e187d0 to your computer and use it in GitHub Desktop.

Select an option

Save p123ad/5b1482200715d834e9db736fa9e187d0 to your computer and use it in GitHub Desktop.

Revisions

  1. p123ad revised this gist Jan 5, 2024. 2 changed files with 13 additions and 4 deletions.
    15 changes: 12 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,18 @@
    From [Nunos great instructions](https://gist.github.com/nunofgs/84861ee453254823be6b069ebbce9ad2)
    From [Joltcans great instruction](https://gist.github.com/joltcan/bf31bd184b118ee8c983bc1a1fd642af)
    # Use Raspberry Pi and Pi Cam for Prusa Connect
    Made this for my PRUSA MINI with a Raspberry Pi Zero 2W and a Raspi Cam v1.3

    Based on the great instructions from [Nunos](https://gist.github.com/nunofgs/84861ee453254823be6b069ebbce9ad2) and [Joltcans](https://gist.github.com/joltcan/bf31bd184b118ee8c983bc1a1fd642af)

    ![3](https://gist.github.com/assets/65493497/5a98eafe-e5d1-44ec-abfb-191ce8e41647)


    # Instructions

    1. Go to the Cameras section at https://connect.prusa3d.com
    2. Add a new camera "Add new other camera".
    3. Copy the generated Token
    4. Copy the "Token" headers into the file below.
    4. Set up your Raspberry Pi with simpe Raspian OS and enable the camera with `raspi-config`.
    5. Create a shell script `prusaconnect_upload_cam.sh` and paste the Token into the file below.

    ## Test

    @@ -15,6 +21,9 @@ From [Joltcans great instruction](https://gist.github.com/joltcan/bf31bd184b118e

    If It works you should see the images appearing in Prusa Connect every 10 seconds.

    ![1](https://gist.github.com/assets/65493497/d7ff2131-8ab0-4cf3-9476-a4649cd1bdf2)


    ## Create Autostart Service

    To run the script in the background and start it automatically.
    2 changes: 1 addition & 1 deletion upload.sh → prusaconnect_upload_cam.sh
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    # FINGERPRINT can be a random string with at least 16 characters
    : "${FINGERPRINT:=123456789012345678}"
    # CAMERA_TOKEN generated by the Connect server
    : "${CAMERA_TOKEN:=2mpIL0ojCGG6r6i8xCxK}"
    : "${CAMERA_TOKEN:=put the token here}"

    while true; do
    # Grab a frame from the Raspi Cam using FFmpeg, -video_size 1280x720
  2. p123ad created this gist Jan 5, 2024.
    25 changes: 25 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    From [Nunos great instructions](https://gist.github.com/nunofgs/84861ee453254823be6b069ebbce9ad2)
    From [Joltcans great instruction](https://gist.github.com/joltcan/bf31bd184b118ee8c983bc1a1fd642af)

    # Instructions

    1. Go to the Cameras section at https://connect.prusa3d.com
    2. Add a new camera "Add new other camera".
    3. Copy the generated Token
    4. Copy the "Token" headers into the file below.

    ## Test

    5. Save `prusaconnect_upload_cam.sh` from below to `/usr/local/bin/prusaconnect_upload_cam.sh` and make it executable `chmod +x /usr/local/bin/prusaconnect_upload_cam.sh`.
    6. Start the script with `./usr/local/bin/prusaconnect_upload_cam.sh`

    If It works you should see the images appearing in Prusa Connect every 10 seconds.

    ## Create Autostart Service

    To run the script in the background and start it automatically.

    7. Create `/etc/systemd/system/prusaconnect_upload_cam.service` and paste the content from below.
    8. Start the service: `sudo systemctl start prusaconnect_upload_cam.service`.
    9. Check if the service is running with `sudo systemctl status prusaconnect_upload_cam.service`.
    10. Enable the service: `sudo systemctl enable prusaconnect_upload_cam.service`.
    8 changes: 8 additions & 0 deletions prusaconnect_upload_cam.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    [Unit]
    Description=Raspi Cam to Prusa Connect

    [Service]
    ExecStart=/usr/local/bin/prusaconnect_upload_cam.sh

    [Install]
    WantedBy=multi-user.target
    51 changes: 51 additions & 0 deletions upload.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    #!/bin/bash

    # Script is from here
    # https://gist.github.com/moritzmhmk/48e5ed9c4baa5557422f16983900ca95
    # https://gist.github.com/nunofgs/84861ee453254823be6b069ebbce9ad2

    # Set default values for environment variables
    : "${HTTP_URL:=https://connect.prusa3d.com/c/snapshot}"
    : "${DELAY_SECONDS:=10}"
    : "${LONG_DELAY_SECONDS:=60}"
    # FINGERPRINT can be a random string with at least 16 characters
    : "${FINGERPRINT:=123456789012345678}"
    # CAMERA_TOKEN generated by the Connect server
    : "${CAMERA_TOKEN:=2mpIL0ojCGG6r6i8xCxK}"

    while true; do
    # Grab a frame from the Raspi Cam using FFmpeg, -video_size 1280x720
    ffmpeg \
    -y \
    -f video4linux2 \
    -input_format mjpeg \
    -video_size 1280x720 \
    -i /dev/video0 \
    -vframes 1 \
    -filter:v "vflip" \
    -f mjpeg \
    output.jpg

    # If no error, upload it.
    if [ $? -eq 0 ]; then
    # POST the image to the HTTP URL using curl
    curl -X PUT "$HTTP_URL" \
    -H "accept: */*" \
    -H "content-type: image/jpg" \
    -H "fingerprint: $FINGERPRINT" \
    -H "token: $CAMERA_TOKEN" \
    --data-binary "@output.jpg" \
    --no-progress-meter \
    --compressed

    # Reset delay to the normal value
    DELAY=$DELAY_SECONDS
    else
    echo "FFmpeg returned an error. Retrying after ${LONG_DELAY_SECONDS}s..."

    # Set delay to the longer value
    DELAY=$LONG_DELAY_SECONDS
    fi

    sleep "$DELAY"
    done