Tuesday, December 31, 2013

Garage Door Controller Tutorial - Using the app away from home

As I mentioned in different places throughout my tutorial, you can use your smartphone to check the status of, and open/close your garage door from anywhere in the world. However, as I mentioned in the last post (Step 9) of this tutorial, we set it up so that you can only access your Garage Door Controller from within your own network. This is because it is the easiest way to get you up and running. If you want to expand upon that and be able to access your garage door controller from anywhere, then we need to do a little more work...

Note - You should read this article in its entirety before drawing any conclusions about the path(s) you want/need to take to overcome any problems that you may have.

Please take a moment to look at the following diagram:

No, I do not claim to be an artist

Do you see that vertical red bar that is going through the center of the router? I'm trying to show that the LAN and WAN sides of the router are blocked off from each other. This is actually not entirely true because the router does allow computers from the LAN to access the Internet (WAN), but devices and computers from the Internet (WAN) cannot access the devices and computers inside the LAN. This is by design.

Those numbers below each device are called IP addresses. Every device that goes on the Internet must have one. All the devices inside your home network have a similar one, but the last section of numbers (i.e. the '15' or '16' or '123') must be unique. All of these devices inside your home network can communicate with each other. So, your smartphone can easily connect to and communicate with your Garage Door Controller with no problem as long as your smartphone is in physical range of your wireless router. Once your phone travels out of your router's wireless range, it connects to the Internet via your cell carrier's network, receiving a completely different IP address. Once this happens, it can no longer communicate with your internal network. Therefore it cannot communicate with your Garage Door Controller. This is our first problem:

Problem #1 - Can't connect to Garage Door Controller outside home network

If you think you are going to want/need to connect to your Garage Door Controller outside of your home network, you're going to have to do a little more work.

Solution for Problem #1

The solution to this problem is fairly simple in theory: Enter the WAN IP of your router into the 'IP address or domain (url):' field of the Android app, then tell your router to forward the traffic through. However, this brings up another problem:

Problem #2 - Your WAN IP address is dynamic (changes frequently)

If you have a 'home' account with your ISP, then it's highly likely that your WAN IP address (actual IP assigned from your ISP) is dynamic - changes from time to time (the frequency varies depending on multiple factors).

