Building a low-powered offline & offgrid bug-out media server
I’ve been looking for a new project, particularly one that will use some parts I’ve had laying around for a long time. In particular, I desperately want to find uses for the old Raspberry Pi boards I have collecting dust.
This project is to use my ancient Pi Zero as a super low power bugout media and file server. This is inspired by jcorp-nomad project that uses an ESP32 board for a ultra tiny, low-power, portable media server.
My build has has:
- 12 movies
- 1 Season of a tv show
- 35 YouTube vidoes for the kids
- 3 music playlists
- A small collection of HTML & classic Flash games
- 2 full length wrestling live events
This setup broadcasts a wifi network and makes all the movies, music, YouTube videos, and games availabe at http://IP_ADDR:3939 and a mini Wikipedia at http://IP_ADDR:8080.
Monitoring energy use once the build was complete, I rarely saw it go above 1.5-watts of electricy consumption, even with two web servers and a wifi dongle.
Purpose
Primarily, this is a bordem-solver build, not a compete offgrid situation. The goal is to provide a distraction in an offline or power outage situation that can spin something up very fast without a lot of setup. My internet-in-a-box takes 20-30 min. to get setup. I’d like to have something that just plug in and go. The other goal is to use very, very little power. I want it to be able to run off of essentially any powered USB port. Doing this means it can run while I drive, from a battery pack, or even one of those solar phone chargers.
Examples
Example scenario 1: We take it with us camping. This gives the gorls something to watch for an hour or two during the day, stories at bedtime, and a few movies for the adults to watch. We camp for 1-3 days.
Example scenario 2: A power outage at the house during a big winter storm. Running from solar is not an option, therefore setting up the internet-in-a-box can’t charge enough to keep running. This build will use such little power it can run from the power bank for 3 days or more.
Example scenario 3: A backup setup in the portable IIAB kit. Fills in for downtime from the existing offgrid build.
What did I learn
These kinds of builds can often feel like a waste of time because when am I ever going to be in any of these scenarios. Plus, I can easily put all this content onto everyone’s devices individually (another project I am already working on) and don’t need something to create a hotspot and spin up servers.
However, I always end up learning something while doing any project. This is why I love doing them. I learn something. Then I can apply it to many other projects or builds or just have learned something new.
Here’s what I learned during this project:
- DietPi is awesome. I am going to use this more often when doing Pi projects, especially since I am typically using older devices. It gives you just the minimum to get started and keeps old devices feeling usable. It is based on Debian, so I can install anything I want from
aptas I have done for other Pi projects. But, it also has an awesome TUI interface for installing whole kits of software by simply runningdietpi-software. - To re-encode videos I have been putting them into Handbrake with some custom settings. This is a slow and bloated process. It can take an hour or more per video for the conversion. During this project I learned how to use
ffmpegto just reduce the resolution of the videos to 360p and achieve my goal. Notes below on that. - I solved the wifi firmware issue with these old Ralink USB wifi adapters. Now I have what I need to use them in other projects.
- The Pi Zero v1 can handle 2 SD video streams and serve Kiwix with no problems.
The basics
- ✅ Creates a wifi hotspot
- ❌ Navigate to file/media server with easy to remember URL (probably something like
files.local) - ✅ Stream media to mobile devices
- ✅ A file manager that allows upload/downloads
- ✅ Run from USB power which means it can get power from any device, like a phone that does reverse charging, a device USB port, or a car 12v USB adapter.
- ✅ Run all day from one of my existing power banks
- ✅ Run from a portable solar panel
Extended:
- ✅ Whatever SD card I end up using, cram as much as possible onto it. Take all videos down to 360p.
- ✅ Needs to have Ryan & Craig for bedtime, Sqaishey for lunch, and a few long-form no commentary “simulator” game streams for distraction downtime for the kids as these are normal watches for them.
- ✅ Premium wresting events. We typically watch a couple a week.
- ✅ Longplay video games for the kids to watch
Nice-to-have:
- ✅ Gams for offline basic gaming.
- ✅ Basic Wikipedia. Multiple people in the house will surf Wikipedia to pass the time.
Below are my technical notes during the build.
DietPi
Wifi dongle firmware
It took me FOREVER to figure this out. Essentiall, no Linux distributions come with the Ralink rt2870 firmware. This is a Ralink issue. You can see what device it is running lsubs. Its right there:
Bus 001 Device 005: ID 148f:3070 Ralink Technology, Corp. RT2870/RT3070 Wireless Adapter
To fix this issue I found an thread that had easy notes for getting the firmware.
One, download the deb from the Debian archives. I have saved this in Nextcloud under the Pi folder.
Two, extract the bin files from the deb with dpkg-deb -xv firmware-ralink_0.43_all.deb $HOME/tmp.
Three, copy all the bin files to /lib/firmware.
Four, reboot.
Setup AP
I am using this guide which I have also saved in the same Pi folder as the Ralink drivers.
Essentially you can set it up by using the dietpi-software TUI. You can find “Wifi Hotspot” under “Advanced Networking”. Then to change the SSID and password, use dietpi-config and go into “Network Options: Adapters” and choose the wifi device.
Video size reduction
When I am building these offline and offgrid iiab boxes, I am constantly trying to fit as much entertainment into a single storage device, while keeping power usage low. This means I want to reduce the video storage size as much as possibe so I can use things like SD cards for storage, which sip power.
Handbrake is too much tool for this job. I want to maintain all of the metadata, like thumbnail, description, and subtitles, while re-encoding the video to a lower resolution. I could change the compression, but all I want is to reduce the pixels which will reduce the storage size.
I found this post about using ffmpeg to simply reduce the resolution by scaling. This is the text from the post:
You mentioned wanting to reduce the file size to fit more videos on a mobile device, which is my use case as well. All the answers here are for reducing the compression quality, but nobody has mentioned reducing the video frame size. It’s a lot quicker, up to multiple times faster depending on your source, and the amount of the resolution decrease, as there are fewer pixels to be encoded. As a result, the file size can be reduced significantly.
The downside is you also lose a large amount of quality because fewer pixels means less image detail. But when converting for a small device this may be acceptable.
See the FFmpeg docs on scaling for more info.
To scale to half size:
ffmpeg -i input.mkv -vf "scale=trunc(iw/4)*2:trunc(ih/4)*2" half_the_frame_size.mkv
One-third size:
ffmpeg -i input.mkv -vf "scale=trunc(iw/6)*2:trunc(ih/6)*2" a_third_the_frame_size.mkv
One-quarter size:
ffmpeg -i input.mkv -vf "scale=trunc(iw/8)*2:trunc(ih/8)*2" a_fourth_the_frame_size.mkv
One-fifth size:
ffmpeg -i input.mkv -vf "scale=trunc(iw/10)*2:trunc(ih/10)*2" a_fifth_the_frame_size.mkv
In these examples, the size is divided by twice the value and multiplied by two to ensure the pixel size is a multiple of two, which is required for some codecs, including H265.
You can also scale to a specific size in one parameter and automatically keep the same ratio using
-2for the other. For example 360 pixels in one direction would use:
-vf "scale=-2:360"
Be aware that changing the resolution always requires re-encoding, so all the ins and outs of the other answers apply here as well, and these examples are compatible with H265 options like
-c:v libx265 -crf 28.
Copyparty
I had originally thought I was going to use dufs as the file server since it can play videos and render static pages. But, I decided to go with copyparty since it handles playing media better, while also having solid permission settings, render static pages, and run a single binary.
To install, I dropped the copyparty-sfx.py file into $HOME/copyparty along with the config file. This is my config:
[global]
p: 3939 # listen on port 3939
e2dsa # enable file indexing and filesystem scanning
# e2ts # and enable multimedia indexing
# z, qr # and zeroconf and qrcode (you can comma-separate arguments)
# create users:
[accounts]
dominic: [REDACTED] # username: password
# create volumes:
[/] # create a volume at "/" (the webroot), which will
$HOME/boredom_media # share the contents of "." (the current directory)
accs:
A: dominic # I get all permissions
[/games]
$HOME/boredom_media/games
accs:
r: *
[/longplays]
$HOME/boredom_media/longplays
accs:
r: *
[/movies]
$HOME/boredom_media/movies
accs:
r: *
[/music]
$HOME/boredom_media/music
accs:
r: *
[/reacher]
$HOME/boredom_media/reacher
accs:
r: *
[/ryan_craig]
$HOME/boredom_media/ryan_craig
accs:
r: *
[/sqaishey]
$HOME/boredom_media/sqaishey
accs:
r: *
[/wwe]
$HOME/boredom_media/wwe
accs:
r: *
[/community_uploads]
$HOME/boredom_media/uploads
accs:
rw: *
This config allows read-only access to all the directories except one where I allow anyone to upload. Doing this allows an easy way for people to share something they have on their device. Then I gave my user all the permissions so I can manage it.
Running
I created a script and then have it run with cron on boot. It starts copyparty in a screen session so I can pop in and check on it.
The script:
#! /bin/bash
screen -S copyparty -d -m bash -c 'python3 $HOME/copyparty/copyparty-sfx.py -c $HOME/copyparty/copyparty.conf'
Then cron
# Start Copyparty
@reboot sleep 60 && $HOME/scripts/copyparty_start
Kiwix
I’m not sure how useful this will be, but I know folks in my house will browse Wikipedia while just hanging out. The primary issue is I don’t have enough storage space for the full Wikipedia copy (106GB) or the smaller version with no pictures (45GB).
There is a “mini” version which only has the preamble for each page and this comes in at 13GB. I guess it is better than nothing?
Setup Kiwix
First, get the server and other utilities installed with sudo apt install kiwix-tools.
Next, transfer the mini WIkipedia to the SD card. I put it in $HOME/boredom_media/kiwix.
Running Kiwix
I’m doing this the same way I am running Copyparty by running a script that creates a screen session so I can monitor.
The script:
#! /bin/bash
screen -S kiwix -dm bash -c 'kiwix-serve -p 8080 $HOME/boredom_media/kiwix/*.zim'
And cron
# Start Kiwix
@reboot sleep 30 && $HOME/scripts/kiwix_start
- - - - -
Did you like this post? Give it an upvote by clicking on the arrows below! Sending me an upvote is like you and I giving each other a high five.
🙏 😎
Thank you for reading! If you would like to comment on this post you can start a conversation on the Fediverse. Message me on Mastodon at @cinimodev@masto.ctms.me. Or, you may email me at blog.discourse904@8alias.com. This is an intentionally masked email address that will be forwarded to the correct inbox.If you enjoy the random stuff I write here, post to Mastodon, or watch on YouTube, and are feeling generous, I am open to tips of Ko-fi.