# Termux Photoserver Setup Guide A Node.js photo server running on Android via Termux that provides camera capture and gallery browsing via HTTP endpoints. ## Prerequisites ### Required Apps (all from F-Droid) 1. **Termux** - Terminal emulator for Android 2. **Termux:API** - Provides access to Android device features (camera, sensors, etc.) 3. **Termux:Boot** - Enables running scripts at device boot (optional, for auto-start) > **Important:** All Termux apps must come from the same source (F-Droid recommended). Do not mix Play Store and F-Droid versions. ### Required Packages ```bash pkg install termux-api termux-services nodejs exiftool ``` > **Note:** `exiftool` is required for GPS geotagging of photos. ### Permissions - Grant **Camera** permission to the Termux:API app - Grant **Location** permission to the Termux:API app (for GPS geotagging) - Android Settings → Apps → Termux:API → Permissions → Camera → Allow - Android Settings → Apps → Termux:API → Permissions → Location → Allow all the time ## Photoserver Location ``` ~/storage/shared/sites/geo.camera/apps/photoserver.js ``` ## API Endpoints ### Capture Photo (saves to gallery) ``` GET /api/capture?camera=back|front&geo=true|false ``` Parameters: - `camera` - `back` (default) or `front` - `geo` - `true` (default) or `false` - whether to add GPS EXIF data Returns JSON: ```json {"success": true, "filename": "IMG_1234567890.jpg", "location": {...}, "geoTagged": true} ``` ### Capture and Return Image (no save) ``` GET /api/capture-image?camera=back|front&geo=true|false ``` Returns the JPEG image directly in the response. The image is cached for the `/api/last-image` endpoint. Temp file is automatically deleted after sending. ### Get Last Captured Image (fast, no capture) ``` GET /api/last-image?camera=back|front ``` Returns the most recently captured image for the specified camera instantly from memory cache. No new capture is performed. - Returns `404` if no image has been captured yet for that camera - Cache is per-camera (back and front are stored separately) - Cache resets when the server restarts ### List Photos (paginated) ``` GET /api/photos?page=0 ``` Returns JSON with photo metadata. ### View Photo ``` GET /photo/{filename} GET /thumb/{filename} ``` ### Web Interface - `http://localhost:8080/` - Landing page with capture buttons - `http://localhost:8080/gallery` - Photo gallery browser ## Running as a Background Service ### 1. Create the Service Directory ```bash mkdir -p $PREFIX/var/service/photoserver ``` ### 2. Create the Run Script Create `$PREFIX/var/service/photoserver/run`: ```bash #!/data/data/com.termux/files/usr/bin/sh exec node /data/data/com.termux/files/home/storage/shared/sites/geo.camera/apps/photoserver.js 2>&1 ``` ### 3. Make it Executable ```bash chmod +x $PREFIX/var/service/photoserver/run ``` ### 4. Enable the Service ```bash sv-enable photoserver ``` ### Service Management Commands | Command | Description | |---------|-------------| | `sv status photoserver` | Check if running | | `sv restart photoserver` | Restart the service | | `sv stop photoserver` | Stop the service | | `sv-enable photoserver` | Enable the service | | `sv-disable photoserver` | Disable the service | ## Auto-Start on Boot ### 1. Install Termux:Boot Download from F-Droid and open it once to initialize. ### 2. Create Boot Script Create `~/.termux/boot/start-services`: ```bash #!/data/data/com.termux/files/usr/bin/sh termux-wake-lock . $PREFIX/etc/profile sv-enable photoserver ``` ### 3. Make it Executable ```bash chmod +x ~/.termux/boot/start-services ``` The photoserver will now start automatically when the device boots. ## Troubleshooting ### "termux-camera-photo: not found" Install the termux-api package and Termux:API app: ```bash pkg install termux-api ``` Then install Termux:API from F-Droid. ### Empty/0-byte images Grant camera permission to Termux:API app in Android settings. ### "EADDRINUSE: address already in use" The server is already running. Kill existing process: ```bash pkill -f photoserver.js ``` ### Check camera availability ```bash termux-camera-info ``` ## Testing Test capture directly from command line: ```bash termux-camera-photo -c 0 ~/storage/dcim/Camera/test.jpg ls -la ~/storage/dcim/Camera/test.jpg ``` Camera IDs: - `0` - Back camera - `1` - Front camera ### Test API with GPS verification ```bash # Capture via API and verify GPS EXIF data curl -s "http://localhost:8080/api/capture-image?camera=back" -o ~/test.jpg exiftool -GPS* ~/test.jpg ``` ### Test last-image caching ```bash # First capture (slow - takes photo) time curl -s "http://localhost:8080/api/capture-image?camera=back" -o /dev/null # Subsequent fetch (fast - from cache) time curl -s "http://localhost:8080/api/last-image?camera=back" -o /dev/null ``` ### Verify location service ```bash termux-location -p network ```