If you have a 'static IP' (one that doesn't change) (sometimes business accounts may be provided with a static IP), then problem #2 doesn't apply to you - just enter that IP address (it will never change) in your app, and you're good to go. You can skip to  'Problem #3' below.

If you are like most of us and have a dynamic IP, you would have to change it in your smartphone's app setting constantly. But knowing when it changes or what it actually is at any given time is not easy or practical.

Solution for Problem #2

The solution to this problem is called Dynamic DNS.

One of the most popular Dynamic DNS services out there is NoIP. Sign up for a free account with them. Here's a 'Getting Started Guide' that they created. Once you're all done setting up your account and choosing a domain and hostname, enter in your new URL (i.e. theSmithsGarageDoorController.no-ip.com) into the 'IP address or domain (url)' field of the smartphone app.

Please note a couple things:

  1. If you went with the free (NoIP) service, you will have to click a link in an email that they send every 30 days to keep the account alive. (If you go with the paid service, you don't have to do this)
  2. In order for your shiny new URL to always be accurate (remember, your WAN IP address changes from time to time), you need to do 1 of 2 things:
    1. Install the DUC software (offered for free on their website) on your computer so that it can constantly check/update DNS records. Please note that if you go this route, your computer should always be turned on...or at least turned on once a day...OR
    2. If your router supports it, configure your router to update it. Look for DDNS or Dynamic DNS settings in your router and enter the appropriate information for your account

Problem #3 - Your router blocks traffic from the Internet to your internal network

There is one more thing you have to do with your router in order to access the Garage Door Controller from outside of your LAN. Remember how I said that your router blocks all traffic from the outside trying to come in? Well this fact would normally prevent you from accessing your Garage Door Controller from the Internet.

Solution for Problem #3

Most (if not all) routers that you have bought within the last several years allow you to create what's called a pinhole, or port forward (different router manufactures use different terms, though 'port forward' seems to be the most popular term) in order to allow a specific kind of traffic to come through to a specific IP address. Here is a brief explanation of port forwarding.

You're going to need a few pieces of information to successfully set up a port forward on your router. You are going to need the port # and IP address of your Garage Door Controller. You should have these 2 pieces of information from Step 3 - The microcontroller. The 3rd piece of information is the protocol, and that is going to be 'TCP'.

With those 3 pieces of information, you have what you need to set up a port forward on your router for your Garage Door Controller. I can't tell you exactly how to log in to your router and configure a port forward as the steps vary from manufacturer to manufacturer and even model to model. But, there is a great resource, portforward.com, that can!

Follow their guide on 'How to Get an Open Port'. You'll need to select your router's manufacturer in the list, then the model number. You will then be at another long list, this time of 'programs'. You can pick any one of them, as it doesn't matter. So just for simplicity, just click on 'Beyond Remote'. Follow the instructions, but replace all references of '5424' ('Beyond Remote's specific port) with the port number you chose in Step 3 of my tutorial. (The default is '4999', but it needs to be whatever you specified). Where it asks for IP address, enter whatever IP address you assigned your Garage Door Controller. And lastly, the 3rd piece of information is the protocol, which is 'TCP'.

There may be a couple of things in the instructions on that guide that may make things a little confusing:

  1. If it mentions that your computer needs to have a static IP, you can ignore that. We're not setting up a port forward to your computer - we're setting it up for your Garage Door Controller, which is already set up with a static IP address. (Done in Step 3 - The microcontroller)
  2. If it asks you to enter the IP address assigned to your computer, don't enter your computer's IP address, but again, use your Garage Door Controller's IP address.

Now that you have your own personalized URL pointing to your Garage Door Controller, you can enter that into the 'IP address or domain (url)' field in the Garage Door Controller app. Now you should be able to be at work, or on vacation in the Bahamas, or around the corner from your house and be able to open/close (or check the status of) your garage door from your smartphone!

We're not quite out of the clear yet though...we have 1 more potential problem to overcome. :(

Problem #4 - Your router doesn't support loopback

Here is a possible scenario:
Your app works great away from home, connecting to your Garage Door Controller via your static WAN IP address (not likely using this), or your new domain/URL (much more likely). When you are home, with your smartphone connected to your WiFi now (which puts it on your internal LAN/network), you can't connect.

This is caused by your router not supporting something called loopback. You see, you can't be inside your internal network, go out through the internet and connect back into it. Many routers unfortunately don't support this. The solution(s) to this problem depends on how you're using your device.

Solutions for Problem #4

If you just want to simply open the garage door when you get home, the solution is simple:

Simply connect to your system before you get too close to your house (within range of your wi-fi) and open/close the garage door.

If you want to use the Garage Door Controller away from home just as much as you do when you're home, you have a couple of options:

  1. When you're away, use your new domain/URL to connect, and when you're home use the Garage Door Controller's internal IP address. This isn't exactly ideal as you're constantly changing that 1 setting in the app, but it would work.
  2. Buy a router that supports loopback.(I did not create that list or do I have any affiliation with it or the website that maintains it). I know this isn't ideal either as you have to purchase new equipment and then configure/install it, but at least it would be a permanent solution that would allow you to 'set it and forget it' - it would always work without you thinking about it anymore. This is the solution I use. I have a Linksys WRT54GL router with Tomato firmware loaded on it, and I love it!
  3. If you already have a router that supports the Tomato or dd-wrt firmware, you may be able to just do a firmware upgrade, and that might (the Tomato firmware should work as mine is working, but may not be the same as what you download, and I've never used dd-wrt so can't speak for that one) give you loopback support.
  4. If you have a server at home, or if your router has a VPN server, you could configure your app to use the Garage Door Controller's LAN IP address. When you're home, no further action is required. If you are away from home, you would need to use a VPN client on your smartphone to VPN into your network, then you would be able to open up the Garage Door Controller app, and use it like as if you were home.

If you have any questions regarding any of this, please contact me, and I will do my best to help you out.

No comments:

Post a Comment