Using a Pi Zero to store and upload Sentry / Dash cam footage to Google Drive

Not the snappiest of titles, but it covers what we are trying to achieve! Some very smart people have worked out how to make your Tesla believe your Pi Zero W is a USB drive, this then uploads your saved clips and Sentry mode events to either a local NAS or Online service when you connect to WiFi.

This guide focuses on getting the sync to work to Google Drive, as the NAS transfer seems to work off the bat with the headless setup guide found on the Marcone teslausb github page linked below.

The instructions I’ve based this off have come from:
https://github.com/marcone/teslausb
https://github.com/marcone/teslausb/blob/main-dev/doc/SetupRClone.md

I’ve then filled in the blanks from lots of googling and a discussion thread on the https://teslamotorsclub.com forum. 

You will need

Raspberry Pi Zero W 
Raspberry Pi Zero case
Micro SD Card – 64gb (£9.98 at time of writing) – 128gb (£16.98 at time of writing)
Micro USB lead to connect it to the car

Grab the latest TeslaUSB image

The Marcone fork is what I’ve used and seems to the most frequently updated. 

https://github.com/marcone/teslausb

I’d suggest grabbing the latest image file and burning it to your micro SD card, on my Mac, I use ‘ApplePi-Baker’

Configuring the WiFi

Once the image is on the micro SD card, on your laptop or desktop edit the “wpa_supplicant.conf.sample” file and replace your WiFi details within the quotation marks in the below section:

network={
ssid=”YOURSSID (Wifi name)”
psk=”YOURPASSWORD (to connect to the Wifi network)”
key_mgmt=WPA-PSK
}

Once done, exit and save the file, rename it to remove the .sample, so the new file should be wpa_supplicant.conf

You are now ready to put the microSD into the Pi and boot it up

Rclone config (to upload to Google Drive)

Once the Pi has power (plugging into your laptop/desktop is fine to power it) you should then SSH into it, on a Mac I use Terminal, choose your favourite SSH client in Windows. To do this in Terminal: ssh pi@raspberrypi

If you are prompted that “The authenticity of host XXXXXXX” etc.. type yes and press enter to continue.

The default password (you should change this once complete) is: raspberry

Once you are in, the next command to run is: sudo -i

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

Once this is completed, we now need to configure rclone, run this to start: rclone config

Use the following options;

  1. n for new remotes
  2. gdrive for name
  3. 13 for Google Drive
  4. Leave client_id and client_secret blank (hit enter to leave blank on both)
  5. Option 1 (some people have said option 3 works just as well)
  6. Leave root_folder_id and service_account_file blank (hit enter to leave blank on both)
  7. n to skip advanced config
  8. n for autoconfig
  9. Copy the link to create a token, then approve in the Google authentication screen 
  10. Copy the verification code and paste into your SSH session.
  11. n for team drive
  12. y to confirm
  13. q then enter to quit config

Once rclone config is complete, run: 
export RCLONE_DRIVE=”gdrive”

Next, run: rclone listremotes
This is to validate that you can see what you’ve just done has worked.

Then run the following one after the other:

export ARCHIVE_SYSTEM=rclone
export RCLONE_DRIVE=gdrive
export RCLONE_PATH=TeslaCam

rclone mkdir “$RCLONE_DRIVE:TeslaCam”
rclone lsd “$RCLONE_DRIVE”:

The last command should confirm that the TeslaCam folder now exists in Google Drive, if not, start over from the rclone config stage.

I would now recommend to set the camsize=60% and musicsize=10% leaving some free space on the drive. Without this, I started getting USB drive too slow errors, to do this, run the following commands one after the other:

export camsize=60%
export musicsize=10%

Setting up TeslaUSB

Run the following commands one after the other, the final command takes a good while to run as it installs lots of components and pulls down from the teslausb repo.

mkdir -p /root/bin
cd /root/bin
wget https://raw.githubusercontent.com/marcone/teslausb/main-dev/setup/pi/setup-teslausb
chmod +x setup-teslausb
./setup-teslausb

If prompted to delete snapshots, choose yes and press enter

This is where I’ve had to do a couple of extra changes not in the original instructions as it would not work without them and trust me, I rebuilt that image about 50 times trying to get this working!

When the setup-teslausb step has finally completed, we need to create a symbolic link from the .config folder to the mutable config directory, to do this, run: 
ln -s /mutable/configs/rclone /root/.config/rclone

If you run the following;
ls -l /root/.config

This should confirm your symlink is in place (the –> shows it’s working, it should look like this (but with correct time stamps!)

total 0
lrwxrwxrwx 1 root root 23 Apr 22 15:01 rclone -> /mutable/configs/rclone

Now run: halt

This will stop the Pi, you can now safely unplug the Pi.

Get it in the car!

The next time you boot it up it’s good to go, so stick it in the car, do a test save once it’s booted up and the camera icon appears (teslausb only uploads saved records and sentry mode events).

If you need to SSH into the Pi again, the name will have now changed to teslausb, so use the command ssh pi@teslausb.local instead

You can SSH into the Pi to check what’s going on by reviewing the log file in the mutable folder by either tailing or editing the archiveloop.log file.