Skip to content

Instantly share code, notes, and snippets.

@joltcan
Last active April 4, 2024 06:34
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • 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
@Xennic
Copy link

Xennic commented Sep 17, 2023

Had to change SNAPSHOTURL="http:///webcam?action=snapshot" to SNAPSHOTURL="http://127.0.0.1:8080/?action=snapshot" then it started working

@rodi01
Copy link

rodi01 commented Nov 25, 2023

I had an issue with the curl command, so I removed the --no-progress-meter line and it's working

@Hypopheralcus
Copy link

Had to change from SNAPSHOTURL="http:///webcam?action=snapshot" to SNAPSHOTURL="http:///webcam/?action=snapshot"

Added an / after webcam

@sbernd78
Copy link

sbernd78 commented Jan 12, 2024

I'm using a standard-Raspberry-PI-OS with a Camera-Modul v3. For this I completly removed the Snapshot-URL-Command and use
rpicam-still -n --width 1920 --height 1080 -q 75 -o /tmp/output.jpg
instead. And it works fine.

@hillsandales
Copy link

uuidgen can be used to generate a Fingerprint. I had issues clicking the QR code because my computer does not have a webcam.

Found this tip at this link.

@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