Notifications
Clear all

MK4 RPI webcam with prusa connect?  

  RSS
mep67
(@mep67)
Active Member
MK4 RPI webcam with prusa connect?

Sorry to bring this topic up again. But, I've searched everything I can and can't figure it out. 

In an effort to get a camera working with Prusa Connect, I setup a RPI 4 with webcam. I was able to get the whole thing working with Octoprint and can see the webcam video. However, I can't figure out how to add the camera to Prusa Connect.

I know it doesn't work with Prusalink on the MK4, but some forum posts seem to imply it can with Prusa Connect. Is this true? 

Thanks!

Posted : 29/03/2024 8:40 pm
Mike B
(@mike-b-3)
Trusted Member
RE:

Here's how I added my RPi5/Camera3 to Prusa Connect:

1. Go to https://connect.prusa3d.com and click on the Camera tab.

2. Click on the "Add a new web camera"

3. You will see a QR code - point your camera at the screen displaying the QR code.

4. Nothing happens.  Now, if this was a cellphone you'd click on the resulting link and everything would be fine.  I don't know if it's the browser not recognizing QR Codes, or I should be using a special scanning app, but I didn't research it much further.  I worked around this as follows:

5. You need to construct a URL from the registration ID on the webpage like this:   https://webcam.connect.prusa3d.com/?token=xyZaBcDef4hXmkURJ8HO.  On my Mac, I can right-click on the QR code and copy the registration link, but you can just copy the token and add it to the URL manually if you need to.

6.  On the RPi, open a web browser and enter the URL from step 5.  The token is what links the connect session to the camera session on the RPi.

 

Prusa MK4 since Jan 2024, Printables: @MikeB_1505898

Posted : 30/03/2024 1:06 am
that0neguy
(@that0neguy)
Active Member
RE:

Here is the script I use. Found the original here on github but had to modify it quite a bit. You should be able to use my script and add a fingerprint and your token plus the instructions on how to set up the script to start automatically from the link to github to set it up.  Was using an old url to upload to (webcam.connect.prusa.com or something). The documentation is really poor for the API call. API doesn't really function well. I was getting an error for a while because my fingerprint was only 12 characters, and it was not well documented that it had to be 16. 

Other things that I had to find out by looking at the forums that aren't documented on the API page. Printer has to be online in order for uploads to update on connect dashboard. 

#!/bin/bash

# Set default values for environment variables
: "${HTTP_URL:= https://connect.prusa3d.com/c/snapshot }"
: "${DELAY_SECONDS:=10}"
: "${LONG_DELAY_SECONDS:=60}"
: "${FINGERPRINT:=}"

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

    # Grab a frame from the Raspi Camera
        wget -O /tmp/prusa_output.jpg  http://localhost:8080/?action=snapshot 

    # 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 "wget returned an error. Retrying after ${LONG_DELAY_SECONDS}s..."

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

    sleep "$DELAY"
done
This post was modified 7 months ago by that0neguy
Posted : 30/03/2024 7:57 pm
that0neguy
(@that0neguy)
Active Member
RE: MK4 RPI webcam with prusa connect?

can't edit my post for some reason. Not sure how but the : "${TOKEN:=}" variable was removed from the script. You need to copy that from your prusa connect camera page and paste it into the script. Also set the fringerprint variable in the script. 

Posted : 30/03/2024 9:21 pm
mep67
(@mep67)
Active Member
Topic starter answered:
RE: MK4 RPI webcam with prusa connect?

Thanks you so much for responding. I really appreciate the suggestions and code as well. 

In the end, I was able to connect the camera using the first method. It did work well on prusaconnect. The only problems was that I had to manually setup the camera link in the RPI each time I booted up. This was too cumbersome as it required keyboard/monitor be attached. Most likely I'm doing it wrong.

The code is way above my ability, but maybe one day I'll figure it out. I appreciate your time in sharing.

Ultimately, I'm planing on ditching the camera idea and using the RPI as a gaming emulator, LOL.

 

Posted : 11/04/2024 5:56 pm
Chefke
(@chefke)
Member
RE:

I was just wondering, since I am extremely new to all this stuff, that you're supposed to copy your script with our own "token" and "fingerprint" and save it as a certain type of file.

Then save it on a microSD and insert it in the Raspberry pi that you intent on using? And since I am here asking about this, I've got a Raspberry Pi 4B with a Raspi cam V2. Is that a compatible setup for your current script? Or should I adjust it to my devices, and if so, how would one go about adjusting it to the devices I intent on using?

It would be a great help if you're able to tell me how I could fix it, should it even be possible.

Thanks in advance!

Posted : 28/08/2024 12:18 pm
Share: