teslausb

repository·main-dev·Indexed 25 days ago

https://github.com/marcone/teslausb

A project that enables Single Board Computers, such as Raspberry Pi, to emulate a USB drive for Tesla vehicles. It provides advanced dashcam management including automatic cloud archiving, filesystem repair, a web interface for viewing footage, and support for multiple notification services like Pushover, Gotify, Telegram, and Discord.

Tokens
5.2K
Snippets
18
Records
27
Agent score
80%

What's inside teslausb

  1. Overview of teslausb

    main-dev

    teslausb allows a Raspberry Pi or other Single Board Computer (SBC) to emulate a USB drive for a Tesla. This enables the car to write dashcam footage to the SBC, which can then perform several automated tasks:

    • Automatic Archiving: Copies recordings to an archive server when the vehicle returns to a known wireless network.
    • Multi-purpose Storage: Can hold both dashcam recordings and music files simultaneously.
    • Filesystem Repair: Automatically repairs filesystem corruption caused by the Tesla's power-cutting behavior.
    • Web UI: Serves a web interface to view or download recordings.
    • Extended History: Retains more than one hour of RecentClips (depending on storage capacity).
  2. Monitor LED flash stages during setup

    main-dev

    During the One-step setup, the Raspberry Pi LED flashes specific patterns to indicate the current stage of the installation process:

    Stage (flashes)Activity
    2Verify the requested configuration is creatable
    3Grab scripts to start/continue setup
    4Create partition and files to store camera clips/music
    5Setup completed; remounting filesystems as read-only and rebooting

    After the final stage and reboot, the LED will pulse steadily once the archive loop is running.

  3. Configure `teslausb_setup_variables.conf` with correct quoting

    main-dev

    When creating the teslausb_setup_variables.conf file in the boot directory, you must follow bash quoting rules for sensitive values like WiFi SSIDs and passwords. Special characters like &, /, and \ must be escaped with a backslash \.

    Quoting Patterns

    • Standard Password: If the password has no single quotes, wrap it in single quotes: export WIFIPASS='password'

    • Password with Single Quote: Use the $'...' syntax and escape the quote: export WIFIPASS=$'pass\'word'

    • Password with Single Quote and Backslash: Escape both: export WIFIPASS=$'pass\'wo\\rd'

    • SSID with Spaces: Use quotes or escape spaces: export SSID='Foo Bar 2.4 GHz' export SSID=Foo\ Bar\ 2.4\ GHz

    export WIFIPASS='password'
    export WIFIPASS=$'pass\'word'
    export WIFIPASS=$'pass\'wo\\rd'
    export SSID='Foo Bar 2.4 GHz'
  4. Configure and verify rclone remote storage

    main-dev

    If you need a detailed manual setup, follow these steps within a single sudo -i session:

    1. Install rclone

    curl https://rclone.org/install.sh | sudo bash

    2. Configure the remote

    Run rclone config and follow the interactive prompts.

    • Google Drive Users: It is recommended to use the drive.file scope. Refer to rclone Google Drive docs for details.
    • Naming: Note the name you give your configuration (e.g., gdrive).

    3. Verify and create the directory

    Replace gdrive and TeslaCam with your actual configuration name and desired folder name:

    # Verify the remote name exists
    rclone listremotes
    
    # Set the drive variable
    export RCLONE_DRIVE="gdrive"
    
    # Verify the drive is accessible (should not list files if scope is correct)
    rclone lsd "$RCLONE_DRIVE":
    
    # Set the path variable and create the folder
    export RCLONE_PATH="TeslaCam"
    rclone mkdir "$RCLONE_DRIVE:$RCLONE_PATH"
    
    # Confirm the directory exists
    rclone lsd "$RCLONE_DRIVE":

    4. Enable rclone in teslausb

    To ensure the setup scripts use rclone, export the following variable in your current session:

    export ARCHIVE_SYSTEM=rclone

    Then proceed to the Main Instructions.

    rclone config
    rclone listremotes
    export RCLONE_DRIVE="gdrive"
    rclone lsd "$RCLONE_DRIVE":
    export RCLONE_PATH="TeslaCam"
    rclone mkdir "$RCLONE_DRIVE:$RCLONE_PATH"
    export ARCHIVE_SYSTEM=rclone
  5. Host the archive on Windows File Shares, MacOS Sharing, or Samba on Linux

    main-dev

    You can host the Tesla USB archive on a computer on your home network using a network share (CIFS/Samba). This allows the Raspberry Pi to write archive data to a remote server instead of local storage.

    Prerequisites

    1. Create a Share: Set up a share on your server (e.g., Windows, MacOS, or Linux/Samba).
    2. Create a User: It is recommended to create a dedicated user for the Pi with read/write access to the share.
    3. Network Connectivity: Ensure the Pi can reach the server. You should be able to ping the server by name or by its IP address.

    Configuration Steps

    1. Enter a root session on the Pi:
      sudo -i
    2. Verify connectivity by pinging the server name or IP address:
      ping -c 3 nautilus
      # OR if name resolution fails, use the IP:
      ping 192.168.0.41
    3. Set the following environment variables in your root session to configure the archive location:
    VariableDescription
    ARCHIVE_SYSTEMSet to cifs for network shares.
    ARCHIVE_SERVERThe hostname or IP address of your archive server.
    SHARE_NAMEThe name of the shared folder on the server.
    SHARE_USERThe username created for the share.
    SHARE_PASSWORDThe password for the share user.

    After setting these variables, proceed to the USB storage functionality setup in the main documentation.

    export ARCHIVE_SYSTEM="cifs"
    export ARCHIVE_SERVER="Nautilus"
    export SHARE_NAME="SailfishCam"
    export SHARE_USER="sailfish"
    export SHARE_PASSWORD="pa$$w0rd"
  6. Authenticate the TeslaUSB device with a remote rsync server

    main-dev

    To use rsync for archiving TeslaCam footage, the TeslaUSB device must be able to connect to your remote server via SSH without a password. This is achieved by generating an SSH keypair for the root user on the TeslaUSB device and copying the public key to the remote server's ~/.ssh/authorized_keys file.

    Follow these steps on the TeslaUSB device:

    1. Enter the root session: sudo -i
    2. Remount the file system as read-write: bin/remountfs_rw
    3. Generate the SSH key: ssh-keygen
    4. Copy the key to your storage server: ssh-copy-id user@archiveserver (replace user@archiveserver with your actual server credentials).
    sudo -i
    bin/remountfs_rw
    ssh-keygen
    ssh-copy-id user@archiveserver
  7. Perform a One-step setup for teslausb

    main-dev

    The One-step setup is a streamlined process for setting up a Raspberry Pi using a preconfigured Raspbian Buster Lite image. This method works for both headless and manual setups, assuming the Pi has internet access via WiFi during setup.

    Setup Steps

    1. Flash the Image: Use Raspberry Pi Imager to flash the latest image release. In the Imager, select 'Use custom' under the 'Operating System' menu.
    2. Configure Variables: Mount the SD card and create a file named teslausb_setup_variables.conf in the boot directory. This file exports environment variables for WiFi, archive methods, and push notifications. A sample file is available in the boot folder on the card.
    3. Boot the Pi: Insert the card into the Pi and power it on. Monitor the LED flash patterns to track progress.
    4. Verify Completion: Once the LED pulses steadily, the archive loop is running. You can verify success by checking for the existence of /teslausb/TESLAUSB_SETUP_FINISHED and /teslausb/WIFI_ENABLED files.

    Accessing the Pi

    After setup (approx. 5 minutes), you can SSH into the Pi at pi@teslausb.local using the default password raspberry via WiFi or USB networking.

  8. Configure Telegram notifications

    main-dev

    To use Telegram, you need a TELEGRAM_CHAT_ID (obtained by messaging @userinfobot) and a TELEGRAM_BOT_TOKEN (created via BotFather). If your API key does not have the bot prefix, ensure you include it manually.

    export TELEGRAM_ENABLED=true
    export TELEGRAM_CHAT_ID=123456789
    export TELEGRAM_BOT_TOKEN=bot123456789:abcdefghijklmnopqrstuvqxyz987654321
    export TELEGRAM_SILENT_NOTIFY=false
  9. Easy rclone setup for teslausb

    main-dev

    The recommended way to configure rclone archiving is to first complete the one-step setup process using the none archive method instead of cifs. Once the Raspberry Pi is functional, follow these steps to enable rclone:

    1. SSH into the Pi and become root with read-write access:
      sudo -i
      /root/bin/remountfs_rw
    2. Install rclone:
      curl https://rclone.org/install.sh | sudo bash
    3. Configure your remote service using rclone config and follow the official rclone.org instructions.
    4. Edit /root/teslausb_setup_variables.conf to change the archive method to rclone.
    5. Add the following variables to the config file:
      • RCLONE_DRIVE: The name of the remote shown by rclone listremotes.
      • RCLONE_PATH: The path on the remote (verify with rclone ls "$RCLONE_DRIVE:$RCLONE_PATH").
      • RCLONE_FLAGS (optional): An array of flags to add to the command, e.g., RCLONE_FLAGS=(--checksum).
    6. Run the setup script to apply changes:
      /root/bin/setup-teslausb
    sudo -i
    /root/bin/remountfs_rw
    curl https://rclone.org/install.sh | sudo bash
    rclone config
    # Edit /root/teslausb_setup_variables.conf
    /root/bin/setup-teslausb