Harnessing the Power of Your Smartwatch: Linux and Django on Wear OS
Written on
Chapter 1: Introduction to Smartwatch Computing
In today's rapidly advancing technological landscape, many might be surprised to learn that even a standard smartwatch can possess significant computational capabilities. In fact, the processing power found in many smartwatches exceeds that of the computers used by NASA during the Apollo missions, and it rivals some of the older professional laptops. This raises an intriguing question: can we utilize this power? The answer is a resounding yes! Engaging in unconventional projects can be both enjoyable and educational. In this article, I will guide you through the process of running Linux, Python, and a Django web server on an Android Wear smartwatch.
Section 1.1: Getting Started with Termux
To embark on this journey, we will rely on an application called Termux. This free tool provides a terminal and a complete Linux environment. Termux operates in a local 'sandbox' mode, eliminating the need for 'root' access and ensuring system safety. While you can find Termux on Google Play, it is not available for Wear OS directly, so we must install the APK manually via ADB (Android Debug Bridge). This command-line utility is designed for Android developers and will assist us in app installation and command execution.
Before we proceed, we need to enable ADB and Wi-Fi debugging on the smartwatch. The "ADB debugging" feature allows us to connect to the device, while "Debug over Wi-Fi" ensures that the smartwatch maintains its Wi-Fi connection even during periods of inactivity.
Now, let’s connect:
adb connect 10.14.24.123:5555
After confirming the connection on the smartwatch, we can verify the ADB link with:
adb devices
Next, we will download and install Termux onto the smartwatch:
adb -s 10.14.24.123:5555 install com.termux_118.apk
Once installed, you should see the Termux icon on the apps screen. Launching Termux will provide you with a Linux command prompt.
Section 1.2: Configuring the Environment
In the Termux application, it is advisable to access the context menu (by long-pressing) and select the "Keep screen on" option to maintain visibility. When you're finished, you can terminate ADB with the following command:
adb kill-server
Unfortunately, the on-screen keyboard on Android Wear is not ideal for entering bash commands. However, you can easily send keystrokes via ADB like this:
adb shell input text "'pkg upgrade'" && adb shell input keyevent 66
Here, "pkg upgrade" is the command you want to execute, and "66" corresponds to the Enter key. This method allows for command entry from a desktop, with results displayed on your smartwatch.
To begin, let's update the system:
pkg update
pkg upgrade
apt-get update
apt-get upgrade
If you encounter the prompt "Update this package [y/n]?", you can send "y" using:
adb shell input text "y" && adb shell input keyevent 66
Chapter 2: Remote Access with SSH
While using ADB can be enjoyable, it is less practical for extended tasks. Instead, standard SSH provides a more comfortable experience. We can install and set it up with the following commands:
pkg install termux-services openssh
passwd
sshd
In this context, "termux-services" and "openssh" are essential services, while the "passwd" command sets an SSH password, and "sshd" starts the SSH daemon in the background. To find your username, execute:
whoami
Once you have this information, you can close ADB:
adb kill-server
Now, you can SSH into your smartwatch from your desktop:
ssh [email protected] -p8022
The first video, How to run Django Web Framework on Mobile Phone | Python - YouTube, provides a detailed overview of running Django applications on mobile devices.
Chapter 3: Benchmarking Your Smartwatch
After successfully logging in via SSH, I became curious about the performance of the smartwatch compared to other computers. To gauge this, I ran a benchmark using 7Zip, which can be easily installed with:
pkg install p7zip
You can initiate the test with:
7z b -mmt1
The results were intriguing. The Galaxy Watch’s processor is roughly three times faster than the Intel Pentium II (from 1997) and performs similarly to the Intel Atom N270 (from 2008). This comparison illustrates that the smartwatch on your wrist is 2-3 times more powerful and has superior RAM and storage than many workstations from the late 2000s.
Chapter 4: Running Python and Django
With a fully operational Linux environment established, the final step is to run Python and set up a web server. We'll use Django, a modern framework for web application development.
First, we need to install the necessary packages:
pkg install python
pip3 install django tzdata
Now we can create a new Django project:
django-admin startproject hello_world
cd hello_world
Before launching the server, we must configure it by editing the settings file:
nano hello_world/settings.py
Set the ALLOWED_HOSTS parameter to accept all hosts:
ALLOWED_HOSTS = ['*',]
Finally, we can start the web server:
python3 manage.py runserver 0.0.0.0:8000
Now, you can access the server running on your smartwatch from your desktop.
The second video, Porting Python to a terrible $3 smartwatch - YouTube, explores the challenges and triumphs of running Python on less capable devices.
Conclusion
In this article, I demonstrated how to install a Linux environment on an Android Wear smartwatch, conduct a benchmark test, and run Python along with a Django server. While there may not be a practical reason to host a web server on a smartwatch, such endeavors can be both amusing and thought-provoking, akin to an Ig Nobel Prize. I enjoyed this experiment and hope readers found it enlightening and perhaps even learned something new.
Thank you for reading! If you enjoyed this article, consider subscribing to Medium for notifications on future publications and access to countless stories from other authors. For those interested in programming, feel free to explore my other articles.