Sunday 21 October 2018

TeslaCamPi - Uploading the Tesla DashCam videos dynamically to AWS / DropDox

Current active github TeslaUSB project from a great team look here
https://github.com/cimryan/teslausb




<WIP>

8GB virtual USB Drive
uploads 'Saved-' files from TeslaCam to dropbox
crontab running every 5 mins

frostymccool/TeslaCamPi


Extending from:





  



MAKE A PI ZERO W SMART USB FLASH DRIVE

https://www.raspberrypi.org/magpi/pi-zero-w-smart-usb-flash-drive/

3GB for TeslaCam, 8G for Music

Create 3G TeslaCam drive file
sudo dd if=/dev/zero of=/piTeslaCam.bin bs=3M seek=1024 count=0

Create the file to user for usb fat sharing drive
sudo dd if=/dev/zero of=/piTeslaMusic.bin bs=8M seek=1024 count=0

sudo mkdosfs /piTeslaMusic.bin -F 32 -I
sudo mkdosfs /piTeslaCam.bin -F 32 -I

Mount the TeslaCam and create the key folder that the car will look for 
sudo mount -t vfat /piTeslaCam.bin /mnt/temp && sudo mkdir /mnt/temp/TeslaCam
sudo umount /mnt/temp
sudo nano /etc/fstab
Append the line below to the end of the file
/piTeslaMusic.bin /mnt/usb_share vfat users,umask=000 0 2

/piTeslaCam.bin /mnt/usb_share vfat users,umask=000 0 2

Test the mass storage gadget - … if it doesn’t work, likely a conflicting gadget is already loaded (try checking / removing  loaders from boot/configtext)
sudo modprobe g_mass_storage file=/piTeslaCam.bin stall=0 ro=0 removable=1
sudo modprobe g_mass_storage file=/piTeslaMusic.bin stall=0 ro=0 removable=1

For the normal load gadget line, they should be loaded together, only difference is that the music gadget can be loaded readonly as there is no need to allow the car to have write access to it.
sudo modprobe g_mass_storage file=/piTeslaCam.bin,/piTeslaMusic.bin stall=0,0, ro=0,1 removable=1,1


AWS S3 uploader .....

<TBD> .... event date stamp min vs file ... concatenated 10min 'saved-front-...' files ... contruct 360-saved... with just the front and structure for merging sides and rear  - assuming they will be able to be exported by Tesla soon :)

And dropbox uploader ..

https://www.raspberrypi.org/forums/viewtopic.php?t=164166


python dbupteslacam.py 


script modifications:


# Path to use for re-mounting to make sure get up to date data
umountdir = "/mnt/usb_share"
#The directory to sync
syncdir="/mnt/usb_share/TeslaCam"
#Filename prefix to test for
filenameprefix="saved-"


#Uploads files in a directory
def upload_files(path, level):
    fullpath = os.path.join(syncdir,path)
    print_output("Syncing " + fullpath,level)
    if filenameprefix:
        print_output("Syncing files with prefix only: " + filenameprefix, level) 


....

        #Loop through the files to check to upload
        for f in files:                                 
            print_output("Found File: " + f,level)   
            if upload == 1 and (f[:len(filenameprefix)]==filenameprefix) and (overwrite == 1 or not f in dfiles):



... and at the bottom ...

#re-mount the folder to make sure it's fresh
def remount():
        cmd = [ 'sudo', 'umount', umountdir ]
        p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)

        cmd = [ 'sudo', 'mount', '-a' ]
        p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)

#Start
remount()


crontab

*/5 * * * * python /home/pi/dbupteslacam.py







Issues/updates:
  • possibly need to control w/r more across the gadget and the share, there are some FSCK files appearing in the root  and 0 byte file minutes. (pre-dropbox addition)
  • check dropbox handler to make sure noop if no wifi
  • update uploader to a daemon / stop it just spinning up multiple instances
  • update / use accelerometer on pi to trigger the copy / upload.. at least it will snapshot in case user forgets to hit the button even in wifi not available.... 
  • could maybe use trigger on phone to switch on phone hotspot... then tcp - teslacampi :) - could connect and use the phone hotspot to upload



No comments:

Post a Comment

Note: only a member of this blog may post a comment.