Skip to content

Using an Android phone as a webcam

Blankboot10 edited this page Jul 28, 2019 · 26 revisions

Prerequisites

  • 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.

Android setup

Getting a Static IP

  1. For most phones, go to Settings > Wifi > Long hold [YOURSSID] > Advanced options > IP settings > Static

Setup

  1. Connect your android phone to a wireless network and a charger.
  2. Install IP webcam.
  3. [Optional] Under Power management, enable "Deactivate display" which will turn of the phones display when you aren't connected.
  4. [Optional] Under MISC, disable Audio mode.
  5. [Optional] Under MISC, enable Stream on device boot.
  6. [Optional] Under Video Preferences, change the Main camera and Secondary camera depending on the which camera will be facing you printer.
  7. Select Start Server at the bottom of the screen.

Getting your IP

  1. Select How do I connect? On the top left.
  2. Select Connect Directly.
  3. Select I'm Using a Wifi Router.
  4. Write down/remember the IP address. You will need this later.

OctoPrint setup

  1. Go to your OctoPrint Server.
  2. Open Settings.
  3. Select Webcam & Timelapse on the left hand side
  4. Next to Stream URL, enter http://[androidPhoneIP]:8080/video replacing androidPhoneIP from the IP you got earlier.
  5. Next to Snapshot URL, enter http://[androidPhoneIP]:8080/shot.jpg replacing 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.jpg instead. You can also use http://[androidPhoneIP]:8080/photoaf.jpg - this would focus the camera before taking a photo.
  6. 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

http://codetheory.in/android-debug-bridge-adb-wireless-debugging-over-wi-fi/

  1. Connect your phone using a usb cable to your main computer / laptop
  2. In a terminal window: adb devices 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.

Other

Tested Devices

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
Clone this wiki locally
You can’t perform that action at this time.