Jump to content

Adding another camera


Go to solution Solved by CarloK,

Recommended Posts

Posted (edited) · Adding another camera

I found posts by GR5 referencing that if another camera were plugged into the USB then it would be found on the next sequentially numbered port.

Also the api mentions camera numbers and the port numbers.

By default the camera built into the S5 is on port :8080 and if adding more cameras...  a second, third etc camera would be on pors :8081 and :8082 etc.

so...

I tested the api assuming that the index of the first camera, the built-in, would be 0.

 

http://10.0.0.5/api/v1/camera/0/stream
http://10.0.0.5/api/v1/camera/0/snapshot

and what do you know! it works.

 

I also found references in the forums to being able to change the camera resolutions.

 

Also found info that the camera stuff wasn't being developed anymore, but it was still left in the api (Good!)

 

So I want to put another camera that has a different viewing angle. I want to see the first layer being laid down more clearly.

 

Is there an empty usb port on one of the boards? I really don't want to take the s5 apart to find out, if someone can answer me. Or do I need to find where the current camera is plugged in... and put a usb hub in?

 

Or can I just change the camera out that is currently in the S5 for a different one? Are there certain specs like power, size, min/max resolution supported by the firmware etc that I need to be aware of? I do see the built in one takes a mini usb port on the camera.

 

fyi, I don't expect these other views to be accessible via digitalfactory... but directly via ip address on my network is what I want. 

 

I also can then display it on my readyboard in the main room of our offices (based on magicmirror 2) ... we all keep an eye on it that way.

 

Edited by kayakbabe
  • Like 1
Link to post
Share on other sites

Posted · Adding another camera
10 hours ago, kayakbabe said:

 

Is there an empty usb port on one of the boards?

