Skip to content

Instantly share code, notes, and snippets.

@mandreko
Forked from joltcan/README.md
Last active May 29, 2025 19:09
Show Gist options
  • Save mandreko/1ac7e189967f7a170485c4a04c459c57 to your computer and use it in GitHub Desktop.
Save mandreko/1ac7e189967f7a170485c4a04c459c57 to your computer and use it in GitHub Desktop.
Prusa Connect Webcam upload

From Nunos great instructions

Instructions

  1. Go to the Cameras section at https://connect.prusa3d.com
  2. Add a new camera.
  3. Click the QR code link
  4. Click "Start Camera"
  5. Open your browser's inspector window and look for the "/snapshot" request.
  6. Copy the "Fingerprint" and "Token" headers into the file below.
  7. 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.

Service

To run in the background, create /etc/systemd/system/prusaconnect_upload_cam.service and then start and enable it: systemctl enable --now prusaconnect_upload_cam.service.

[Unit]
Description=Raspi Camera to Prusa Connect
[Service]
ExecStart=/usr/local/bin/prusaconnect_upload_cam.sh
[Install]
WantedBy=multi-user.target
#!/bin/bash
# Set default values for environment variables
: "${HTTP_URL:=https://webcam.connect.prusa3d.com/c/snapshot}"
: "${DELAY_SECONDS:=10}"
: "${LONG_DELAY_SECONDS:=60}"
: "${FINGERPRINT:=<fingerprint>}"
: "${TOKEN:=<token>}"
while true; do
# Delete the previous image since libcamera-jpeg won't overwrite
rm -f /tmp/prusa_output.jpg 2> /dev/null
# Grab a frame from the Raspi Camera
libcamera-jpeg -o /tmp/prusa_output.jpg -q 80 --width 800 --height 600 -n
# 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: $TOKEN" \
--data-binary "@/tmp/prusa_output.jpg" \
--no-progress-meter \
--compressed
# Reset delay to the normal value
DELAY=$DELAY_SECONDS
else
echo "libcamera-jpeg returned an error. Retrying after ${LONG_DELAY_SECONDS}s..."
# Set delay to the longer value
DELAY=$LONG_DELAY_SECONDS
fi
sleep "$DELAY"
done
@BigAl66
Copy link

BigAl66 commented May 29, 2025

I made it with mjpg-streamer (on a raspberry pi that hosts my repetier server). And I also check if the printer is running before I grab a picture:

while true; do
    # Delete the previous image
    rm -f /tmp/prusa_output.jpg 2> /dev/null

    if ping -c 1 prusa-mk4s-1 &> /dev/null; then

      # Grab a frame from mjpeg-streamer
      wget localhost:8080/?action=snapshot -O /tmp/prusa_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: $TOKEN" \
              --data-binary "@/tmp/prusa_output.jpg" \
              --no-progress-meter \
              --compressed

          # Reset delay to the normal value
          DELAY=$DELAY_SECONDS
      else
          echo "Error saving snapshot. Retrying after ${LONG_DELAY_SECONDS}s..."

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

Works perfect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment