How I connected my RaspberryPi Zero W (with camera) to my Synology NAS (DS 216 II+) and use it in the Diskstations Surveillance Station

So the wife and I recently bought a new Synology NAS (we really were together in the store, yes store, and it was paid from the shared bank account), because the old on got the slows.

A DS 216 II+ it was destined to be. With a cool Intel Celeron x86 CPU, 1 GB of RAM and this in a nice black casing. What’s not to love about that?!

We also have a house (which we live in). And I wanted to “secure things”. Now count 1 & 1 & 1 together: RaspberryPi & new Diskstation & my new found IT-discovery-urge, what do we get? A question!

Can I connect a Raspberry Pi Zero W (with the Picamera) to my Diskstation?


And livestream & record the feed in Synology’s Surveillance Station?


But how?

With a camera and motion as package. That’s the main thing the Pi then will do. Okay, let’s get into the details. You’ll need:

  1. A Raspberry Pi. I recommend the Zero W, because it’s super small (both in physical size and also energy footprint), and its official case comes with a camera cover. It’s basically meant to be a security cam (among other things).
  2. A Camera for the Pi. Recommendation, go for the official Pi Camera. All following steps will assume it is an official Pi Camera, and physical installation of it in a Pi Zero Case is a breeze.
  3. Other hardware items for the Pi: case, power supply, micro sd-card (we will run a headless installation of the PI, so USB & HDMI-Stuff is not needed).
  4. A PC/Mac to connect to the Pi via SSH/Putty/etc, and configure it. I’m using a Mac here, the workflow shouldn’t be that different on a Windows/Linux machine though.
  5. The Synology SAN in the same LAN as the Pi.

Headless setup of the (new) Raspberry Pi

We start with a factory fresh Pi and an empty sd-card. You an skip this step if your Pi is already set up with an OS and you can connect to it.

  1. Download Raspbian from the official site. We’ll use the lite version for this guide, because the Zero isn’t supposed to do more than running the camera and doing the motion analysis. Desktop and a graphical user interface… pah… pure overkill. Who needs this stuff nowadays?!
  2. Use Etcher to burn the Raspbian image onto the sd-card.
  3. Before un-mounting the sd-card, place two files into the \boot-partition:
    1. A file called ‘ssh‘ without a file type extension. This will enable ssh access directly by default.
    2. A file called wpa_supplicant.conf. In it define the credentials for your WLAN, like so:
      ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
  4. With the sd-card now in the Pi, boot it and wait until you can connect to it. You can ping raspberrypi.local to get its IP, or just use exactly this hostname for the first SSH connection.
  5. SSH into the Pi with ssh pi@raspberrypi.local with the default password ‘raspberry’ and run:
    $ sudo raspi-config
  6. There we’ll do three things:
    1. Change the password & hostname from the default to something else in order to be secure and to identify the Pi should more of them turn up in your network.
    2. Enable the Camera interface.
    3. Save and confirm the changes (this may result in a reboot, after which you need to connect via the new hostname & new password).
  7. Still in SSH, to get the newest software packages installed run:
    $ sudo apt-get update
    $ sudo apt-get upgrade
  8. The Pi needs to have a fixed IP, because it won’t actually send anything to the Diskstation. Instead it’s the other way around the Diskstation will pull the feed from Pi, and in order to do that, the Diskstation needs a fixed IP to turn to. My way of choice to configure a fixed IP is (you need to enter the right IP settings for your network and your Pi):
    $ sudo nano /etc/dhcpcd.conf
    interface wlan0
  9. Reboot the Pi if necessary.

Installing Motion

Motion is a software package developed to detect… motion (haha!) on image feeds. It is installed with the following commands:

$ wget
$ sudo apt-get install gdebi-core
$ sudo gdebi pi_jessie_motion_4.0.1-1_armhf.deb


$ mkdir /home/pi/motion_conf
$ cp /etc/motion/motion.conf /home/pi/motion_conf/motion.conf

we create a folder into which we copy the default motion configuration file, and then this copy will be adjusted and used to start motion with. So go ahead and run:

$ sudo nano ./motion_conf/motion.conf

