This code sets up a website using nginx to display the footage from a Tesla dashcam, using a Raspberry Pi Zero W as the USB drive. It uses the teslausb project for creating the USB drives on the Pi.
Note: The Tesla car browser doesn't load local websites. So if you want TeslaDashcamWeb to load on the car browser, you will need to perform the steps mentioned here after you have TeslaDashcamWeb working.
Update August 2019
I have stopped using TeslaDashcamWeb because I wanted to merge the three videos from the car into one and view them together in a website. I have created the TeslaCamMerge project to accomplish this. I am running this now instead of TeslaDashcamWeb.
- Raspberry Pi Zero W
- Micro-USB to USB cable, plugged into one of the Tesla's USB ports
- Tesla car!
- If you want to access this on your car browser, another Raspberry Pi (3B+ works well for me) to run an nginx reverse proxy server
- Raspbian Stretch Lite
- nginx web server
- rclone
- Responsive File Manager
- If you want to access this on your car browser, an update client from a dynamic DNS service to run on your nginx reverse proxy server
Load a Pi Zero W with Raspbian Stretch Lite and get SSH going
- Load Raspbian Stretch Lite on a Micro SD card
- On your computer, install Notepad++ or similar text editor that saves Unix-style line endings correctly
- In the
boot
drive of the Micro SD card, openconfig.txt
in Notepad++ and add a new line at the end with this content and save it:dtoverlay=dwc2
- Open
cmdline.txt
, make these changes and save it:- Before
rootwait
, addmodules-load=dwc2,g_ether
- Remove the
init=/usr/lib/raspi-config/init_resize.sh
at the end
- Before
- Add an empty file called
ssh
(no extension) in the same folder - Safely eject the Micro SD card from your computer
- Insert the Micro SD card into a Pi and boot it up
- Install Putty on your computer and try to connect to
raspberrypi.local
; you may need to install Bonjour for Windows if that doesn't work - Login in Putty using the id
pi
and passwordraspberry
- Change password, locale, timezone, etc. and enter your WiFi credentials using
sudo raspi-config
; do not reboot when exitingraspi-config
- Check that your Pi is connnecting to WiFi using
sudo wpa_cli -i wlan0 reconfigure
- Confirm you have an IP address with
ifconfig wlan0
- Edit
/boot/cmdline.txt
with your favorite editor usingsudo
to deleteg_ether
from themodules-load
phrase so it looks likemodules-load=dwc2
- Reboot with
sudo reboot
- Use Putty and login with your new password to the
pi
account, you now have a working SSH connection
Update the Pi and load required software
sudo apt update
sudo apt upgrade
sudo apt install nginx php-fpm php-mbstring git
Configure php-fpm
sudo nano /etc/php/7.0/fpm/php.ini
and make these changes:
- Replace the line that contains
cgi.fix_pathinfo=1
withcgi.fix_pathinfo=0
- Replace the line that contains
session.save_path
withsession.save_path = /tmp/php/sessions
Configure nginx
sudo nano /etc/nginx/sites-available/default
, edit these lines to look like:
index index.html index.htm index.php index.nginx-debian.html;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
sudo nano /etc/nginx/nginx.conf
, edit the log location lines:
access_log /tmp/log/nginx/access.log;
error_log /tmp/log/nginx/error.log;
mkdir -p /tmp/log/nginx
sudo nginx -t
- Restart nginx with
sudo /etc/init.d/nginx restart
- On your computer browser, navigate to the LAN IP of your Pi, you should see the default nginx welcome page
Configure rclone
sudo -i
- Install rclone with
curl -L https://raw.github.com/pageauc/rclone4pi/master/rclone-install.sh | bash
rclone config
and follow prompts; recommended:- Name the drive as
gdrive
- Use
drive
for Google Drive - Set up scope as
3
fordrive.file
- Name the drive as
exit
(from interactive sudo session)
Update sudoers and rc.local
sudo -i
echo "www-data ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/020_www-data-nopasswd
- Check the location of your rclone configuration file: try
ls /root/.config/rclone/rclone.conf
andls /root/.rclone.conf
and see which one it is. If your file is not at/root/.config/rclone/rclone.conf
, you need to replace this with the correct location of that .conf file in the next step when updating/etc/rc.local
nano /etc/rc.local
and update the first line of the file to#!/bin/bash -e
, then add this block of code just before the lineexit 0
LOGFILE=/tmp/rc.local.log
function log () {
echo -n "$( date )" >> "$LOGFILE"
echo -n ": " >> "$LOGFILE"
echo "$1" >> "$LOGFILE"
}
log "Running fsck..."
/sbin/fsck /mnt/cam -- -a >> "$LOGFILE" 2>&1 || echo ""
log "Running modprobe..."
/sbin/modprobe g_mass_storage >> "$LOGFILE" 2>&1
log "Preparing temp files..."
/bin/cp /root/.config/rclone/rclone.conf /tmp/rclone.conf >> "$LOGFILE" 2>&1
/bin/chmod 644 /tmp/rclone.conf >> "$LOGFILE" 2>&1
/bin/mkdir -p /var/log/nginx >> "$LOGFILE" 2>&1
/bin/mkdir -p /tmp/php/sessions >> "$LOGFILE" 2>&1
/bin/chown www-data:pi /tmp/php/sessions >> "$LOGFILE" 2>&1
/bin/mkdir -p /tmp/log/nginx >> "$LOGFILE" 2>&1
log "Starting nginx..."
/usr/sbin/service nginx start >> "$LOGFILE" 2>&1
log "All done"
exit
(from interactive sudo session)
Load website scripts
mkdir /home/pi/dash
- Set up some permissions:
sudo chown -R pi:www-data /home/pi/dash
sudo chown -R pi:www-data /var/www/html
cd /home/pi/dash
- Download the scripts with
git clone https://github.com/ppamidimarri/TeslaDashcamWeb
- Move the website scripts with
cp -r /home/pi/dash/TeslaDashcamWeb/html/ /var/www/
- Move python scripts with
mv /home/pi/dash/TeslaDashcamWeb/*connect* /home/pi/dash
- More permissions:
chmod +x /home/pi/dash/*
- On your computer browser, navigate to the LAN IP of your Pi, you should see the Tesla Dashcam welcome page
Create USB drives on the Pi
This section is work-in-progress as the teslausb project hasn't merged in latest changes needed to work with Tesla software versions 2019.5.1 and newer. For now, follow these instructions as root with sudo -i
to get it working.
Once you run the script fully and reboot the Pi, you should see the drive CAM automatically mount on your laptop (and MUSIC if you set that up). The CAM drive should have a folder called TeslaCam
in it. If you then SSH into your Pi, you should see that your root filesystem is now read-only. After this point, if you need to change anything on the Pi, you can do it by running sudo mount -o remount,rw /
and that will remount the root filesystem until the next reboot.
Create some symlinks for the dashcam clips on the Pi
sudo mount -o remount,rw /
cd /var/www/html
mount /mnt/cam
ln -s /mnt/cam/TeslaCam .
ls /mnt/cam/TeslaCam
and see if foldersRecentClips
andSavedClips
exist; if they don't create them withmkdir /mnt/cam/TeslaCam/RecentClips
andmkdir /mnt/cam/TeslaCam/SavedClips
mkdir thumbs
cd thumbs
ln -s /mnt/cam/TeslaCam/RecentClips .
ln -s /mnt/cam/TeslaCam/SavedClips .
chmod 775 /var/www/html/thumbs/
umount /mnt/cam
sudo shutdown now
Congratulations, you are done now! Plug your Pi into the Tesla and wait for the dashcam icon to appear. Once it appears, open the browser in the car and navigate to the hostname/IP of the Pi.
1. Front page of the website
2. View of folders within the TeslaCam folder
3. View of clips available, with options to Preview, Rename, Delete or Upload them to Google Drive
4. This is how Preview looks
5. Uploading a clip to Google Drive
6. Upload status after it is done