Setting up a Wyze Server


What is a Wyze Server?

A Wyze Server allows you to expand the capabilities of your Wyze cameras beyond what the phone app or online service can do. The benefits you will see are: Here's an example of my cameras in action:



Here's an example of what it looks like you look up previously recorded video clips. They're all time-stamped and the file size is usually a good indication of how much action it recorded since it only records when it detects motion -- the bigger the file, the longer the motion event was. I say usually though, because a good wind blowing in a tree will set it off, so you will have a lot of false positives. But I figure it's better to have too much than too little, when you need it.



What You'll Need


Tasks to Complete

This is the part where you're probably going to get overwhelmed because it looks like a lot of tecno-babble. We will be using linux because it's free and powerful, but you will need to install and configure it. You will also need to configure your router and your DNS service. I will give you as many specific examples as possible, especially the linux commands, but some things will be impossible for me to do so, like the router setup. I can't possibly know which router you have so all I can do is tell you what you need to do, then you'll have to go in and configure your specific device. Here is the list of what we're going to do in this tutorial:
Let's get to it!

Set up your Wyze cameras

Follow the instructions that came with your camera to do the initial setup. Alternately, you can follow this guide https://wyzelabs.zendesk.com/hc/en-us/articles/360030110891-Wyze-Cam-Setup-Guide. Repeat for all of your cameras.

Enabling RTSP on your Wyze camera

Wyze cameras support RTSP, which is necessary for this to work, but they don't come out of the box with this enabled. You will have to go to their website, download the special firmware, copy it to the small (1+ GB) micro SD card, then flash your camera with it. Wyze gives complete instructions here: https://support.wyzecam.com/hc/en-us/articles/360026245231-Wyze-Cam-RTSP. During this setup, you will create a username and password, and be given an IP address (it will look something like this: 192.168.1.100), write these down and save for later. Repeat this process for all your cameras. You can use the same username and password for each camera, but each camera will give you a different IP address. Write these down and for which camera they belong to.

After this is done, take the small SD card out and put the 32 GB card in the camera. This step isn't absolutely critical, but it's a good backup option. If your server or network go down, you'll lose your ability to record motion events, BUT the camera will record to the SD card still. So if something happens and your server goes down and loses the footage, you can still get at from the Wyze app (by reading the camera's SD card). Just remember, a 32 gb card is the biggest they can take and it only stores about a day or two of footage at a time (which then gets overwritten by new footage).


Reserve IP addresses in your router for your Wyze cameras

Wyze cameras cannot be setup with a static IP address (one that doesn't change). If you restart your Wyze camera, it may reserve a different IP address, causing your feed to stop working (because it'll still be looking at the old address). You need to go into your router and reserve the IP addresses for each camera so that your router will never let another device use that number.

To do this, you need to know the IP Address and MAC Address of each of your cameras. An IP address will look something like 192.168.1.100 and a MAC address will look someting like 12:AB:45:CD:67:EF. The easiest way to get these is to use the Wyze app and look up each camera individually, following the instructions located here: https://wyzelabs.zendesk.com/hc/en-us/articles/360031216452-Finding-your-camera-s-MAC-address#:~:text=Using%20the%20Wyze%20App&text=From%20the%20Home%20tab%20select,go%20to%20the%20Live%20Stream.&text=on%20the%20top%20left%20to,will%20see%20the%20MAC%20address.

Now that you know the numbers, go into your router and find the section related to IP Address Reservation. Each record will ask you for the MAC Address and IP Address, use the combinations you got in the Wyze app, one row per camera. Basically you're just telling your router that "this MAC Address belongs to IP Address" and it will enforce that going forward. This may be confusing but do not skip this step! It may appear to work at first if you skip this step, but the next time you restart your Wyze camera it'll probably break because your web server will be looking at the wrong address.


Set up dynamic DNS service

While this step talks about IP addresses, they are NOT the same IP addresses for your cameras. This step is actually talking about the IP address you get for your house from your internet service provider