The things I recommend to change, in the order they appear in the configuration file (hint: Motion manual with all the details on these parameters

  • rotate XXX (this simply varies, only multiples of 90 allowed)
  • width 1280
  • height 960
  • framerate 2
  • Uncomment mmalcam_name
    (this is the picamera module, and we are using it)
  • output_pictures center or best saved image with the motion detected
  • quality 90
  • ffmpeg_output_movies off because we aren’t actually video-feeding, but only feeding jpegs (and only saving those as well)
  • locate_motion_mode preview and locate_motion_style redbox will draw a red box around the detected motion area
  • text_changes on shows the number of pixels changed
  • target_dir /home/pi/motion_capture this is the location folder into which motion will save images with detected motion
  • stream_quality 90
  • stream_localhost off because you want the Synology being able to access the stream
  • webcontrol_localhost off and you may want to be able to change settings from other machines than the Pi itself

You may also want to play with the Motion Detection Settings (threshold, event_gap, etc.). I leave that to your taste, as it’s mostly for alerting (into which we’ll get in another article). You can also get an example motion.conf in the according GitHub-respository.

We’re almost finished now. Save the configuration changes and run motion with the custom config once manually by:

$ motion -c /motion_conf/motion.conf

Watch for error messages, if all goes well, you should be able to access the feed on http://IP_OF_THE_PI:8081

Now we need to make sure, motion starts on system start. For this we’ll edit the rc.local file with nano and copy the same command into it:

$ sudo nano /etc/rc.local
motion -c /motion_conf/motion.conf

Setting up the Synology Diskstation – Surveillance Station

Okay, last stretch. Really. If you haven’t so far, install the Surveillance Station package on your Diskstation. Once that’s done, and you’re logged into the Surveillance Station module:

  1. Click on IP-Camera and add a new camera. Click Next.
  2. Choose the Complete Setup. Click Next.
  3. Enter the connection data, with port 8081 as the feed port. The Diskstation needs a source path, though it doesn’t really matter what it entered there to my experience. Click Next.
  4. On the Video page of the wizard, disable Audio.
  5. On the Recording page of the wizard, configure how long / much you want to keep the videos. Click Next.
  6. On the Schedule page of the wizard, set if you want to have continous recording or only on motion detected (by the Diskstation, not the Pi), or combined, etc.. Finish the wizard.

That’s it, you should now get a preview from your new Surveillance Pi, and can also access it with the Live View app in the Surveillance Station.


Final Thoughts

  • By default Synology only licenses 2 cameras per Diskstation (at least with our DS 216 II+), so only two PI’ possible right now. You may want to take this into consideration before going on a Pi with camera shopping spree.
  • If you want to place the PI outside, make sure the case is weather proof (water & humidity), as well as the typical temperatures in your region (can the PI handle 40°C + or -20°C for example?).
  • With a small power bank, this thing can be mobile easily though.
  • This will not directly make the home more safe. Intruders don’t know of your Pi when breaking in (how could they, unless you’ll write a big sign). It may give the authorities something to work though, if intruders did happen (which I hope they don’t).
  • I will have a 2nd part to this article, regarding the alerting.
  • There are alternatives which use a complete OS for the PI for the motion detection (I wanted to the Pi’ to potentially do a few other tasks as well, which is why I chose my own way): HOWTO – Set up Raspberry IP Camera on Synology Surveillance station
  1. Headless Raspberry Pi Setup with Raspbian Jessie
  2. Building a Motion Activated Security Camera with the Raspberry Pi Zero
Please follow and like us:



4 thoughts on “How I connected my RaspberryPi Zero W (with camera) to my Synology NAS (DS 216 II+) and use it in the Diskstations Surveillance Station

  1. I’m a total newbie at this. Followed all steps and up until the copy
    $ cp /etc/motion/motion.conf ~/.motion_conf/motion.conf , everything seemed to go fine.
    The file can’t be copied though. I get this error message:
    cp: cannot create regular file ‘/home/pi/.motion_conf/motion.conf’: No such file or directory.
    What to do?

    1. I apologise, those two lines were not quite correct. Please try this:
      $ mkdir /home/pi/motion_conf
      $ cp /etc/motion/motion.conf /home/pi/motion_conf/motion.conf

  2. The default config you’ve given will put all images into a directory in pi’s home dir.

    After a time – this will fill up the disk. When connected to the Synology, do I need to output the pics to disk? Or can that be eliminated? Or do you do some “logrotate” type cleanup of this directory daily, etc.?

    1. You’re right, I forgot to include the cronjob, which cleans up the old files. I’ll include that tonight when I’m home again.

      For the feed to the Synology, saving the images on the Pi is not necessary. The Synology will grab the live images from the motion-page on the Pi.

Leave a Reply

Your email address will not be published. Required fields are marked *