There's the one on the front panel of the machine. I think you can even plug a USB hub in there.

  • Link to post
    Share on other sites

    • Solution
    Posted · Adding another camera

    The API supports up to 10 camera's. For the requirements: plug it in the front usb, and if it works then you are good.
    I don't think there are free USB ports inside, this also might differ on the S5 variant you have (v1 has the robot logo, v2 has the 'U' shape logo on the sides).

     

    The usb supports a hub, you might even move this inside the housing.

     

    Then, recently I learned about this brilliant low tech alternative: stick a mirror to the wall opposite the camera. An IKEA mirror seems to work great. 😎

    mirror.jpg

    • Like 1
    Link to post
    Share on other sites

    • 3 weeks later...
    Posted · Adding another camera
    On 8/20/2021 at 4:25 PM, kayakbabe said:

    I tested the api assuming that the index of the first camera, the built-in, would be 0.

     

    http://10.0.0.5/api/v1/camera/0/stream
    http://10.0.0.5/api/v1/camera/0/snapshot

    and what do you know! it works.

     

    I also found references in the forums to being able to change the camera resolutions.

     

    Also found info that the camera stuff wasn't being developed anymore, but it was still left in the api (Good!)

     

    So I want to put another camera that has a different viewing angle. I want to see the first layer being laid down more clearly.

     

    fyi, I don't expect these other views to be accessible via digitalfactory... but directly via ip address on my network is what I want.

     

     

    I tried this today on my current rev S5 and no bueno.    used a brand new USB camera and plugged into the port on the front of the machine.

     

    http://xxx.xxx.xxx.xxx/api/v1/camera/0/stream worked on internal camera.

    http://xxx.xxx.xxx.xxx/api/v1/camera/1/stream did not work on anything.

     

    http://xxx:xxx:xxx:xxx:8080/?action=stream worked on internal camera.

    http://xxx:xxx:xxx:xxx:8081/?action=stream did not work on anything.

     

    I too, would love to have a much better viewing angle as my machine is in a detached building 150ft away from my house and hiking down there at 1 am isn't my idea of fun 🙂

     

  • Link to post
    Share on other sites

    • 1 month later...
    Posted · Adding another camera

    You might need to change the camera type in the config of the printer. If you have say a VGA instead of a YUC camera.. that would explain. There is another post somewhere here in the community section that explains how to do it.

     

    Anyway, I went with the mirror. Low cost hack and heck I had one laying around. 

  • Link to post
    Share on other sites

    • 5 months later...
    Posted · Adding another camera

    @gr5

    Please can you point me in the direction of your posts regarding adding a second USB camera?

     

    I have tried this on my S3. I plugged a Microsoft Webcam into the front USB port. Both internal and second external cameras are visible if I SSH in to the S3 and look in /dev. I can now see /dev/video0 and /dev/video1 (normally only there is only video0).

     

    The second camera is now available on my S3's IP 'http://<IP address>:8080/?action=stream', but I see nothing on port 8081.

     

    Is it possible to have streaming endpoints for both internal & external cameras? Does this now have to be configured somewhere?

     

    Thanks for any help.

  • Link to post
    Share on other sites

    Posted · Adding another camera

    There's an application running on the printer called mjpg-streamer which hosts the :8080 page and the camera stream for /dev/video0. You would have to configure and run a second instance of that application to host /dev/video1 on :8081. There's nothing on the printer that launches that second instance automatically AFAIK.

  • Link to post
    Share on other sites

    Posted · Adding another camera
    2 hours ago, ahoeben said:

     There's nothing on the printer that launches that second instance automatically AFAIK.

    There are provisions for starting a new instance of mjpeg-streamer for every camera that's inserted: On camera plugin a udev rule is triggered (90-camera_hotplug.rules), which in turn starts a systemd service (mjpg-streamer@.service). Port numbers start at 8080 and then increase by 1 for every camera added.

     

    But, the feature for more than 1 camera was never officially supported, implemented 5 years ago on the UM3 and since then never tested.

    Check the log files for possible error reasons. In the dmesg file you'll see if the camera was detected and perhaps more clues.

    Possible reasons for failure that come to mind: in the S3 printer many of the unused device drivers were stripped, perhaps your camera isn't supported?
    The camera stream is started for SVGA type. Perhaps your camera starts with another type by default?

    • Like 1
    Link to post
    Share on other sites

    Posted · Adding another camera
    3 hours ago, CarloK said:

    There are provisions for starting a new instance of mjpeg-streamer for every camera that's inserted

    I stand corrected.

    • Like 1
    Link to post
    Share on other sites

    Posted (edited) · Adding another camera

    Thanks for the info.

     

    In 'dmesg' I can see that both cameras are detected:

     

    image.thumb.png.2242b9dac45f9bc10c4595ce72988553.png

     

    In process list (ps -ef) I can see that two mjpg-streamer instances are created on ports 8080 and 8081:

     

    image.thumb.png.7e41577a92c2dc9771c0da4e0380c671.png

     

    If I browse to to 8080 port I get the ouput of my external camera no problem. On port 8081 (which I assume is now serving the internal camera) the connection hangs, even though there is a listening process:

     

    image.thumb.png.8c8eb12175e2c9cb9350b52f8fff30cc.png

     

    I tried the connection to 8081 with the Windows Firewall disabled and the connection hangs.

     

    I tried the connection to 8081 from a Linux box on my network, and this also hangs.

     

    I can connect to both ports 8080 and 8081 locally using telnet:

     

    image.thumb.png.0bd53aa831e463689f2d78d068bda223.png

     

    Telnet connects for a short period then mjpg-streamer closes the connection due to inactivity.

     

    So it appears that this is close to working, but there something on the S3 blocking external connections to port 8081. The 'Firewall' setting in the Network menu of the S3 is set to 'off' by the way. If I turn this on then port 8080 gets blocked too (as expected).

     

    Any other suggestions?

     

    Edited by jeremymorgan
    Added more info.
  • Link to post
    Share on other sites

    Posted · Adding another camera

    You did some extensive testing, and indeed, it looks like you got it almost working.
    The fact you see images from your external camera means that configuration for the camera is all good, now it must be a network configuration thing.

     

    I can't spend a lot of time on this, but when I search the code for '8080', then a firewall configuration pops up which looks promising. When we disable the firewall, then port 8080 is actively enabled. I suggest to do the same for 8081 (I assume we are not really disabling the firewall, just opening up/closing more ports).

     

    Modify file /usr/share/griffin/griffin/network/firewall/nftables_firewall_off.conf
    At line #19 you'll find:

    add rule ip filter INPUT ip protocol 6 ct state new tcp dport 8080 accept

    Copy this line for port 8081
    I hope it'll make your second camera work

    • Like 2
    Link to post
    Share on other sites

    Posted · Adding another camera

    @CarloK

    Great - that is the missing piece of the puzzle!

     

    I made the change to the file you suggested then started and stopped the Firewall from the front panel so that it would take effect. Both cameras are now working.

     

    I had previously looked for the nftables service, but this is disabled, so I presume the Ultimaker is doing its own thing:

     

    root@ultimakersystem-0030d627eca3:/usr/share/griffin/griffin/network/firewall# systemctl status nftables
    ● nftables.service - nftables
       Loaded: loaded (/lib/systemd/system/nftables.service; disabled; vendor preset: enabled)
       Active: inactive (dead)
         Docs: man:nft(8)
               http://wiki.nftables.org

     

    I rebooted the printer and the filewall modification change I made remained, but I imagine this might have to be re-done if there is a firmware update?

     

    Thanks again for your help with this.

     

    • Like 1
    Link to post
    Share on other sites

    Posted · Adding another camera

    @jeremymorgan Great to hear you succeeded ! Now others can use it as well.

    The change will indeed be reverted after a firmware update. I suggest you reach out to @Smithy, he created a nice tool for tweaking the Ultimaker printers. The support for extra camera's would be a nice addition to this tool.

     

    • Like 1
    Link to post
    Share on other sites

    Posted · Adding another camera

    Thank you Jeremy, Thank you Carlo!

     

    I was having the same problem as Jeremy and this topic helped me access both cameras! Now if it would be possible to change resolution also, that would be sweet! I've tried to modify the mjpg-streamer@.service file, but with no luck.

  • Link to post
    Share on other sites

    Posted · Adding another camera

    Great idea @CarloK, when @jeremymorgan can send me a short info with the steps he did, I can ofc implement it into the tool. 

     

    I am always open for new ideas and additions 🙂 

  • Link to post
    Share on other sites

    Posted · Adding another camera

    @LoS For documentation on the mjpg-streamer service, see: https://github.com/whinesley/mjpg-streamer
     

    You'd want to change the parameters in the mjpg-streamer@.service file, but I've never tried this.

    Change

    ExecStart=/usr/bin/mjpg-streamer -i "input_uvc.so -r SVGA -d /dev/video%i" -o "output_http.so -p 808%i"

    the '-r' parameter is for resolution, for example:

    -r 320x240

     

  • Link to post
    Share on other sites

    Posted · Adding another camera

    @Smithy

    The change to enable the second camera was quite simple. The file:

      

    /usr/share/griffin/griffin/network/firewall/nftables_firewall_off.conf

     

    needs to have an extra line added:

     

    add rule ip filter INPUT ip protocol 6 ct state new tcp dport 8081 accept

     

    This needs to be placed underneath the similar '8080' line (or at least in that section of the file). The contents of the file then becomes:

     

    #!/usr/sbin/nft -f
    
    # This file contains two formats to represent the ipv4 (generated by iptables-restore-translate) and
    # ipv6 (old format that previously worked for MISP-1027)
    # Both formats are required as the complete ipv4 rule set does not work in the old ipv6 rule format, and vice versa
    # We attempted to make only one format work, but could not and do not want to spend extra time for no gain.
    
    flush ruleset
    
    add table filter
    add chain filter INPUT { type filter hook input priority 0; }
    add chain filter OUTPUT
    add rule ip filter INPUT ct state related,established accept
    add rule ip filter OUTPUT accept
    add rule ip filter INPUT ip protocol udp udp dport 53 accept
    add rule ip filter INPUT ip protocol udp udp dport 5353 accept
    add rule ip filter INPUT ip protocol 6 ct state new tcp dport 22 accept
    add rule ip filter INPUT ip protocol 6 ct state new tcp dport 80 accept
    add rule ip filter INPUT ip protocol 6 ct state new tcp dport 8080 accept
    add rule ip filter INPUT ip protocol 6 ct state new tcp dport 8081 accept
    add rule ip filter INPUT ip protocol 6 ct state established accept
    add rule ip filter INPUT ip protocol 1 icmp type echo-request accept
    add rule ip filter INPUT ip daddr 127.0.0.1 accept
    add rule ip filter INPUT ip daddr 224.0.0.251 accept # for Avahi/Zeroconf/Bonjour/mDNS (this is all the same)
    add rule ip filter INPUT drop
    
    # ----- IPv6 -----
    table ip6 filter {
            chain input {
                    type filter hook input priority 0; policy drop;
                    ct state invalid drop
                    ct state established, related accept
                    ip6 nexthdr icmpv6 accept
            }
    
            chain forward {
                    type filter hook forward priority 0; policy drop;
            }
    
            # This chain explicitly states the default policy
            chain output {
                    type filter hook output priority 0; policy accept;
            }
    }
    
    # yes this is even more hacky, but the other format didn't work for this
    # and as mentioned the above does not work in this format, go figure!
    insert rule ip6 filter input ip6 nexthdr udp udp dport 53 accept

     

    I tried just adding the new line to the bottom of the file as I thought that might make writing a script to update the file easier, but it did not work in that position.

     

    It should theoretically be possible to add further cameras; each of these would be served on port 8082, 8083 etc. and a similar entry in the file would be required for each one.

    • Like 1
    Link to post
    Share on other sites

    Posted · Adding another camera

    Thanks a lot, I will look into it in the next days, but I see no problem to add this feature.

    • Like 1
    Link to post
    Share on other sites

    Posted · Adding another camera
    On 4/6/2022 at 8:09 PM, Smithy said:

    Thanks a lot, I will look into it in the next days, but I see no problem to add this feature.

     

    did you ever look into this Smithy? the built-in camera has really started to annoy me now, its borderline useless and we have the camera feed displayed in the lab to show print progress. Everyone asks what the hell it is they are meant to be looking at.

     

     

  • Link to post
    Share on other sites

    Posted · Adding another camera

    To be honest......I forgot (shame on me)

    But will do it (really) this week!

  • Link to post
    Share on other sites

    Posted · Adding another camera

    So, this one-liner  should do the change:
     

    sed -i 's/add rule ip filter INPUT ip protocol 6 ct state new tcp dport 8080 accept/add rule ip filter INPUT ip protocol 6 ct state new tcp dport { 8080-8083 } accept/' /usr/share/griffin/griffin/network/firewall/nftables_firewall_off.conf

     

    Just ssh into the printer and copy/paste the one-liner and hit enter. You have to restart the printer to see a difference.

    Will now try to put that function into UltiTuner, but it would be nice if someone could test it.

  • Link to post
    Share on other sites

    Posted · Adding another camera

    Here we go:

    https://github.com/SmithyAT/UltiTuner/releases/latest

     

    It changes the firewall rule from 8080 to 8080-8083 so you can add additional 3 webcams if you want.

     

    If you already have activated the additional webcams with UltiTuner and fire the command a second time, you will get a message that your printer is not compatible. That's not nice, but also don't hurt. Will change it to a better message if I have more time.

     

    Additionally I will implement a feature to revert the change with UltiTuner, which is currently not possible.

     

    Usage:

    ultituner webcam -p 192.168.0.123 

     

    Remember to reboot your printer after the change or add the -r flag to the command line.

     

  • Link to post
    Share on other sites

    Posted · Adding another camera
    1 hour ago, Smithy said:

    Here we go:

    https://github.com/SmithyAT/UltiTuner/releases/latest

     

    It changes the firewall rule from 8080 to 8080-8083 so you can add additional 3 webcams if you want.

     

    If you already have activated the additional webcams with UltiTuner and fire the command a second time, you will get a message that your printer is not compatible. That's not nice, but also don't hurt. Will change it to a better message if I have more time.

     

    Additionally I will implement a feature to revert the change with UltiTuner, which is currently not possible.

     

    Usage:

    ultituner webcam -p 192.168.0.123 

     

    Remember to reboot your printer after the change or add the -r flag to the command line.

     

     

    great work as per.

    Sadly doesnt work for me though, but it guess its more to do with the camera being some HD Logitec thing. I'll see if i can find a lesser model in here somewhere and try that.

  • Link to post
    Share on other sites

    Posted · Adding another camera

    I am using Logitech C270 on other printers, connected to Octoprint. I can try if that model works with the Ultimaker.

  • Link to post
    Share on other sites

    Posted · Adding another camera
    5 minutes ago, Smithy said:

    I am using Logitech C270 on other printers, connected to Octoprint. I can try if that model works with the Ultimaker.

     

    ha, thats the exact same one im trying to use!

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • UltiMaker Cura 5.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 16 replies
      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
          • Like
        • 0 replies
    ×
    ×
    • Create New...