Why this is needed: you need a way to find your way back to your home computer even when you're not at home. This is an IP address, but the problem is home internet users usually have an IP address that periodically changes. Using a dynamic DNS service will let you always go to, say, something like http://iamawesome.ddns.net and it will know which is the right IP address to send you to to get to your home computer. Start by creating an account here: http://freeddns.noip.com. During this setup, you will create a hostname (e.g. iamawesome.ddns.net, which I will use to refer to as an example in this guide), a username, and a password. Write these down and save them for later.


Updating your dynamic DNS service

Now that you have a dynamic DNS service, you also need a way to keep it updated as your home IP address changes. This can be done a few different ways: No matter what you do, do not skip this step! Everything will seemingly work at first if you skip this step, but after some time, you will probably randomly get a new IP address from your internet service provider, which will make this stop working. At some point I may get around to writing a ddclient tutorial to help with this step. It may be worth noting that if you get a static IP address from your ISP, you wouldn't need to do this, but that's fairly rare. If you're not sure, you probably don't, and you need to do this step.


Installing Ubuntu Server on your dedicated PC

I recommend using Ubuntu Server for this, so go ahead and download the latest version of Ubuntu Server, flash it to a USB stick, and install Ubuntu Server on the PC you've dedicated for this. In case it wasn't clear, do not do this on your main computer. You will be dedicating a cheap PC to do this (the one you maybe got from Ebay or Newegg). Installing Ubuntu Server on it will be the only thing it does -- and it doesn't even have a desktop environment because we want to make it run as lean as possible. Anyway, I don't have the means to show a step by step install of Ubuntu Server, but if you've never done it before, this is a video that can help: https://www.youtube.com/watch?v=xUH256WAWt0. Just focus on the installation portion, no need to follow the instructions on installing a web server because I'll be walking you through that. A couple things I recommend while installing this: What is SSH Server? Most times when I install linux on anything, I just have the computer runnin with no keyboard, mouse, or monitor. It just sits there and does its thing. But what happens when I need to update something on it? That's where SSH comes in -- it lets you run a program on your main PC and "dial into" the linux server and control it as if you were sitting there with a keyboard and monitor. You WILL need a keyboard and monitor while installing it the first time, but after you get it to the point you can connect via SSH, you can toss the monitor and keyboard in the closet and just control it from your main computer. This is optional of course, you can keep a dedicated monitor and keyboard on it if you'd like. If you want to utilize the SSH connection, go download putty: https://www.putty.org/ for your main computer, we'll use it shortly.

If everything went according to plan you should have a fully installed version of Ubuntu Server on your PC and you're sitting there with a black and white screen with a bunch of gibberish on it. Go ahead and login to it by giving it your username and password you setup during install. When logged in you should see a prompt that says username@wyzeos:~$. This is your command prompt and where we will issue all commands going forward.

The first step is to setup your IP adress as static. As of this writing, this is how it's done in Ubuntu Server 20.04 LTS. This has changed over the years so if this isn't working, you may need to find updated instructions. Remember how your cameras all had unique IP adresses, something like 192.168.1.100? Well you need to give your Ubuntu Server a unique address too. You will have to consult your router to see what all devices are using which addresses, but it's usually safe to use a high number, so for this guide I'm going to say let's use 192.168.1.200 (remember -- if your network uses a different numbering scheme, like 192.168.2.1 or 192.168.100.1, you will have to mimic the first 3 numbers, and for the fourth just use 200, so 192.168.1.200, etc). To set this, type the following commands:
ip link (press enter)

You should see some gibberish that looks like this:

What's important here is NOT the "lo" line, but the other one. My example shows "enp0s25", whatever yours shows, write it down!

Now type the command:
ls /etc/netplan (enter)
It should spit you back a filename that looks something like mine, 00-installer-config.yaml


Use that exact filename in the next step, change your command to match the file you see, and do the command
sudo nano /etc/netplan/00-installer-config.yaml (enter, it will probably ask you to re-supply your password)

Remember to change it if you had a different filename, so if yours was net.yaml, you'd do sudo nano /etc/netplan/net.yaml.
You should now see a screen that looks like this:

It really doesn't matter what's in here, just make it match this instead, but there are a few watchouts:

