Skip to content

Instantly share code, notes, and snippets.

@awlx

awlx/bmw-pi.md Secret

Last active January 13, 2024 13:32
Show Gist options
  • Save awlx/085e016c8f27b12768b4296976217fe1 to your computer and use it in GitHub Desktop.
Save awlx/085e016c8f27b12768b4296976217fe1 to your computer and use it in GitHub Desktop.

Manual to expose videos from a Raspberry PI to DriveOS 8.5 BMWs

This comes with absolutely 0 warranty if you brick your car with it it's your own fault. The scripts are neither safe nor protect you from any goofiness, it's a hacking project ;).

mkdir -p /opt/metube/downloads
mkdir -p /mnt/usb_share
mkfifo /opt/metube/downloads/containerpipe
dd if=/dev/zero of=/usb-drive.img bs=1M count=16048
mkdosfs -F 32 /usb-drive.img
apt install docker-compose -y

Add the following to /boot/config.txt (place it somewhere between the other dtoverlay lines)

dtoverlay=dwc2

Add the following to /boot/cmdline.txt after rootwait

modules-load=dwc2

Paste the following contents in /opt/metube/downloads/mv.sh also chmod +x /opt/metube/downloads/mv.sh

#!/bin/bash

/usr/sbin/modprobe -r g_mass_storage
mount /usb-drive.img /mnt/usb_share
count=`ls -1 /mnt/usb_share/ | wc -l`
if [ $count -ge 8 ]; then
   cd /mnt/usb_share && ls -A1t | tail -n +9 | xargs rm
fi
for i in /opt/metube/downloads/*.mp4; do
        file=`echo $i | sed 's#/opt/metube/downloads/##g' | tr -cd '.A-Za-z0-9_-'`
        mv "$i" "/mnt/usb_share/${file//[^[:alnum:]_-]/}.mp3"
        touch "/mnt/usb_share/${file//[^[:alnum:]_-]/}.mp3"
done
sync
umount /mnt/usb_share
/usr/sbin/modprobe g_mass_storage file=/usb-drive.img stall=0 removable=1

Paste the following contents in /root/waitforever.sh also chmod +x /root/waitforever.sh

#!/bin/bash
/usr/sbin/modprobe g_mass_storage file=/usb-drive.img stall=0 removable=1
while true; do
eval "$(cat /opt/metube/downloads/containerpipe)"
done

Add a cronjob for @reboot

@reboot /root/waitforever.sh

Create a docker-compose.yaml

version: "3"
services:
  metube:
    image: ghcr.io/alexta69/metube
    container_name: metube
    restart: unless-stopped
    ports:
      - "80:8081"
    environment:
      - 'YTDL_OPTIONS={"merge_format": "mp4","postprocessors":[{"key":"Exec","exec_cmd":"echo /opt/metube/downloads/mv.sh > /downloads/containerpipe","when":"after_move"}]}'
    volumes:
      - /opt/metube/downloads:/downloads

Run docker-compose up -d. Verify the webpage loads and reboot the PI for full effect.

Add your Raspberry PI to the WiFi of your BMW by running raspi-config.

In the BMW hotspot navigate to http://video.local and copy&paste your video links. Make sure you select "mp4" as output format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment