Setup an external USB camera with your AutoPi

Installing a web cam to an AutoPi

Hello everyone!

Today, we’re going to explore how you can attach an external USB camera to your AutoPi device and make some use out of it. There is one prerequisite however - you need to be able to SSH into your dongle. We already have a guide on that which you can take a look at here.

Firstly, we need to do some initial setup to get the AutoPi ready to use an external USB web camera. Let’s start with the software that we’re going to use:

  1. motion - Motion is a daemon service that is responsible for communicating with the camera. It’ll setup the devices (/dev/video*) and get them started.

  2. motionEye - MotionEye is a web based frontend for motion. It provides an
    easy to use interface to setup configuration for each camera and also shows what the cameras are currently seeing.

Installing both of them should be as easy as installing any other package on a debian system. We will use the apt command. The next command installs motion daemon and its dependencies:

$ sudo apt install motion

Let’s now prepare for the installation of motioneye - there are some dependencies that need to be installed:

$ sudo apt install python-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libz-dev

Now that we’ve got the dependencies installed, let’s install motioneye itself:

$ sudo pip install motioneye

Note: If pillow installation fails, you can try installing it from official repos using apt install python-pillow.

After successfully installing motion and motioneye we now need to prepare some directories for them to use. The next two commands will create the motioneye configuration directory and copy the default configuration file in that directory:

$ sudo mkdir -p /etc/motioneye

$ sudo cp /usr/local/share/motioneye/extra/motioneye.conf.sample /etc/motioneye/motion.conf

Now, let’s create the directory in which motioneye will save our video files to:

$ sudo mkdir -p /var/lib/motioneye

Finally, let’s create a service file for motioneye so that the system can automatically start it up:

$ sudo cp /usr/local/share/motioneye/extra/motioneye.systemd-unit-local /etc/systemd/system/motioneye.service

$ sudo systemctl daemon-reload

$ sudo systemctl enable motioneye

$ sudo systemctl restart motioneye

At this point, the web interface should be running on the device, however you probably won’t be able to access it from your computer or mobile phone. Instead, it’s only accessible from the device itself. This is because there are some firewall settings that have been implemented on the device and we need to add a new exception. We can do that by navigating to the Advanced > Settings menu in There, one of the inner tabs called System should contain an entry called Network > Firewall. Let’s add the following new entry to the list:

-A INPUT -s -i uap0 -p tcp --dport 8765 -j ACCEPT

NOTE: 8765 is only the default port for MotionEye. If you happen to change the port number, please make sure to add the rule with the respective new port number.

What this entry will do is allow all TCP traffic that comes from the AutoPi’s WiFi network interface through port 8765 to be accepted. This will allow you to navigate to the following link: There you’ll finally be able to see the MotionEye frontend interface.

At this point, you should be able to plug in the camera to your device’s micro-usb, wait a few seconds and see the video feed on your screen. You should also be able to see the settings for the camera by clicking on the ‘burger-menu’ button on the top left of the website. If you’re unable to see a long list of settings, try reloging as an admin. If this still doesn’t do the trick, try restarting the motion and motioneye services using the following commands:

sudo systemctl restart motion motioneye

Now we will move on to some pointers on how to get started with certain, popular projects.

Setting up basic camera settings

Sometimes the image on the camera can be very dim or with a low resolution as a default. The general settings for the camera can be found under the “Video Device” section. Settings such as brightness, contrast, sharpness and video resolution can be set up there. This should allow you to fine tune your camera for the environment you’re looking to use it in. There is also the ability to automatically set the brighness and exposure of the camera.

Furthermore, you’re also able to change the default location of where the video files (recordings) are saved. The default location is /var/lib/motioneye/Camera1, however you can change that by going under the “File Storage” section.

There you’re also able to setup a webhook or a command to be called whenever a new file has been saved on the file system.


Which camera hardware is being used here?

Additionally, what sort of performance are you seeing on this in terms of FPS, and what impact does it have on regular AutoPi operation?

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.