Now press CTRL-X, it'll ask if you want to save, press Y, it'll ask what filename, we want to keep the same filename, so just press enter and it should save the file. Now issue the command:
sudo netplan apply (enter).

Next, issue command ip addr show (enter). You should see some information, look for your ethernet name and verify that it's seeing the IP adress you told it to use (mine is using 192.168.1.222, but just make sure yours is using the right one):

At this point you can start using putty if you want to dial into the computer from your other computer. Load it up, put in the IP address, give it a name, then click save. From here on you can access it by double clicking on the "wyzeos":

The first time you connect to your linux server it will ask you a security question about host keys. Just click yes. It won't ask again after that.

Take a breath, we're through most of the hard stuff, now it's going to get a little easier.


Configuring Your Server

Time to install the software we need. Type the following commands (enter after each):
sudo apt-get update
sudo apt-get install apache2 motion
(answer Y to the prompt, this will take several minutes to complete)
sudo mkdir /var/www/html/motion sudo chmod 777 /var/www/html/motion -R


Most websites respond to port 80, and this will not be the most secure server in the world, but let's make a small tweak to keep out casual prying eyes by changing it to respond to port 8080 instead, use the command:
sudo nano /etc/apache2/ports.conf

The line that says Listen 80, change it to say Listen 8080, then press CTRL-X, Y, enter, to save and exit.

Now do command
sudo nano /etc/apache2/sites-enabled/000-default.conf

Up at the top where it says <VirtualHost *:80>, change it say to <VirtualHost *:8080>, do CTRL-X, Y, enter, to save.
Now issue command:
sudo service apache2 restart

Now we're ready to start configuring motion. Unfortunately, the configuration for motion seems to change from time to time, including the setting names, so as much as I wish I could give you a quick copy/paste, you're going to have to go into the config file and update it as appropriate. If any of the options are missing or named differently than what I have here, you're going to have to consult the motion documentation because they probably changed something. I'll highligt the important parts here. First, issue command:

sudo nano /etc/motion/motion.conf
  1. Look for daemon off and change it to daemon on
  2. Look for target_dir /var/lib/motion and change it to target_dir /var/www/html/motion
  3. Look for videodevice /dev/video0 and put a semicolon in front of it, so change to ;videodevice /dev/video0
  4. Look for movie_output off and change to movie_output on (it may already be on by default)
  5. Look for movie_max_time 60 and change to movie_max_time 300
  6. Look for movie_codec mkv and change to movie_codec mp4
  7. Look for webcontrol_port 8080 and change to webcontrol_port 8081
  8. Look for stream_port 8081 and change to stream_port 8082
  9. Look for stream_localhost on and change to stream_localhost off
Notice this section, you need to change this depending on how many cameras you have. Basically, for however many cameras you have, uncomment (remove the semicolon) from the line. If you have 3 cameras, remove the semicolon from the camera1.conf line, the camera2.conf line, and the camera3.conf line. If you have more than 4, you can make an additional line for camera5.conf, just copy the template. I wouldn't run more than 5 cameras per machine unless you have a really powerful computer.
##############################################################
# Camera config files - One for each camera.
##############################################################
; camera /etc/motion/camera1.conf
; camera /etc/motion/camera2.conf
; camera /etc/motion/camera3.conf
; camera /etc/motion/camera4.conf


CTRL-X, Y, enter to save and exit.

Now you need to make a configuration file for every camera you have, so repeat this step for as many cameras you have. Change camera1/cam1 to camera2/cam2, etc for each camera. You don't have to use cam1 and such, you could name them FRONTDOOR or whatever, this is just an example. What's important is that the filename matches what is being called in the camera config files section of the previous configuration file. So for each camera do:
sudo nano /etc/motion/camera1.conf

It should open a blank file, paste or type this in -- hint, if you're doing this via putty, when you right click your mouse in putty it sends a "paste" command, so you can copy this and the right click in putty to paste it:

camera_name CAM1
camera_id 101
netcam_url rtsp://username:password@192.168.1.205/live
width 800
height 450
text_left CAM1
text_right
movie_filename CAM1_%t-%v-%Y%m%d%H%M%S
movie_output on
framerate 15
stream_maxrate 15

