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.
Load a Pi Zero W with Raspbian Stretch Lite and get SSH going
boot
drive of the Micro SD card, open config.txt
in Notepad++ and add a new line at the end with this content and save it: dtoverlay=dwc2
cmdline.txt
, make these changes and save it:
rootwait
, add modules-load=dwc2,g_ether
init=/usr/lib/raspi-config/init_resize.sh
at the endssh
(no extension) in the same folderraspberrypi.local
; you may need to install Bonjour for Windows if that doesn't workpi
and password raspberry
sudo raspi-config
; do not reboot when exiting raspi-config
sudo wpa_cli -i wlan0 reconfigure
ifconfig wlan0
/boot/cmdline.txt
with your favorite editor using sudo
to delete g_ether
from the modules-load
phrase so it looks like modules-load=dwc2
sudo reboot
pi
account, you now have a working SSH connectionUpdate 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:
cgi.fix_pathinfo=1
with cgi.fix_pathinfo=0
session.save_path
with session.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
curl -L https://raw.github.com/pageauc/rclone4pi/master/rclone-install.sh | bash
rclone config
and follow prompts; recommended:
gdrive
drive
for Google Drive3
for drive.file
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
ls /root/.config/rclone/rclone.conf
and ls /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 line exit 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"
4. `exit` (from interactive sudo session)
**Load website scripts**
1. `mkdir /home/pi/dash`
2. Set up some permissions:
* `sudo chown -R pi:www-data /home/pi/dash`
* `sudo chown -R pi:www-data /var/www/html`
3. `cd /home/pi/dash`
4. Download the scripts with `git clone https://github.com/ppamidimarri/TeslaDashcamWeb`
5. Move the website scripts with `cp -r /home/pi/dash/TeslaDashcamWeb/html/ /var/www/`
6. Move python scripts with `mv /home/pi/dash/TeslaDashcamWeb/*connect* /home/pi/dash`
7. More permissions:
* `chmod +x /home/pi/dash/*`
8. 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](https://github.com/cimryan/teslausb/issues/119#issuecomment-473346734) 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**
1. `sudo mount -o remount,rw /`
2. `cd /var/www/html`
3. `mount /mnt/cam`
3. `ln -s /mnt/cam/TeslaCam .`
4. `ls /mnt/cam/TeslaCam` and see if folders `RecentClips` and `SavedClips` exist; if they don't create them with `mkdir /mnt/cam/TeslaCam/RecentClips` and `mkdir /mnt/cam/TeslaCam/SavedClips`
4. `mkdir thumbs`
5. `cd thumbs`
6. `ln -s /mnt/cam/TeslaCam/RecentClips .`
7. `ln -s /mnt/cam/TeslaCam/SavedClips .`
4. `chmod 775 /var/www/html/thumbs/`
8. `umount /mnt/cam`
9. `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.
## [Screenshots](https://imgur.com/a/JcjnGYA)
**1. Front page of the website**
![Main page](https://i.imgur.com/3kkqZfe.png)
**2. View of folders within the TeslaCam folder**
![Folder view](https://i.imgur.com/0Jm7qqu.png)
**3. View of clips available**, with options to Preview, Rename, Delete or Upload them to Google Drive
![Folder view](https://i.imgur.com/3UusX2P.png)
**4. This is how Preview looks**
![Previewing a clip](https://i.imgur.com/hhtgNjC.png)
**5. Uploading a clip to Google Drive**
![Uploading...](https://i.imgur.com/um2Pbmr.png)
**6. Upload status after it is done**
![Upload done](https://i.imgur.com/O0NRdr8.png)