Tuesday, April 16, 2024

Portable Car Media Server

***

This is a work in progress post, it has most of the content of what I did, but it's after the fact, and I haven't replicated it to ensure it works exactly as described, but you should have enough info to accomplish what I did!

***

 

(Note I have Amazon Affiliate links below FYI)

I decided to build a portable Jellyfin Server. I wanted my kids to be able to login and watch shows as needed while we were driving and thus started going down the path.

I bought a travel router from amazon. I came across this on HackerNews a while back, and liked the idea, which is where this all started.

We used it on our last road trip and it worked quite well.

Parts required (I used stuff I had around, so the links below are largely placeholders for you to try, with the exception of the travel router and power bank, I did buy those).

1 Usb-A to Usb-micro cable

1 Usb-A to Usb-c cable

1 Power Bank

1 Raspberry Pi (I selected 3b+ as it's what I had lying around)

1 SD Card (If you already have a pi up and running, you may not need this)

1 GL-MT3000 (Beryl AX) Pocket-Sized Wi-Fi 6 Wireless Travel Gigabit Router

1 Storage usb drive

1 Shutdown Key (Or just find a spare usb device you can bring along)

1 Storage Case (Totally optional)

Key Stages:

  1. Get Pi Setup and running (Assumed you have set this up)
  2. Get Jellyfin installed on Pi
  3. Setup USB Drive for media
  4. Get nginx installed on Pi
  5. Static IP on Travel Router
  6. Get Adblocker running on Travel Router with Redirect
  7. Get USB Shutdown Key Created


Installing Jellyfin

https://pimylifeup.com/raspberry-pi-jellyfin/

Ultimately I just searched install jellyfin on raspberry pi and it just worked.

Setup USB Drive for media

TODO: More details on how I setup with the USB drive.

Installing nginx

https://engineerworkshop.com/blog/setup-an-nginx-reverse-proxy-on-a-raspberry-pi-or-any-other-debian-os/

Ultimately we will follow the above however there are some details that are a bit fuzzy for me. It has you edit this

sudo nano example.com.conf

file, however my system wasn't setup like that,  so instead of that I used default (likely this command):

ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

From there we need to update:

sudo nano /etc/nginx/sites-available/default

to contain this:

server {
	listen 80;
	server_name jellyfin.car.com;
	location / {
	proxy_pass http://localhost:8096;
	}
}

This means that we will redirect a request coming in for jellyfin.car.com to the jellyfin server. You can replace jellyfin.car.com with whatever you want, but that's what I used.

I specifically used localhost, because when I was doing setup, I was on my main wifi, so when I swapped between wifi's as long as I had the request coming in via jellyfin.car.com (on my main or the travel wifi) it handled correctly.

Static IP

https://docs.gl-inet.com/router/en/3/setup/gl-e750/more_settings/#static-ip-address-binding

This should generally be what you need to do. Figure out your mac address, and then put in a static IP there. I think the default IP range is 192.168.8.x so I set my pi to something like 192.168.8.31.

Get Adblocker running on Travel Router with Redirect

https://medium.com/@life-is-short-so-enjoy-it/homelab-adding-local-dns-entry-into-adguard-home-arpa-and-pushing-to-clients-from-udm-se-8493253830e5

Next we are going to turn on the adguard (A sweet feature of the travel router), and point the redirect to our pi!

Specifically we are going to do the section called add local DNS entries into Adguard.

I put in 

192.168.8.31 jellyfin.car.com

(instead of their arpa example)

Now when I visit jellyfin.car.com on the wifi that router is on, the adguard will look that URL up, and then return the pi's ip address, which in turn, means that it will connect over NGINX on port 8096

 

Get USB Shutdown Key Created

http://blog.onaclovtech.com/2024/03/usb-shutdown-key.html

Finally, we will setup a USB shutdown key, this makes it so when we are ready to shutdown for the day we can kill our pi, and unplug power after maybe 30 seconds.

You can use any old usb device I have an old 32 mb usb key (my first perhaps?) that I am using, I labelled it Shutdown Key.


Results

 

Once you have this setup, you can kick it off, the system should last on the battery bank more or less 5-7 hours (maybe more, maybe less, depending on use).

Alternatively you can buy two banks, and then just run the router on one, and the pi on another. 

Finally you "could" possibly just run your router off the USB power in the car, so you don't need the power bank at all, however I didn't test that out, I think the router can handle power interruptions, the pi generally can get finnicky on that, so I wanted a way to be in control of that which is why it's on a power bank, so if I shut the car off I don't accidentally forget to gracefully power the pi off, and kill it in the middle of my trip.


***

This is a work in progress post, it has most of the content of what I did, but it's after the fact, and I haven't replicated it to ensure it works exactly as described, but you should have enough info to accomplish what I did!

***


Friday, March 22, 2024

USB Shutdown Key

While building up a raspberry pi system recently I needed an easy way to shutdown the device without having to ssh into it.

I had an idea pop into my head, what if I plug in a usb drive and maybe it automatically runs a script on the usb key, or something and powers the device down.

Well after a bit of googling it turns out.... you can use udev rules to do what I want, and no need to put anything on my drive.

This is the process.

First, you figure out the vendor ID and the product ID of the usb key. 

The way I did this was by running lsusb and noting the devices, since this is a raspberry pi, the list was short.

I then plugged the usb drive in, and ran lsusb again. I noted which device it was.

Then I ran lsusb -v to get the values for idVendor and idProduct. 

I then copied them into this line (remember not to include the 0x), in the applicable spots. 

ACTION=="add" , ATTRS{idProduct}=="2168" , ATTRS{idVendor}=="0ea0" , RUN+="/usr/local/bin/my_shutdown_script.sh"

I then placed that line into this file:

sudo nano /etc/udev/rules.d/99-usb-shutdown.rules

Next, I edited /usr/local/bin/my_shutdown_script.sh to contain the following:

#!/bin/sh sudo shutdown -h now 

Finally I ran 

sudo chmod +x /usr/local/bin/my_shutdown_script.sh

on the file and rebooted, just to make sure everything was stable.

Now when I plug in the usb drive, bam, it just shuts down.

Thanks to this post for the details they used, which was exactly what I did with the minor note that I used lsusb -v (they just mentioned using lsusb ;))! 

https://www.reddit.com/r/linuxquestions/comments/yiw13c/trying_to_create_a_udev_event_to_safely_shutdown/