CTRL-X, Y, enter to save and exit. NOTE! - change the camera_id 101 to match each camera, so 102 for cam2, 103 for cam3, etc. For the netcam_url line, modify to match the username and password and IP adress for the camera when you set up RTSP mode on it from earlier. Lastly, repeat this for each camera you have, modifying the information as appropriate.

Now we want to remove the default apache website, so do command:
sudo rm -rf /var/www/html/index.html

Now do:
sudo nano /var/www/html/index.html

It should open a blank file, paste this code into it, CTRL-X, Y, enter to save and exit.
Important part here, see the line that says <iframe src..., you need to replicate that line for each camera you have, remembering to change the camera_id as approriate. So if you had three cameras, you'd do something like:


IMPORTANT - the file examples above are shown as they are to help you understand how this works, but there's one major problem here, we're referencing our internal IP addresses. This works just fine if you only want to watch them locally on your LAN. But if you want to be able to watch remotely, e.g. from your office, that's why we did the dynamic DNS thing. So we need to tell this webpage where to find the cameras externally, which would look like this:

Do NOT modify your motion cam.conf files, they do need to be set up with the internal IP addresses to work.



We need to do one more thing now, we probably don't want to keep videos saved forever. Eventually you're going to fill up your hard drive, so let's build in a process to purge files older than 14 days. To do that, do command:
sudo crontab -e (note - you'll probably be asked to choose the default editor, choose the line that corresponds with /bin/nano)

At the end of the file, paste this in:
0 0 * * * sudo find /var/www/html/motion/ -mindepth 1 -mtime +14 -delete

CTRL-X, Y, enter to save and exit.

Just a couple cleanup things. Sometimes Ubuntu Server will boot into the GUI/desktop, but we don't want that. It won't hurt anything, it'll just take resources away from the camera stuff, which is totally unnecessary because we don't need the GUI/desktop for this. Let's just tell it to NOT do that by default by issuing the command:
sudo systemctl set-default multi-user.target

Lastly, we have to tell motion to start up on bootup, so do:
sudo nano /etc/default/motion
The line that says start_motion_daemon=no change to start_motion_daemon=yes, then CTRL-X, Y, and enter to save and exit.

Finally, let's set the local timezone. You have to know exactly how your timezone is called in linux, so first let's see what is allowed by doing:
timedatectl list-timezones

Scroll down by pressing/holding enter, but look for the one you need. The one I need happens to be Chicago (central time) so I'm going to set it to that timezone by issuing command:
sudo timedatectl set-timezone America/Chicago

You can check to see if it worked by issuing command:
date
What it returns should be your local date and time.

Now all you need to do is reboot and it should be good to go! Issue command:
sudo reboot

When it comes back up, try opening a web browser on your other computer, going to http://192.168.1.200:8080 (or http://iamawesome.ddns.net:8080) and you should see your camera feed! HINT - if you have multiple cameras, zoom out (on a computer: hold CTRL and scroll your mouse wheel) to see multiple at the same time.


Set up port forwarding for your Wyze server

The last step to getting this to work is to tell your router to forward all web traffic to your Wyze server. Again, every router will be different, so you may need to seek guidance from your manufacturer's website. Find the port forwarding area of your router, have it forward ports 8080, 8081, and 8082 to the IP adress of your Wyze server, e.g. 192.168.1.200 or whatever you used in the past. Once this is done, now you can go to http://iamawesome.ddns.net:8080, or whatever website you setup with your ddns account with and you should see your cameras! This should work from anywhere, even if you're not at home. You'll also notice a link at the bottom of that webpage that brings you to "Saved Videos". This is where you can view the saved videos from the last 14 days.


If you get stuck, I'm willing to help you out, just email me: bnelson333 at gmail dot com.

Setting up multiple servers

If you have more cameras than your server can handle, you can set up multiple servers. With mine, once I went past 5, I needed to add another server to handle the load, and it works great. The problem is this is going to get more complicated and depending on your situation, it's going to be hard for me to explain exactly what you need to do, but some general pointers: