This article is part of a series about how to spy your pet with Raspberry Pi, don’t miss the first step here: where I describe how to set up a camera stream server! Spy your pet with a Raspberry Pi Camera Server Final result of the tutorials : a full connected cage ! In order to access your Raspberry Pi from anywhere, you need to be able to enter your home network! What is the only way of accessing it from anywhere? Your IP address! It’s basically like your home address but on the internet. However, most of home networks IP adresses change dynamically after a certain time. So let’s say you use it directly to access your PI, it would only work for a short time and then you’ll need to go home and check it again. Oh! Then could we create a script in our Raspberry Pi that checks our IP address and mail it back to us? You could! But assuming you want to build a website or an app that uses this IP to access your PI, you will have to continuously do updates to change the IP. Which is very annoying right? Then, maybe I can ask to have a fixed IP address at home ? Yes ! But most internet providers still charge fixed IP adresses. That’s why I used a free DDNS tool. Dynamic DNS with no-ip To access my PI from anywhere, I used a service called Dynamic DNS or Domain Name Server. What does it involve? You choose a name for your home network that will redirect requests to an IP address stored on no-ip servers. I chose http://mochi.ddns.net You install the no-ip script in your Raspberry PI. This will make sure that your home IP address stored on no-ip is always updated. I used services because you can have one free dynamic DNS. There are plenty other offers online and you can choose whatever service suits you. The principle remains the same. no-ip Step 1: Create your domain name After , in the dashboard, simply go in the “Dynamic DNS” section. Then “Create Hostname”. Choose a name on the next screen, let the options by default and validate. Now let’s go back on our Pi! subscribing Step 2: Install the no-ip script on your PI Let’s download the script from no-ip first. On the Raspberry PI terminal: mkdir /home/pi/noipcd /home/pi/noip vzxf noip-duc-linux.tar.gz # Create the directory, step into, and download the script wget _http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz_tar This should have created another directory with a folder named by the last version of no-ip script. _cd noip- <the_version_you_have_downloaded>_**sudo make install # Install no-ip script! ** You are going to be prompted to login with your no-ip account. After that, when asked how often you want the updates to be triggered, I recommend 15min. Now let’s launch the service! sudo /usr/local/bin/noip2 sudo noip2 -S # To confirm the service is running properly Last step, we want to automate the service launch. If we don’t, you will have to do it after every single reboot of the Pi. sudo nano /etc/rc.local # Open the boot file /usr/local/bin/noip2 # Add this line at the bottom of the file (just before exit 0) Done! Now we have an automated system that updates our domain name IP alone! Here comes the tricky part. Configuring your internet box Ok, we have a domain name that always redirects to our home network. However, your internet box (a.k.a ) doesn’t know how to deal with the incoming requests! We need to ask All routers are different, the best thing to do is to search “Port forwarding” on the web with your brand and model. I will highlight here the main things you’ll have to do. router “Hey please, redirect incoming requests to the Raspberry Pi”. Connect to your router administration panel On a web browser, type your router IP address in the URL bar. Typically it’s 192.168.1.1 or 192.168.1.254. If not, it should be somewhere in your router manual. Login. By default credentials are often admin & admin or 0000. In the router admin page, find the section. port forwarding Configure the port forwarding to your PI After finding the port forwarding, you’ll need to add a new rule. Here’s an example with the parameters and their meaning. French BBOX port forwarding configuration French Livebox port forwarding configuration with a additional rule for a web server (80). From left to right : Application, internal port, external port, protocol, device, active : The port on the raspberry Pi where requests should be redirected to. In our case, the video stream server is at 8081 if you followed the first tutorial. Internal Port : We don’t want ALL requests redirect to our PI. Only those that are targeting the camera server. Since we are going to use a browser, or an app to access our Pi, we can request our home network with any port we want. (for example we will use To make it simple, I used the same as the video stream server: 8081. External Port http://mochi.ddns.net:XXXX). : Set this to ALL. Protocol : The IP of the Pi in your home network. That’s where we are going to redirect the incoming requests so they can reach our Pi. To find it, type the following command (on your Pi): IP Address / Device ifconfig In the command line response, find the which will give you the Raspberry Pi IP “inet addr” wlan0 Link encap:Ethernet HWaddr 80:1f:02:aa:12:58 Bcast:192.168.1.255 Mask:255.255.255.0... inet addr:192.168.1.8 We are actually telling our router: Please redirect all outside world request with port 8081 to the raspberry Pi on port 8081. You may have to restart your router after adding the rule, and finally we’re all set! Access your Raspberry PI Camera stream from anywhere On the previous tutorial we learned how to install Remember the step where you configured ? That port is the entrance gate on your system to the video stream. Now we’re going to use that… and it’s dead simple! Motion Pi. the port for the stream server ⚠️ Try this with a different connection than your home. For example, on your smartphone. When being inside your local network, trying to use the DDNS may not work. This is a limitation with . routers https:// .ddns.net: Test your camera from the internet! <your_ddns_name> <motion_port> Authenticate the camera server You can add a username and a password to your camera in order to protect it. If you have followed the and use motion, you can do : previous tutorial sudo vim /etc/motion/motion.conf# Add this line in the filewebcontrol_authentication username:password See for more details and options. motion documentation All this tutorial also works for any exposed service on your raspberry PI. For example, a web server where you could have a website. (port would be 80 then). Capture from a distant browser Connected food dispenser! (Next article) In my next article, I will show you and then from anywhere with a webserver ! how to build a food dispenser with your Raspberry Pi trigger it If you’ve liked this article and that it helped you building your own remote system on your Pi, please post a picture of it =D! Thank you so much for reading. See you soon.
Share Your Thoughts