From 5f382288604958b634002c79d5b06901b4fa47af Mon Sep 17 00:00:00 2001 From: cimryan Date: Thu, 18 Oct 2018 09:07:13 -0700 Subject: [PATCH 1/6] Get the IP address of the archive server by parsing ping output instead of using getent This seems to work for more network configurations. --- windows_archive/setup-teslausb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 045360c..55524c6 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -109,7 +109,7 @@ function create_usb_drive_backing_files () { function configure_archive () { echo "Configuring the archive..." mkdir /mnt/archive - local archive_server_ip_address="$(getent hosts $archiveserver | cut -d' ' -f1)" + local archive_server_ip_address="$(ping -c 1 -w 1 $archiveserver 2>/dev/null | head -n 1 | grep -o -e "(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\})" | tr -d '()')" echo "//$archive_server_ip_address/$sharename /mnt/archive cifs vers=3,credentials=/root/.teslaCamArchiveCredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0" >> /etc/fstab echo "username=$shareuser" > /root/.teslaCamArchiveCredentials From c1b2d33546ef7630de5d53b101ba989b75d6b22a Mon Sep 17 00:00:00 2001 From: cimryan Date: Thu, 18 Oct 2018 18:32:21 -0700 Subject: [PATCH 2/6] Fix references to setup-piForHeadlessConfig.sh --- GetShellWithoutMonitorOnLinux.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GetShellWithoutMonitorOnLinux.md b/GetShellWithoutMonitorOnLinux.md index 9bb6061..88d0522 100644 --- a/GetShellWithoutMonitorOnLinux.md +++ b/GetShellWithoutMonitorOnLinux.md @@ -8,7 +8,7 @@ Basically what you're doing is using the Pi's capability to emulate a network co ## Use the update script to setup Wifi and USB networking -A [script](https://raw.githubusercontent.com/cimryan/teslausb/master/mac_linux_archive/update-rpi-mac-linux.sh) is provided to automatically update your SD card so the first time you boot it on your Pi, USB networking and Wifi will automatically be configured. +A [script](https://raw.githubusercontent.com/cimryan/teslausb/master/mac_linux_archive/setup-piForHeadlessConfig.sh is provided to automatically update your SD card so the first time you boot it on your Pi, USB networking and Wifi will automatically be configured. If you prefer not to run the script, it's also a useful reference for the steps you'll need to take. @@ -19,7 +19,7 @@ If you prefer not to run the script, it's also a useful reference for the steps 1. Change to the directory where the SD card's `boot` folder (containing `cmdline.txt`) is located. On a Mac, this will be `/Volumes/boot`. On Linux the location may vary. 1. Run the following commands: ``` - wget https://raw.githubusercontent.com/cimryan/teslausb/master/mac_linux_archive/update-rpi-mac-linux.sh + wget https://raw.githubusercontent.com/cimryan/teslausb/master/mac_linux_archive/setup-piForHeadlessConfig.sh chmod +x update-rpi-mac-linux.sh ``` 1. Set your SSID (Wifi network name) and WIFIPASS environment variables. The script will insert them into the `wpa_supplicant.conf` when creating it: From 7dfee7900e165704915374a034077e406e249e14 Mon Sep 17 00:00:00 2001 From: cimryan Date: Thu, 18 Oct 2018 18:35:51 -0700 Subject: [PATCH 3/6] Revert unnecessary usb->USB changes. --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 55b5b49..c17ee30 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# teslaUSB +# teslausb ## Meta -This repo contains steps and scripts originally from [this thread on Reddit]( https://www.reddit.com/r/teslamotors/comments/9m9gyk/build_a_smart_USB_drive_for_your_tesla_dash_cam/) +This repo contains steps and scripts originally from [this thread on Reddit]( https://www.reddit.com/r/teslamotors/comments/9m9gyk/build_a_smart_usb_drive_for_your_tesla_dash_cam/) Many people in that thread suggested that the scripts be hosted on Github but the author didn't seem interested in making that happen. I've hosted the scripts here with his/her permission. @@ -160,16 +160,16 @@ Now that you have Wifi up and running, it's time to set up the USB Storage and s ``` 1. Run these commands: ``` - wget https://raw.githubusercontent.com/cimryan/teslaUSB/master/windows_archive/setup-teslaUSB - chmod +x setup-teslaUSB - ./setup-teslaUSB + wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/setup-teslausb + chmod +x setup-teslausb + ./setup-teslausb ``` 1. Run this command: ``` reboot ``` -After reboot, the Pi hostname will become `teslaUSB`, so future `ssh` sessions will be `ssh pi@teslaUSB.local`. +After reboot, the Pi hostname will become `teslausb`, so future `ssh` sessions will be `ssh pi@teslausb.local`. ### Get the Pi set up for your Tesla. If you set up the Pi with a keyboard and a monitor disconnect it and connect it to a PC. If you're using a cable be sure to use the port labeled "USB" on the circuitboard. @@ -187,7 +187,7 @@ The setup process configures the Pi with read-only file systems for the operatin To make changes to the system partitions: ``` -ssh pi@teslaUSB. +ssh pi@teslausb. sudo -i mount / -o remount,rw mount /boot -o remount,rw From 258051039de1b5d0e2993cfdc66916f1d8272458 Mon Sep 17 00:00:00 2001 From: Richard Goodwin Date: Fri, 19 Oct 2018 01:39:24 -0500 Subject: [PATCH 4/6] Made sed command portable, added checks to not dupe file edits. --- .../setup-piForHeadlessConfig.sh | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/mac_linux_archive/setup-piForHeadlessConfig.sh b/mac_linux_archive/setup-piForHeadlessConfig.sh index 4e6572b..5148d85 100755 --- a/mac_linux_archive/setup-piForHeadlessConfig.sh +++ b/mac_linux_archive/setup-piForHeadlessConfig.sh @@ -51,12 +51,22 @@ verify_wifi_variables CMDLINE_TXT_PATH="$BOOT_DIR/cmdline.txt" CONFIG_TXT_PATH="$BOOT_DIR/config.txt" -echo "Updating $CONFIG_TXT_PATH ..." -echo "" >> "$CONFIG_TXT_PATH" -echo "dtoverlay=dwc2" >> "$CONFIG_TXT_PATH" +if ! grep -q "dtoverlay=dwc2" $CONFIG_TXT_PATH +then + echo "Updating $CONFIG_TXT_PATH ..." + echo "" >> "$CONFIG_TXT_PATH" + echo "dtoverlay=dwc2" >> "$CONFIG_TXT_PATH" +else + echo "$CONFIG_TXT_PATH already contains the required dwc2 module" +fi -echo "Updating $CMDLINE_TXT_PATH ..." -sed -i -e "s/rootwait/rootwait modules-load=dwc2,g_ether/" -e "s@ init=/usr/lib/raspi-config/init_resize.sh@@" "$CMDLINE_TXT_PATH" +if ! grep -q "dwc2,g_ether" $CMDLINE_TXT_PATH +then + echo "Updating $CMDLINE_TXT_PATH ..." + sed -i'.bak' -e "s/rootwait/rootwait modules-load=dwc2,g_ether/" -e "s@ init=/usr/lib/raspi-config/init_resize.sh@@" "$CMDLINE_TXT_PATH" +else + echo "$CMDLINE_TXT_PATH already updated with modules and removed initial resize script." +fi echo "Enabling SSH ..." touch "$BOOT_DIR/ssh" From 832320aa1af2a27302e07010c61408d5bab8c070 Mon Sep 17 00:00:00 2001 From: cimryan Date: Fri, 19 Oct 2018 10:39:36 -0700 Subject: [PATCH 5/6] Create the wpa_supplicant file on the boot partition during setup-piForHeadlessConfig.ps1. Also consolidate the documentation. Removed support for manual setup; that process doesn't add value, anymore. --- GetShellWithoutMonitorOnWindows.md | 2 + README.md | 71 +++---------------- windows_archive/setup-piForHeadlessConfig.ps1 | 28 +++++++- 3 files changed, 38 insertions(+), 63 deletions(-) diff --git a/GetShellWithoutMonitorOnWindows.md b/GetShellWithoutMonitorOnWindows.md index efd24ab..86a8773 100644 --- a/GetShellWithoutMonitorOnWindows.md +++ b/GetShellWithoutMonitorOnWindows.md @@ -18,6 +18,8 @@ ./setup-piForHeadlessConfig.ps1 -Verbose ``` 1. Enter the single letter of the "boot" drive and press Enter. +1. Enter the SSID of your WiFi network and press Enter. +1. Enter the Pre-Shared Key of your WiFi network and press Enter. 1. Eject the sd card. 1. Move the sd card to the Pi. 1. Connect a micro usb cable to the port labeled "USB" on the Raspberry Pi, and to the PC. diff --git a/README.md b/README.md index c17ee30..18ac6fd 100644 --- a/README.md +++ b/README.md @@ -32,22 +32,17 @@ Required: > Note: Of the many varieties of Raspberry Pi only the Raspberry Pi Zero and Raspberry Pi Zero W can be used as simulated USB drives. It may be possible to use a Pi Zero with a USB Wifi adapter to achieve the same result as the Pi Zero W, but this hasn't been confirmed. * A Micro SD card, at least 8 GB in size, and an adapter (if necessary) to connect the card to your computer. -* A USB A/Micro B cable: [Adafruit](https://www.adafruit.com/product/898) or [Amazon](https://www.amazon.com/gp/product/B013G4EAEI/) - -Recommended: These will allow you to set up the Raspberry Pi without following the steps for a "headless" setup, which are a little more complicated. -* Mini HDMI to HDMI cable [Adafruit](https://www.adafruit.com/product/2775) or [Amazon](https://www.amazon.com/AmazonBasics-High-Speed-Mini-HDMI-HDMI-Cable/dp/B014I8UEGY) -* A USB keyboard. -* A micro USB power cable. +* A mechanism to connect the Pi to the Tesla. Either: + * A USB A/Micro B cable: [Adafruit](https://www.adafruit.com/product/898) or [Amazon](https://www.amazon.com/gp/product/B013G4EAEI/), or + * A USB A Add-on Board if you want to plug your Pi into your Tesla like a USB drive instead of using a cable. [Amazon](https://www.amazon.com/gp/product/B07BK2BR6C/) Optional: -* USB A Add-on Board if you want to plug your Pi into your Tesla like a USB drive instead of using a cable. [Amazon](https://www.amazon.com/gp/product/B07BK2BR6C/) * A case. Don't want unprotected circuits hanging about! Official case at [Adafruit](https://www.adafruit.com/product/2885) or [Amazon](https://www.amazon.com/gp/product/B06Y593MHV). There are many others to choose from. Note that the official case won't work with the USB A Add on board. -* USB Splitter if you don't want to lose a front USB port. [The Onvian Splitter](https://www.amazon.com/gp/product/B01KX4TKH6) has been reported working by multiple people on reddit. +* USB Splitter if you don't want to lose a front USB port. [The Onvian Splitter](https://www.amazon.com/gp/product/B01KX4TKH6) has been reported working by multiple people on reddit. ### Software Download [Raspbian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/) * Note: Bittorrent is dramatically faster than direct download. -* Note: Raspbian Stretch Lite was tested by the original poster on Reddit, other varieties may work, too. Download and install: * [Etcher](http://etcher.io) @@ -64,7 +59,7 @@ Get the IP address of the archive machine. You'll need this later, so write it d There are four phases to setting up the Pi: 1. Get the OS onto the micro sd card. 1. Get a shell on the Pi. -1. Get the scripts onto the Pi. +1. Set up the USB storage functionality. 1. Get the Pi set up for your Tesla. ### Get the OS onto the micro SD card @@ -75,58 +70,12 @@ There are four phases to setting up the Pi: > Note: you don't need to uncompress the zip file you downloaded. ### Get a shell on the Pi -> Regardless of which way you use to access the Pi (Keyboard+HDMI or USB networking), **before you boot the Pi for for the first time with the MicroSD inserted**, verify that the /boot/cmdline.txt file on the MicroSD does not contain the parameter "init=/usr/lib/raspi-config/init_resize.sh". Delete that entire string if present. +If you used a Windows computer to flash the OS onto the MicroSD card, follow these [Instructions](GetShellWithoutMonitorOnWindows.md). +If you used a Mac or a Linux computer, follow these [Instructions](GetShellWithoutMonitorOnLinux.md). -#### Use a monitor/keyboard/mouse -If you have a monitor with an HDMI input, a Mini HDMI to HDMI cable, a USB keyboard and a Micro USB power cable you can hook up the devices to the Pi and configure it directly. -1. Insert the MicroSD card into the Pi. -1. Connect the keyboard, and monitor to the Pi. -1. Connect the power supply to the Pi using the port labeld "PWR" on the circuitboard. -1. When you're prompted for the password for the user "pi" use "raspberry" without the quotes. -1. Now skip to section below titled "Get the scripts onto the Pi". +### Set up the USB storage functionality -#### Windows (Setup USB Networking) - -If you don't have a keyboard/HDMI setup to boot the Pi and edit/transfer files directly, you'll probably want to connect to the Pi over Wifi or USB networking. -* Follow [these instructions](GetShellWithoutMonitorOnWindows.md), then skip down to the section titled **Set up Set up Wifi on the Pi (manually)y**. - -#### macOS or Linux (Setup Wifi or USB Networking) -* Follow [these instructions](GetShellWithoutMonitorOnLinux.md), then proceed to the section **Set up the USB Storage Functionality**. - - -### Set up Wifi on the Pi (manually) - -If you don't yet have Wifi running from the previous section, use these instructions to get it set up. Otherwise, skip to **Set up the USB Storage Functionality**. - -Now that you have an `ssh` shell on the Pi over USB networking, you can set up Wifi and continue with setup. - -1. Enter the following commands: - ``` - sudo -i - nano /etc/wpa_supplicant/wpa_supplicant.conf - ``` -1. Add this block to the bottom of the file specifying the actual SSID of your network and your actual PSK, keeping the quotes around both values. Note that the SSID may be case-sensitive on your network. - ``` - network={ - ssid="SSID" - psk="PASSWORD" - } - ``` -1. Press Control-O, Enter to save the file. -1. Press Control-X to return to the command line. -1. Configure the wifi to ensure that your Pi has access to your network. - ``` - wpa_cli -i wlan0 reconfigure - ``` -1. Run this command - ``` - ifconfig wlan0 - ``` -1. Verify that there's an IP address on your subnet assigned. If you don't see the IP address wait for a couple of seconds and re-run the command. - -### Set up the USB Storage Functionality - -Now that you have Wifi up and running, it's time to set up the USB Storage and scripts that will manage the dashcam and (optionally) music storage. +Now that you have Wifi up and running, it's time to set up the USB storage and scripts that will manage the dashcam and (optionally) music storage. 1. SSH to the Pi and run `sudo -i` 1. Try to ping your archive server from the Pi. In this example the server is named `nautilus`. @@ -192,6 +141,4 @@ sudo -i mount / -o remount,rw mount /boot -o remount,rw ``` -A script has been provided as `/root/remountfs_rw` to run the mount commands for you more easily. - Then make whatever changes you need to. The next time the system boots the partitions will once again be read-only. diff --git a/windows_archive/setup-piForHeadlessConfig.ps1 b/windows_archive/setup-piForHeadlessConfig.ps1 index ff951ea..972bbbc 100644 --- a/windows_archive/setup-piForHeadlessConfig.ps1 +++ b/windows_archive/setup-piForHeadlessConfig.ps1 @@ -2,7 +2,13 @@ Param ( [Parameter(Mandatory=$True,Position=1)] - [string]$driveLetter + [string]$driveLetter, + + [Parameter(Mandatory=$True,Position=2)] + [string]$wifiSSID, + + [Parameter(Mandatory=$True,Position=3)] + [string]$wifiPSK ) $drivePath="${driveLetter}:" @@ -28,4 +34,24 @@ $cmdlinetxtContent.Replace("rootwait", "rootwait modules-load=dwc2,g_ether").Rep Write-Verbose "Enabling SSH ..." [System.IO.File]::CreateText($sshPath).Dispose() +# Sets up wifi credentials so wifi will be +# auto configured on first boot + +$wpaSupplicantConfPath="$drivePath\wpa_supplicant.conf" + +Write-Verbose "(Re)creating WiFi configuration file $wpaSupplicantConfPath." +if ([System.IO.File]::Exists("$wpaSupplicantConfPath")) { + del "$wpaSupplicantConfPath" +} + +"ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev` +update_config=1` +` +network={` + ssid=`"$wifiSSID`"` + psk=`"$wifiPSK`"` + key_mgmt=WPA-PSK` +}` +" | Out-File -FilePath "$wpaSupplicantConfPath" -Encoding utf8 + Write-Verbose "All done." \ No newline at end of file From 8744bf0c19a8dcc8afaaf006db9d6ebdab5a0b54 Mon Sep 17 00:00:00 2001 From: cimryan Date: Fri, 19 Oct 2018 10:52:35 -0700 Subject: [PATCH 6/6] Extracted notification instructions to separate document. Keep the main instructions as streamlined as possible. --- ConfigureNotificationsForArchive.md | 12 ++++++++++++ README.md | 15 +++------------ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 ConfigureNotificationsForArchive.md diff --git a/ConfigureNotificationsForArchive.md b/ConfigureNotificationsForArchive.md new file mode 100644 index 0000000..2c6c936 --- /dev/null +++ b/ConfigureNotificationsForArchive.md @@ -0,0 +1,12 @@ +OPTIONAL: You can choose to integrate with [Pushover](https://pushover.net) to get a push notification to your phone when the copy process is done. Depending on your wireless network speed/connection, copying files may take some time, so a push notification can help confirm that the process finished. If no files were copied (i.e. all manually saved dashcam files were already copied, no notification will be sent.). The Pushover service is free for up to 7,500 messages per month, but the [iOS](https://pushover.net/clients/ios)/[Android](https://pushover.net/clients/android) apps do have a one time cost, after a free trial period. *This also assumes your Pi is connected to a network with internet access.* + +1. Create a free account at Pushover.net, and install and log into the mobile Pushover app. +1. On the Pushover dashboard on the web, copy your **User key**. +1. [Create a new Application](https://pushover.net/apps/build) at Pushover.net. The description and icon don't matter, choose what you prefer. +1. Copy the **Application Key** for the application you just created. The User key + Application Key are basically a username/password combination to needed to send the push. +1. Run these commands, substituting your user key and app key in the appropriate places. No `"` are needed. + ``` + export pushover_enabled=true + export pushover_user_key=put_your_userkey_here + export pushover_app_key=put_your_appkey_here + ``` \ No newline at end of file diff --git a/README.md b/README.md index 18ac6fd..c672958 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ You can configure a Raspberry Pi Zero W so that your Tesla thinks it's a USB dri The scripts in this repo will also allow you to use the Pi to store music that the Tesla can read through the USB interface. +Archiving the clips can take from seconds to hours depending on how many clips you've saved and how strong the WiFi signal is in your Tesla. If you find that the clips aren't getting completely transferred before the car powers down after you park or before you leave you can use the Tesla app to turn on the Climate control. This will send power to the Raspberry Pi, allowing it to complete the archival operation. + ## Prerequisites ### Assumptions @@ -95,18 +97,7 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s export sharepassword=pa$$w0rd export campercent=100 ``` -1. OPTIONAL: You can choose to integrate with [Pushover](https://pushover.net) to get a push notification to your phone when the copy process is done. Depending on your wireless network speed/connection, copying files may take some time, so a push notification can help confirm that the process finished. If no files were copied (i.e. all manually saved dashcam files were already copied, no notification will be sent.). The Pushover service is free for up to 7,500 messages per month, but the [iOS](https://pushover.net/clients/ios)/[Android](https://pushover.net/clients/android) apps do have a one time cost, after a free trial period. *This also assumes your Pi is connected to a network with internet access.* - - * Create a free account at Pushover.net, and install and log into the mobile Pushover app. - * On the Pushover dashboard on the web, copy your **User key**. - * [Create a new Application](https://pushover.net/apps/build) at Pushover.net. The description and icon don't matter, choose what you prefer. - * Copy the **Application Key** for the application you just created. The User key + Application Key are basically a username/password combination to needed to send the push. - * Run these commands, substituting your user key and app key in the appropriate places. No `"` are needed. - ``` - export pushover_enabled=true - export pushover_user_key=put_your_userkey_here - export pushover_app_key=put_your_appkey_here - ``` +1. If you'd like to receive a text message when your Pi finishes archiving clips follow these [Instructions](ConfigureNotificationsForArchive.md). 1. Run these commands: ``` wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/setup-teslausb