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

Housekeeping on the Pi, to remove old images (and avoid the disk filling up):

Create a cron job:

0 * * * * find /home/pi/motion_capture/ -iname "*" -mtime +7 -delete

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:



21 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.

  3. Putting this line into /etc/rc.local

    motion -c /motion_conf/motion.conf

    Didn’t work on reboot. I had to change the line in rc.local to this to get motion to start-up on reboot

    motion -c /home/pi/motion_conf/motion.conf

  4. Hi, thank you, very interesting!
    Can I ask you what type of webcam have you used? Raspberry Pi camera module v2.1 or another?
    Image is very realistic with very good colors and perfectly focused.
    How can you reach these results? Have you a special lens or another cam?

    Thank You!

    1. For the security cam I used the Pi Camera Module two indeed. All photos in the article are shot with a Nikon D800.

  5. Hi do i just copy the text into sudo nano ./motion_conf/motion.conf

    I get to framerate 2 then i cant find

    Uncomment mmalcam_name
    (this is the picamera module, and we are using it)
    output_pictures center or best saved image with the motion detected

  6. Hi don’t mind my last text. can you tell me how to run the cornJob
    0 * * * * find /home/pi/motion_capture/ -iname “*” -mtime +7 -delete

  7. When i run motion -c /motion_conf/motion.conf
    i get the following message

    [1:ml1] [NTC] [ALL] image_ring_resize: Resizing pre_capture buffer to 1 items
    [1:ml1] [NTC] [STR] http_bindsock: listening on port 8081
    [1:ml1] [NTC] [ALL] motion_init: Started motion-stream server on port 8081 (auth Disabled)
    [0:web_control] [NTC] [STR] http_bindsock: listening on port 8080
    [0:web_control] [NTC] [STR] httpd_run: Started motion-httpd server on port 8080 (auth Disabled)
    [1:ml1] [WRN] [ALL] motion_loop: Retrying until successful connection with camera
    [1:ml1] [NTC] [VID] vid_v4lx_start: Using videodevice /dev/video0 and input -1
    [1:ml1] [ALR] [VID] vid_v4lx_start: Failed to open video device /dev/video0: No such file or directory
    [1:ml1] [WRN] [ALL] motion_loop: Retrying until successful connection with camera

    1. It cannot get the camera working there, or at least a connection to it. To be honest, I didn’t encounter the issue so I don’t have any substantial tips here (other than the obvious, check the connector cables, try the command line commands to capture an image with the camera: ). If that works, try the default motion config in terms of resolution and frame rate and see if that works.

  8. Hi,

    thank you for your Guide normally i think ti should work fine but a have a little problem and i am absolutely new to Rasperrys ;-).

    After i want to install motion i get this error:

    pi@raspberrypi:~ $ sudo gdebi pi_jessie_motion_4.0.1-1_armhf.deb
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Reading state information… Done
    This package is uninstallable
    Dependency is not satisfiable: libavcodec56 (>= 6:11~beta1)|libavcodec-extra-56 (>= 6:11.7)

    Could you please help me with that? 😉

    1. Okay i found out that i can istall motion now only by this command because it is include in the actual raspian image sudo apt-get install motion .

      but now if got another problem after i want to start motion….. could you also help me with that?

      pi@raspberrypi:~ $ motion -c ./motion_conf/motion.conf
      [0:motion] [NTC] [ALL] conf_load: Processing thread 0 – config file ./motion_conf/motion.conf
      [0:motion] [NTC] [ALL] motion_startup: Motion 4.0 Started
      [0:motion] [ERR] [ALL] create_path: Problem creating directory /var/log/motion: Permission denied
      [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

      Message from syslogd@raspberrypi at May 27 11:45:24 …
      motion: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

      Broadcast message from systemd-journald@raspberrypi (Sun 2018-05-27 11:45:24 UTC):

      motion[6113]: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

      thank you in advance

  9. …this is great for ‘proof of concept’ but the reality is that licensing has to be purchased once you do more than 2 cameras in the surveillance server… so … has anyone succeeded in getting this setup to work with say… the Ubiquiti Camera controller server (which doesn’t require ‘per device licensing’)???? Just a thought.

    1. Sometimes only one camera is needed or two, and other hardware isn’t available. Then this approach should do fine. There never was a claim that this is the one-size-fits-all solution.

  10. Great project!
    I have had the Synology NAS for a few years now. And have recently started playing with the Pi Zero W Camera kits and wanted to set up the Synology Surveillance Station.
    Your instructions worked perfectly from step 1.
    Only of course had to make a couple modifications:
    – Using Stretch-Lite on the Pi Zero W so I used a different release for Motion: pi_stretch_motion_4.1.1-1_armhf.deb and modified the install accordingly. And still works fine. (Then of course, I saw your note that Motion is included …)
    – Also for the directory where Motion will record imagery, I figured – ‘Hey I have a nice Synology NAS.’ So I set up NFS on the Pi Zero W to mount a directory from the NAS to the PI and now if it wants to record I don’t have to worry about the SD card filling up or running a cronjob to clean up the dir.

    But … One minor irritant I have found is the video in Live View is pretty laggy. By my rough check it is 2~3 seconds behind. So if I wave my hand in front of the camera, I don’t see anything in the Live View display for 2~3+ seconds. — Any ideas?

    Again many thanks!

Leave a Reply

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