September 8, 2023
Description
As I wanted the base in a different color than white, I made this from the original model. This model use the same distance for the screw holes as the TP-Link original mount. I made 2 versions with different tolerances, as the original model was not tight enough to hold the camera in place.
I use this as a camera for PrusaConnect, following this guide: https://gist.github.com/nunofgs/84861ee453254823be6b069ebbce9ad2
It requires a Linux based computer of some sort to capture and upload images using ffmpeg and curl. I used my Raspberry Pi running Home-Assistant Core. I did not use Docker, but set up the bash script to run as a service instead.
Adjust the paths, filenames, camera IP, camera credentials, token and fingerprint to your needs.
/lib/systemd/system/mk4-camera.service
[Unit]
Description=Prusa-Connect MK4 Camera feed
[Service]
ExecStart=/home/pi/mk4-camera/upload.sh
StandardOutput=null
[Install]
WantedBy=multi-user.target
/home/pi/mk4-camera/upload.sh
#!/bin/bash
# Set default values for environment variables
: "${HTTP_URL:=https://webcam.connect.prusa3d.com/c/snapshot}"
: "${DELAY_SECONDS:=10}"
: "${LONG_DELAY_SECONDS:=60}"
: "${RTSP_URL:=rtsp://username:password@cameraip:554/stream1}"
: "${FINGERPRINT:=yourfingerprint}"
: "${TOKEN:=yourtoken}"
while true; do
# Grab a frame from the RTSP stream using FFmpeg (timeout at 5s)
ffmpeg \
-stats \
-y \
-rtsp_transport tcp \
-i "$RTSP_URL" \
-vframes 1 \
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 "@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
Enable service:
pi@hass-pi:~/mk4-camera $ sudo systemctl enable mk4-camera.service
Created symlink /etc/systemd/system/multi-user.target.wants/mk4-camera.service → /lib/systemd/system/mk4-camera.service.
pi@hass-pi:~/mk4-camera $ sudo systemctl start mk4-camera.service
pi@hass-pi:~/mk4-camera $ sudo systemctl status mk4-camera.service
● mk4-camera.service - Prusa-Connect MK4 Camera feed
Loaded: loaded (/lib/systemd/system/mk4-camera.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2023-09-03 01:50:46 CEST; 5s ago
Main PID: 3926795 (upload.sh)
Tasks: 2 (limit: 4163)
CPU: 913ms
CGroup: /system.slice/mk4-camera.service
├─3926795 /bin/bash /home/pi/mk4-camera/upload.sh
└─3926808 sleep 10
In my case, printed in 0.2 Prusament PLA Galaxy Black, 4 perimeters, 15% infill.
License:
Creative Commons — Attribution — Noncommercial
9