Duet 2 and Duet 3 mainboards do not support a directly-connected web camera. However, you can buy a suitable Wifi or Ethernet IP camera and then configure Duet Web Control to include an image from the camera on the Print page.
Important: You must choose a camera that has the facility to return a static JPEG image in response to a HTTP request. Not all IP cameras have this facility. Sadly, none of the major browsers supports including a RTSP camera video stream in a web page.
This is known to work. You can use OctoPrint to host a video camera feed. However there is a lighter weight solution. Here is a summary of the process of installing MotionEyeOS on a RaspberryPi with a camera attached.
:update_config=1
:ctrl_interface=/var/run/wpa_supplicant
:network={
::scan_ssid=1
::ssid="HomeNetwork"
::vpsk="password"
:}
For more details on this setup process please visit https://betrue3d.dk
If using a Raspberry Pi cam, UV4L is a nice lightweight option, and has a built-in webserver for streaming. There’s a guide on Github here.
Roughly:
http://[raspberry pi ip address]:8080/stream/snapshot.jpeg?delay_s=0
http://[ip-address:port]/snapshot.cgi
http://[ip-address:port]/videostream.cgi?loginuse=[YourUserName]&loginpas=[YourPassword]
http://[ip-address:port]/index.htm
and click on Videostream mode, you can use the motors onboard the camera to focus on various parts of your print.The following instructions were contributed by forum user Foden.
Purchased some of these beauties, Amazon (Canada), for the house to replace my way more expensive - but dead - IP cameras. With the addition of a small/cheap 4-16GB SD card and an awesome hack from Github, I can link them to my existing home PVR. I've used Sighthound for years https://www.sighthound.com/, but you don't need to have any software to use these cameras with with Duet 2. All you need to do is extract the folder 'firmware_mod' from the Dafang zip file to the root of your sd card. Edit the file \config\usb_eth_driver.conf.dist (note: it may be wpa_supplicant.conf.dist that you need to edit and rename) and add your SSID and password (only 2.4 Ghz). Rename \config\usb_eth_driver.conf.dist\ to \config\usb_eth_driver.conf. That sets up your Wi-Fi connectivity. Once you figure out the cameras IP just enter it into your browser http://www.xxx.yyy.zzz, you will be prompted for the user name 'root' and password 'ismart12' - all lowercase. You can, and should, change the password straight away. Monkey around with the settings but make sure under the camera controls you have RTSP h264 server running. Probably don't need to change much. Then go to your Duet W-Fi under Settings / User Interface enter this for the camera address https://www.xxx.yyy.zzz/cgi-bin/currentpic.cgi - replacing www.xxx.yyy.zzz with the camera IP. Set the web cam update interval to your liking, mine is set at 1 sec. Save your settings and when printing the job status window will update with an image from your camera based on the update interval you entered.
The cameras will also work, generally, in low to no light, I forgot where i got the info but think it just needs a file in the config folder called 'autonight.conf.sw' and all it contains is '-S'
In RRF 3.5 and later, use the Spyglass camera plugin for cameras connected to the RPi via the CSI connector, and Motion for USB-connected cameras.
For RRF 3.4 and earlier, use the Motion plugin for all cameras.
(Info to come)
From RRF 3.4, the Duet3D-provided Raspberry Pi images for Duet Software Framework come with the motion streaming service installed. A compatible camera can be connected to the Rapsberry Pi using the Raspberry Pi camera connectors or USB, and can then be used through DWC and controlled through the Motion Webcam Plugin.
Motion is a program that monitors the video signal from one or more cameras and is able to detect if a significant part of the picture has changed. Or in other words, it can detect motion. It is generally used in security cameras. It can also stream the camera view, using a built-in webserver, which is what DWC uses.
When you connect a camera to the Raspberry Pi, it is set up as a device in the /dev folder as a 'video' device. You can check what devices are connected by sending v4l2-ctl --list-devices
in the Raspberry Pi's terminal.
bcm2835-codec-decode (platform:bcm2835-codec):
/dev/video10
/dev/video11
/dev/video12
mmal service 16.1 (platform:bcm2835-v4l2):
/dev/video0
HP Webcam 3100: HP Webcam 3100 (usb-3f980000.usb-1.5):
/dev/video1
/dev/video2
In the above, /dev/video0 is a Raspberry Pi Camera, and /dev/video1 is a USB webcam.
This plugin runs the Motion webcam streaming service as a DSF plugin.
More information on configuration parameters can be found on the Motion documentation pages.
The Motion configuration file motion.conf
is created in 0:/sys/motion.conf
, and can be edited in DWC. The default configuration uses the default /dev/video0
device node. Depending on your choice of camera (see 'Camera check' section above), you may need to change this in motion.conf
.
The standard configuration streams video using the built-in webserver, and is not set to capture images or video. However, the stream usually runs at 1 frame per second, with a resolution of 1280x720. If you would prefer a higher frame rate and better quality, at the expense of making the Raspberry Pi work a bit harder, you can add the following to motion.conf.
Turn off the motion detection (reduces RPi CPU utilisation by 5-10%):
# When Motion is started, pause the motion detection. Default: off
pause on
Increase the stream frame rate (usually 1fps!):
# Limit the framerate of the stream in frames per second (default 1, max 100)
stream_maxrate 25
Adjust the video size by editing the following:
# Image width in pixels.
width 1280
# Image height in pixels.
height 720
After you make changes to motion.conf, you will need to restart the Motion Plugin to make the settings take effect. Go to Settings > Plugins > External plugins, click 'Stop' to stop the plugin, wait a couple of seconds, then click 'Start' again. Check that your changes have taken effect, by checking the Job > Webcam page.
Reported in 'top' (run from RPi terminal), Motion's CPU utilisation on a RPi4 is around 40-50% for 1280x720 @ 25fps, and around 30% for 800x600 @ 25fps, when the stream is being displayed. It drops to below 10% CPU utilisation when not being displayed.
To configure this service in DWC, go to the Settings
-> General
page and make the following changes:
Webcam URL
to http://[HOSTNAME]:8081/0/stream
Webcam update interval (in ms)
to 0
Job
-> Webcam
page to see your live streamIt is easiest to set up one camera first, to check everything is working, before setting up multiple cameras.
To use more than one camera, Motion splits the configuration into a main configuraton named motion.conf
and a configuration for each camera. For this example, they are called camera1.conf
and camera2.conf
. There are all created and stored in 0:/sys/
, and can be edited in DWC.
motion.conf
stores all parameters that are used by all cameras. This includes the webserver address for all the cameras, the location of the camera#.conf
configuration files (in the same folder as motion.conf
in this example), and picture settings that apply to all streams. An example could be:
motion.conf
pause on
daemon off
setup_mode off
log_level 3
emulate_motion off
picture_output off
movie_output off
width 800
height 600
framerate 25
stream_maxrate = 25
stream_localhost off
webcontrol_port 8080
webcontrol_localhost off
webcontrol_parms 0
camera /opt/dsf/sd/sys/camera1.conf
camera /opt/dsf/sd/sys/camera2.conf
The individual camera#.conf
files contain information specific to the camera, mainly the device node the stream uses, eg /dev/video0
or /dev/video1
. Create these in the /sys folder with motion.conf
An example could be:
Camera1.conf
camera_name CAM-1
camera_id 001
video_device /dev/video0
text_left CAM-1
stream_port 8081
Camera2.conf
camera_name CAM-2
camera_id 002
video_device /dev/video1
text_left CAM-2
stream_port 8082
After you make changes to motion.conf or camera#.conf, you will need to restart the Motion Plugin to make the settings take effect. Go to Settings > Plugins > External plugins, click 'Stop' to stop the plugin, wait a couple of seconds, then click 'Start' again. Check that your changes have taken effect, by checking the Job > Webcam page.
To configure this service for multiple cameras in DWC, go to the Settings
-> General
page and make the following changes:
Webcam URL
to http://[HOSTNAME]:8080/stream
Webcam update interval (in ms)
to 0
Job
-> Webcam
page to see your live stream(Not generally needed if you are using the 'Release' version of the plugin that matches your RRF version.)
Create a ZIP file of every file but README.md
in this directory and make sure plugin.json
is at the root level. Once created, the ZIP can be installed as a third-party plugin.
Unfortunately the motion service outputs info and warning log messages even if the log level is initially set to not output these, so by default this plugin's configuration suppresses all the log messages and only sends them to the duetpluginservice
journal log.
To view the log of the motion service, open a Linux console (or connect over SSH) and run
journalctl -u duetpluginservice -f
Then restart the Motion Webcam Server plugin and look for potential errors.
To see all the output messages from the motion service directly in DWC, open plugin.json
and set sbcOutputRedirected
from false
to true
. Then build the plugin again and overwrite the existing installation.
Once the plugin is restarted, all the log messages are written to the DWC console.
If you need further details, you can reset log_level
in motion.conf
from 3
(critical) to 6
(notice). Note that a restart of the plugin is required whenever the config file is modified.