On this post, I will explain how to turn your old Android phone into a dedicated IP Cam. This will be more than just downloading an app and running it.
Difficulty : Advanced
What will you achieve ?
- Your phone will broadcast over the internet so you will be able to watch your cam from everywhere that you are connected. (It is possible to set a password protection)
- Not only you will have visuals, you will be able to hear every sound around your phone.
- If your cam detects a motion, you will be notified via email that contains a link to connect your IP cam.
- Your cam will start recording when it detects motion and keep recording until 5 seconds after the motion stops.
- The videos that are recorded will auto-sync to your Google Drive instantly and be deleted (so that your phone will never run out of storage).
Tools you’ll need
- An unused Android phone
- A charger (preferably a dock so that it would stand without moving)
- A home wifi network (and obviously a router)
- IP Webcam PRO (Google Play Link) $3.99
- Tasker (Google Play Link) $2.99
- SendSilentMail Plug-in (Google Play Link) $0.99
- AutoSync for Google Drive (Google Play Link) free
- K-9 Mail (Google Play Link) free
First of all, you have to have an wi-fi connection for this to work. You place your phone to a nice angle and connect it to the internet. You then run the IP Webcam Pro app. Scroll to the bottom and hit “Start Server” button.
When you first start the server, the webcam runs over your private network. This means it is not open to the internet yet, it is only reachable to the devices that are connected to your wifi. When you hit start server button, the program will give you an IP address (it will look something like 192.168.1.44). That is the address of your local server. And also it indicates that the port is 8080 (this is by default, you can change it form the settings). Your local server has the IP address 192.168.1.44 and runs over the port 8080. When you open a browser and navigate to 192.168.1.44:8080 from a device that is connected to your wifi, you will reach to the control panel of your IP camera. Your server serves a simple web page that contains the controls of your IP cam. You can mess around the control panel and inspect what can you do with it, there is fun stuff like taking pictures or toggling the flash light of the phone. Now start the server from the app and we will dive into some configurations and settings…
Assigning a Static IP to your device
There are certain problems with IP allocation that you’ll need to handle. Each time your device re-connects to your wifi, your router will assigns a new IP address to your Android phone. 192.168.1.44 was an IP address that is dynamically assigned to my phone by my router. But next time, this won’t be the same. You don’t want this because you want the IP address to stay the same or it will cause problems within the next steps. To do this, you will need to assign a Static IP to your android phone from your router’s control panel.
If you are a Mac user, go to Settings -> Network -> (select Wi-Fi from the left pane) -> Advanced -> TCP/IP and find the ip address that is indicated with “Router”. If you are a Windows user, best way to do is to open the command prompt (cmd) -> type “ipconfig” and press Enter -> find the ip address that is indicated with “Default Gateway” which is your router’s IP address. Router’s ip address will look something 192.168.1.1. You have to type the IP address to your address bar and hit enter. Next, you will be asked a username and a password for the router control panel. If you have changed these information before, enter your username and password and login to the control panel. If this is your first time, search Google for the default username and password of the router control panel for your routers brand.
Every router brand has a different router control panel interface, so I can’t give absolute and strict instructions. I will theoretically explain what you should do and wish you the best of luck☺ You can always email me and ask for help though. Usually on the landing page of the router interfaces there will be a network map that shows the devices that are connected to the wifi. You have to find your phone on that network map. There should be a link that shows information like MAC address or assigned IP address to that network element on each item. To make sure that the network element represents your phone, you can compare MAC addresses (How to find MAC address of Android Devices). Or you can recognise it from the dynamically assigned IP address, it should match the IP address given to you when you first start your local server from your phone. Anyways, when you locate your device, you should give a Static IP (Static DHCP) to your device. You should probably find a list of Static DHCP’s and there should be an add button somewhere near the list. And you should enter the MAC address of your device and the IP you want to assign to the device. Enter the one that is already assigned to your device to avoid invalid addresses. Once you have done this, the IP address that is assigned to you device will allways be the same.
Your job with the router panel is still not complete. Now each time you start your local server from the app, it will have the same IP, means you will always be able to reach your cam from the private IP (the one like 192.168.1.44:8080). But there is a problem, you can only reach to the panel from the devices that are connected to your wifi. This means you cannot reach your camera from work or from your mobile data. To get around this, you will need to use a technique called Port Forwarding. The idea behind this is simple: every user that is connected to the internet has a public IP address. It is assigned to you by your ISP (Internet Service Provider). This address is like your home address which people can send letters to, it is public and open to the internet, it is visible and accessible from every device that has an internet connection. What port forwarding does is to map your public IP address and the port number to the one that is locally assigned to your device by your router. Think of it this way, the public IP address is your home address and port number is the door number (in this case you have many entrance doors to your house). You ask your servant (which is your router) to lead your visitors that comes to your house through a specific door to the room inside your house which has the camera (that room represents 192.168.1.44:8080).
Just like in the previous section, there is no absolute way I can instruct you to make these settings. What you should look for on your router interface is “Port Forwarding”. You should find this option under “NAT” settings. When you find the port forwarding table, you should add the local IP that is assigned to your phone (in my case it is 192.168.1.44) as the server IP, the trigger port (in my case 8080), translation port (again I made it 8080). What you did here was, you ordered the router to map the connections that are coming from outside through the port 8080 to the local server with the IP 192.168.1.44 through the port 8080. Similar to the servant example above. If you are facing problems at this step, you can find further information about port forwarding here.
Once you have done port forwarding, do a port scan to your public IP to see if it worked. As the name suggests, port scan scans your public IP address and finds open ports (ports that are in use). You can find your public IP address here and do the port scan here. The public IP looks something like (220.127.116.11 in my case). If the port that you have forwarded (8080 in my case) seems to be open, then you shouldn’t have a problem. If it is so, open a browser from your mobile phone (that uses its own mobile data) or from a device that is connected to another internet source. Enter publicIp:port (18.104.22.168:8080 in my case) to the address bar. If everything is working fine, you should see the webcam interface. You can connect to your cam from everywhere, now your cam is public.
There is still a problem though, the public IP address that your ISP gives you is also dynamic and changes from time to time. Some internet service providers just give static IP’s for free and some expects an extra fee for this. If you can get a static IP, that’s great. If you can’t get there are some workarounds such as using a service called DDNS but I won’t dive that deep into networking because our workaround will be much simpler and easier to understand. Also our solution will work as the same principles with DDNS, so don’t worry about this for now☺
Tasker Setup & Dynamic Public IP Fix
Tasker is a great app that lets you to automate your phone. It can do many stuff, more than you could imagine (however it is not able to send emails by itself). Best part is, it doesn’t need rooting for most of the actions. In our case, we will use tasker to send ourself emails in case of motion with help from a plugin called SendSilentMail.
We will also fix the issue with the dynamic IP address that is assigned to us by our ISP which I mentioned by the end of the Port Forwarding part. In order to connect to our camera from outside our wifi network, we need to know what IP address is assigned to us. The only way to know is visiting sites like ipecho.net that tells us our public IP address while we are connected to our wifi. That is not possible when we are not at home, so we will use the fact that our camera is always alive and connected to our wifi. We will literally make our phone visit ipecho.net and attach our current IP address to the email body whenever it sends us an email. We will achieve this by tasker, besides from sending an email.
So now is the time to spend some time with Tasker. Before you start tasker, you should have SendSilentMail plugin installed. When you start tasker, navigate to tab “Task”. Tap on the plus sign on the right bottom corner. Name your task whatever you want, I named it “Mail”. You should now be on the task edit page. What you do here is that you arrange the actions to take when the task is trigger by some event, which is detecting a motion (we will enhance this event afterwards). First thing you have to do is to make tasker determine the public IP address by making it visit ipecho.net. Tap on the plus sign below -> Net -> HTTP Get. From this screen, write “ipecho.net” to the Server:Port textbox. Write “plain” to the Path textbox. Tap on the search icon next to the Mime Type textbox and pick “text/plain”. Then, top the back arrow from the top left corner. Now, tap on the plus sign again -> Plugins -> SendSilentMail -> Pencil icon next to configuration. Now it is time to enter your email address here. But only entering the email address is not enough, because the one that is sending the mail will also be your email address. In order to make some app send email from your email, you will need to set up the SMTP data. If you are using gmail, you are in luck because the instructions will be based on Gmail. If not, you could sign up to gmail just for this or use the smtp data of your own email provider (Google it, it is easy). Anyways; under server settings, write “smtp.gmail.com” to the SMTP Host textbox. Write “465” to the SMTP Port textbox. Check the checkbox that says “Needs authentication”. Two new textbox will appear, username and password. Enter your gmail to the username textbox and password to your password textbox. Then, to the “From address” textbox, you can write anything. This will appear on the from-field of your email. To the To address textbox, type your email (to this field, you can enter any email address you want the mail to be sent, and you can even enter multiple email addresses by separating them with a ; sign). Enter a subject to the mail from the “Mail subject” textbox. Here comes the important part. The ‘Mail text’ textbox will be the body of your email. Enter this : “http://%HTTPD:8080”. The previous step that you did on tasker asked for your local IP address to ipecho.net/plain and stored to the result in the variable “%HTTPD”. You now use the variable to retrieve that result from the request. The “:8080” part is the default port that I talked about at the first chapter. If you changed this default port, you should use the one that you changed it to instead of 8080. So the email sent to you will contain a direct link to your IP camera panel. If you have entered everything correctly; when you tap to the “Send Test Mail” button, an email should be sent with the correct information and a link that actually works. If you receive the mail and everything seems fine, jump back to tasker by hitting the back button and tap on the back arrow on the top left corner. Finally if you want a beep when a mail is sent to you, hit the plus sign again -> Alert -> Beep -> back button on the top left corner. If you don’t want it, ignore the last step. When you are done, tap on the play button on the bottom left corner to test your task. When you tap on the play button, it triggers the task and you should receive an email again with the correct information. Everything fine ? Tap to the back button on the top left corner.
Now navigate to the “Profiles” tab. Here you will set up the “Motion Detected” event and enter your task as the trigger. Hit the plus button on the bottom left corner -> State -> Plugin -> IP Webcam Pro -> Pencil icon next to the configuration textbox. From here, check the first radio button “Motion is detected/timed out”. Enter an event name which is not important, and tap “OK” -> back button on the top left corner. Now a popup list should appear on the top right corner listing you the available tasks. Tap on the task you just prepared. Now your email task will trigger when the IP Webcam Pro app detects a motion. Make sure that the “Motion Detection -> Enable Motion Detection” checkbox is checked at the IP Webcam Pro app. Also you should pay attention to the settings below, make sure the record video button is also checked. Because on the later steps, we will make the recorded video get synchronised with your Google Drive. I don’t recommend to make your record time too long, my settings are “Stop video when inactive for : 10 seconds” and “Motion timeout : 15 seconds”. I also make it play a sound when it detect motion. One more thing, you don’t want the detection sensitivity to be too high. You wouldn’t want your cam to spam you on every light change and every time when a fly flies around. My sensitivity is set to 500.
There is one final thing you need to do with tasker. We still have a problem, we handled the email tasks and our cam sends us emails on every motion. But what if we want to connect to our camera without a motion event ? How do we make our phone send us the link to our camera panel without an action ? Here is how : First, install K-9 Mail application. You need to set up K-9 app and connect it to your email. Instructions on how to set up an email address with K9 mail will be provided to you by the app. Then, open tasker and navigate to Profiles tab. Tap on the plus sign -> 3rd Party -> K-9 Email Received. To the subject textbox, write something unique. I used “GETPUBLICIP”. Now tap on the back button on the top left corner. A popup list should appear on the top right corner, again listing the available tasks. Select the mail task you prepared on the previous steps. What you did here is that whenever you send yourself an email with the subject GETPUBLICIP, tasker will detect that mail and send you the email you prepared in case of motion, which includes the link. So you just ask your cam for your public IP by sending yourself an email. Cool, right ?
Google Drive Synchronisation
As the final step of this set up, you should make the videos upload directly to your Google Drive. This is important because if a thief breaks into your house, he/she will probably steal your phone and disconnect ot from your wifi. If you are not able to connect to your panel the exact time when the thief is in your house, the locally stored videos will have no use, you will have no evidence to show to the police. So, you should have your phone upload the videos right away. To achieve this, we will use the application called Drive Autosync.
Open the application, tap to the three dots on the top right corner -> settings. Here, you will have to deal with a lot of settings. Here they are as follows : Synced Folders -> Add Syned Folders -> Navigate to path : “/storage/sdcard0/ipwebcam_videos/modet” (this is where the app records the videos to) -> Select -> (From the list of your folders on Google Drive, create one for your video files) select destination folder on Google Drive -> Select -> Upload and Delete (from the dropdown) -> Next -> (Sync enabled checked) -> Done. Now the application will detect the changes in your target folder which is “…/modet”, upload the files on the destination folder (on your Google Drive), and delete uploaded videos from the target folder. We make it delete because we don’t want our phone to run out of memory. Lets move on, from the landing menu; “Upload File Size Limit -> No Limit”, “Enable Autosync : checked”, “Autosync Interval : 5 mins” , “Retry Delay : 2 mins” , “Instant Upload : checked” , “Monitor Service in Foreground : checked” , “Power Source : AC/USB/Battery” , “Sync Only If Battery Level : >0% (until battery dies)” , “Internet Connection : Wifi only” , “Notify When Syncing : checked” , “Notify about changes : checked” , “Notify About Sync Errors : checked” , “Max Sync History Age : 7 days”. And finally, Google account should be linked.
If you have done everything correctly, you now should have the exact setup that works as I explained in the “what you will achieve” part. Just start your camera from the IP Webcam Pro app and magic will happen. I hope everything works fine for you and I hope I didn’t skip a step. Mail me if you have any problems while setting up, you can reach me out at oguzgelal.com.
Enjoy your new smart security cam ☺