Skip to content

Instantly share code, notes, and snippets.

@stepman0
Forked from mandreko/README.md
Last active June 1, 2024 10:35
Show Gist options
  • Save stepman0/7626aded1d63ac06d5065249af77820b to your computer and use it in GitHub Desktop.
Save stepman0/7626aded1d63ac06d5065249af77820b 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:=5}"
: "${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 Camera
fswebcam -r 800x600 --jpeg 80 -D 0 /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 "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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment