I have read "installing octoprint on a smartphone" on reddit and decided to do it. Here is my documentation about how to install Octoprint on an Android-Phone (Galaxy S3)
For any rom, if you want to connect it to Ender 3, you need "ch341" driver added/activated in the kernel or you need a custom implementation of it (look for octo4a program). You could understand it by connecting the phone with a USB OTG cable to your printer and execute command "ls /dev | grep tty". If there is "ttyusb" or "ttyacm" , it means that kernel has the driver. If kernel does not have the driver you have two options:
- You need to compile a kernel with driver support. Also keep in mind that kernel needs to support "loopback" functionality to host a virtual linux system and accept/direct connections to that virtual linux over its loopback.
- You can install octo4a, which installs custom a ch34x driver. and you need to mount the serial pipe of the octo4a (you can check that part from: https://github.com/d4rk50ul1/klipper-on-android)
- Terminal Emulator (you need to give root priviliges)
Installing Ubuntu - "Linux Deploy"
Before installing Ubuntu, be sure to have the serial drivers installed (kernel) on the phone, otherwise you will waste too much time.
Newest Ubuntu that i succeded to install is Debian Jessie, since it depends on the Android kernel version of the phone itself.
3. Open LinuxDeploy and go to settings and check
- Lock-wifi
- Wake lock
- Auto-start
- Track network changes
- Track power changes
- Auto-start delay : 60 seconds is enough
- Debug : Useful to understand if something goes wrong (like kernel version is old etc.)
Go to properties menu and and configure below:
- Distribution: debian jessie
- Architecture: armhf
- Username: pi (octoprint scripts are for raspberry-pi installation, pi user will make our job easier)
- Password: your-password
- Installation type: file (default)
- Installation path: $(EXTERNAL_STORAGE)/linux.img (default)
- Image Size: 4000 MB
- enable ssh
- Init: enabled
- Mounts: enabled
- Mount points: source: /sdcard target: /sdcard
Start installation
To eliminate local network problems, first try to connect to linux over the phone itself. ssh to "localhost"
Change root password with command "sudo passwd root"
Installing Python & Octoprint
Octoprint needs Python 2.7.9 or newer (Debian Jessie 2.7.9 could be installad). If you have a phone with a newer kernel you could install a later version of Ubuntu/debian and you won't need to upgrade system or venv python.) It is better to install latest python version in a virtual-environment and install octoprint in the same venv.(future octoprint version or klipper might need newer python version)
1.Change user shell from sh to bash, and close and restart your ssh session.
sudo usermod --shell /bin/bash pi
2. Upgrade ubuntu and install prerequisites
sudo apt-get update sudo apt-get upgrade sudo apt-get install build-essential checkinstall -y sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev -y sudo apt-get install python-pip python-dev python-setuptools python-virtualenv -y
3. Install python 2.7.17 in virtual-environment
Above packages are needed not to face problems later on (python could be make-install without libz2 etc. but then you might face problems like missing modules....)
sudo apt-get install wget -y wget https://www.python.org/ftp/python/2.7.17/Python-2.7.17.tgz tar xfz Python-2.7.17.tgz cd Python-2.7.17 sudo ./configure --prefix /usr/local/lib/python2.7.17 --enable-ipv6 sudo make sudo make install
*if you add --enable-optimizations to line ./configure it will add around 30-40 minutes to compiliation but will result in faster python processing. (for galaxy s3 test result was failure)
4. Check python installation
cd /usr/local/lib/python2.7.17/bin/ ./python --version
5. Upgrade PIP (also for virtualenv)
sudo pip install wheel sudo pip install --upgrade "pip < 21.0" virtualenv virtualenvwrapper --ignore-inst
6.Create and enter into virtual env
cd /home/pi mkdir venvs cd venvs/ virtualenv --python=/usr/local/lib/python2.7.17/bin/python octoprint source /home/pi/venvs/octoprint/bin/activate
7.Check python and pip version inside virtualenv (python 2.7.17, pip 20.x)
python --versionpip install --upgrade "pip < 21.0"
pip install --upgrade setuptools
pip --version
8. Install octoprint (inside venv)
pip install wheel pip install octoprint
8. Start octoprint
/home/pi/venvs/python2717/bin/octoprint serve
Start Octoprint On Debian Boot Automatically
Download necessary script files:
wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.init && sudo mv octoprint.init /etc/init.d/octoprint
wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.default && sudo mv octoprint.default /etc/default/octoprint
sudo chmod +x /etc/init.d/octoprint sudo systemctl octoprint enable
Change the daemon path in "/etc/default/octoprint" file with vi/nano (whatever text editor is your favorite) to:
sudo nano
DAEMON=/home/pi/venvs/octoprint/bin/octoprint
Screen Off - Sleep Problems
For an always on Linux installation on Android, some battery and cpu optimization settings need to be changed otherwise Linux becomes unreachable when screen is of after a while:
1. Change wifi settings to "keep wifi always on"
2. Install Wake-Lock: Select "Screen_DIM_wake_lock" option for phone not to (deep)sleep when the screen is off.
3. Change Battery Settings: Disable optimization for LinuxDeploy and WakeLock application.
4. Change minimum cpu frequency: 100Mhz minimum frequency is too low, i changed it to 400Mhz. You could use SmartPack-Kernel Manager or KernelAuditor.
Astroprint plugin
First install missing packages:
sudo apt-get install libjpeg-dev
Then you could install it Astroprint plugin from octoprint web page.
Restarting Phone Over Octoprint Webpage
Somekev explained it really well in his website, Here it is: https://somekev.com/2019/04/10/adapting-an-s6-for-octoprint/
Temporary Files
If temporary files uses too much space, at the end your 4gb image could fill and octorint might stop working. Keep an eye on the octoprint main page, under upload file menu you could see the.
Logfiles of octoprint are located at "/home/pi/.octoprint/logs". Linux temp files are under "/tmp".
Problems
If i restart my phone, after Linux deploy started, i need to unplug and plug the microusb on phone side, then usb is recognized.
4 comments:
Hello,
Thanks for tutorial.
Have you configure android camera in octoprint ?
And how do you do ?
Hello Nibeck,
No i did not configure android camera, you might use any camera application within Android but i read that it is not stable for long time usages. Using phone camera over linux is totaly different issue and to be honest i do not know if it is even possible.
Hello, thank you for this useful tutorial. More people should know that our old phones can become fully fledged octoprint server.
You should specify that you need to specify sysv and not sys-parts as the startup manager to get the octoprint service running.
Post a Comment