Using an Android phone as a webcam
- Octoprint up and running on a device such as the Raspberry Pi.
- An old Android phone.
- WiFi/LAN for the Android phone.
- Constant power for the Android Phone.
Getting a Static IP
- For most phones, go to Settings > Wifi > Long hold [YOURSSID] > Advanced options > IP settings > Static
- Connect your android phone to a wireless network and a charger.
- Install IP webcam.
- [Optional] Under Power management, enable "Deactivate display" which will turn of the phones display when you aren't connected.
- [Optional] Under MISC, disable Audio mode.
- [Optional] Under MISC, enable Stream on device boot.
- [Optional] Under Video Preferences, change the Main camera and Secondary camera depending on the which camera will be facing you printer.
- Select Start Server at the bottom of the screen.
Getting your IP
- Select How do I connect? On the top left.
- Select Connect Directly.
- Select I'm Using a Wifi Router.
- Write down/remember the IP address. You will need this later.
- Go to your OctoPrint Server.
- Open Settings.
- Select Webcam & Timelapse on the left hand side
- Next to Stream URL, enter
http://[androidPhoneIP]:8080/videoreplacing androidPhoneIP from the IP you got earlier.
- Next to Snapshot URL, enter
http://[androidPhoneIP]:8080/shot.jpgreplacing androidPhoneIP from the IP you got earlier. If you get "Could not retrieve snapshot URL, please double check the URL" try
http://[androidPhoneIP]:8080/photo.jpginstead. You can also use
http://[androidPhoneIP]:8080/photoaf.jpg- this would focus the camera before taking a photo.
- Change the orientation/rotation to suite your needs.
Getting it to work outside your network
This is beyond the scope of this tutorial, but here is how you would go about doing it. You would buy a domain(I use Google domains) and set up a subdomain(such as webcam.yourdomain.com) and have it forward to a port, that you set up with your router to forward it to your android phone. This would then not work in your local network, so you would have to set up a DNS server to point it to where you want. You could use pi-hole, or a custom DNS server (you can look it up on google for guides) and then point it to your phone. The port for outside the network will have to be the same port you access it from inside the network to the device, because you can only have one URL.
Controlling the Camera using adb (Optional)
This section is optional - it allows you to switch on and off the camera using system commands. Keeps the phone cool and doesn't over-heat the camera for no reason.
Enable ADB over Wifi on your phone
- Connect your phone using a usb cable to your main computer / laptop
- In a terminal window:
adb tcpip 5556
adb connect [androidPhoneIP]Once this works - your phone would enable adb over IP. Unfortunately, this needs to be done every time the phone restarts. I have not been able to get adb over usb working on raspbian. If anyone knows - that may be an easier way.
Install ADB on Raspberry Pi
SSH into your octopi instance and run the following commands in terminal:
sudo apt-get update
sudo apt-get install -y android-tools-adb android-tools-fastboot
Controlling IP Webcam through Octoprint:
Got the following to work with help from Pavel Khlebovich (develope of IP Webcam). You can control the IP Webcam using the following commands (and these can be setup as a system menu item in octoprint):
Start IP Webcam:
adb connect [androidPhoneIP] && adb shell am start com.pas.webcam/com.pas.webcam.Rolling
Stop IP Webcam:
adb connect [androidPhoneIP] && adb shell am force-stop com.pas.webcam
You can also add these commands to the scripts section in Octolapse (dev release) so that the camera is switched on automatically before the timelapse starts and is switched off automatically after the timelapse ends.
Add yours if you do this and it works.
- Samsung Galaxy S4 - jakevossen5, kurtjacobson
- ZTE Speed - anoldguy
- HTC M7 - lfried-ndd
- SONY Xperia Z3 Compact (D5803) - magiske
- Samsung Galaxy S7 - magiske
- Samsung Galaxy Ace S5830 - antigreen
- Nexus 6 - mparka
- Samsung Galaxy A3 (old) - R0dri
- Ulefone Power - D-e-k-k-i-a
- Ulefone S8 - unixb0y
- HTC Desire C (With CyanogenMod 10) - D-e-k-k-i-a
- Motorola Droid MAXX 1 - axstepko
- Motorola MOTO G 4G 1st gen. - freerom
- Huawei P9/P9 Plus - Gremson
- Samsung Galaxy Tab A
- Xiaomi Redmi 4A - Sparticle
- Xiaomi Mi III
- OnePlus 6T
- Samsung Galaxy S7 Edge (3DIY Original)
- Samsung Galaxy Note 4 - kkoscielniak
- Sony Xperia L2