Skip to content

Instantly share code, notes, and snippets.

@joltcan
Last active August 11, 2024 12:43
Show Gist options
  • Save joltcan/bf31bd184b118ee8c983bc1a1fd642af to your computer and use it in GitHub Desktop.
Save joltcan/bf31bd184b118ee8c983bc1a1fd642af 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=Octocam 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=""
TOKEN=""
SNAPSHOTURL="http://<octopi>/webcam?action=snapshot"
while true; do
# grab from octopi
curl -s "$SNAPSHOTURL" --output /tmp/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/output.jpg" \
--no-progress-meter \
--compressed
# Reset delay to the normal value
DELAY=$DELAY_SECONDS
else
echo "Octopi snapshot returned an error. Retrying after ${LONG_DELAY_SECONDS}s..."
# Set delay to the longer value
DELAY=$LONG_DELAY_SECONDS
fi
sleep "$DELAY"
done
@Topless-Stang
Copy link

Thanks for this! One question though...After starting the service the first time do I have to restart it every time I reboot my RPi?

@hillsandales
Copy link

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.

As long as it's added as a service, it should start up at boot. Mine starts up automatically.

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