Menu

#2 Auto backup and erase SD card content by Wifi

0.7.0
pending
nobody
fileaccess (1)
discussion
2017-08-19
2017-07-27
Anonymous
No

Hi
I would like to backup all the content from the SD Card on my computer by wifi automatically when I come home.
Like just plug the camera, turn the wifi on and run an executable on the computer.
What I try to do Is:
- set a UBNT antenna as a receiver to put the camera on my network.
- make a program that I just have to execute to look in the directory and download the content and put it in a folder with the current date.
- Erase the SD Card content once it's done.

I run a motorcycle daily and record all my ride. I want to build a database with all the video content to make video editing later and it's a pain to download/erase the content of the SD card daily.
Do you have any clue before I start all the process ?
I'm a network guy, so the difficult part for me is the coding of the executable file.

Thanks
Nicolas

Discussion

  • Nutchanon Wetchasit

    • labels: --> fileaccess
    • status: unread --> pending
     
  • Nutchanon Wetchasit

    Hello Nicolas,

    From your list, I'm going to assume that...

    • You didn't take or leave any photo on the camera: as it is simpler to just format the card, rather than deleting individual video files.
    • You always run the program in the same day you recorded the videos: as it is simpler to just copy all files into single directory named after current date, rather than scan through filenames and download them individually into multiple directories.

    With these two assumptions, what you wish to do should be straightforward to write.

    Off the top of my head, these are steps the backup program would need to do:

    • (Optional) Bring the WiFi interface up, tune it to camera's access point, and provide the required authentication passphrase. Then wait for WiFi association and DHCP negotiation (if any) to complete.
    • Create a target directory on local machine, if not already exists, with an easily-sortable name (possibly YYYY-MM-DD like 2017-07-28).
    • Use a recursive downloader to download all files inside http://192.168.1.254/DCIM/MOVIE/ into target directory (except the directory listing page itself, and URLs which contain query string).
    • Issue MicroSD format command.
    • (Optional) Bring the WiFi interface down.

    As you mentioned connecting via a router instead of WiFi card, you might need to connect/disconnect WiFi manually, and let your program/script handle the rest.

    With all that said, I'm not sure how flexible your router's firmware is, in regard of NAT configuration. In case that NAT cannot be disabled, you might need to make sure that your router allocated network in an address range not conflicting with 192.168.1.0/24. (Though, if camera's directory listing shows up when you entered http://192.168.1.254/ in the browser, you're already fine)

    For the backup program/script itself: if you are running GNU/Linux (or other Unix-like platforms like Mac OS X and Cygwin), writing it as a shell script should be easiest. On the other hand, if you are running Microsoft Windows, just use your favorite programming language or an automation software.

    For the recursive downloader: you probably want to use either Pavuk (Unix) or Wget (Unix/Windows). Since there are URL-based skipping involved, using Pavuk should be more straightforward. Though with some care, Wget can be used too (and there are some interesting side effects). See example scripts in posts below.

    Regards,
    Nutchanon

    P.S. In any case, file modification dates will not be preserved due to the lack of Last-Modified HTTP header, but you should be able to re-assign them later from a look at videos' metadata if that is desired.

     
  • Nutchanon Wetchasit

    This is an example backup script for Unix-like system, using Pavuk as a downloader:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    #!/bin/sh
    # sj4000vbackup-pavuk.sh: Simple SJCAM SJ4000 WiFi video backup script,
    #                         based on Pavuk downloader
    # 
    # Written (2017) by Nutchanon Wetchasit
    # Released to public domain under Creative Commons Zero 1.0
    # <https://creativecommons.org/publicdomain/zero/1.0/>
    # 
    # Usage: ./sj4000vbackup-pavuk.sh
    # 
    # This script will download all videos from SJCAM SJ4000 WiFi action camera
    # located at 192.168.1.254 into a subdirectory named after current date
    # in `YYYY-MM-DD` format (subdirectory will be created if necessary),
    # and format the MicroSD card.
    # 
    # Note: If downloads were interrupted in the middle, re-running this script
    #       should correctly continue the downloads.
    
    ## Insert wireless LAN configuration commands here (if desired).
    
    ## Prepare target directory, use YYYY-MM-DD directory name
    DIRNAME="`date +%Y-%m-%d`"
    echo "Preparing video storage directory ($DIRNAME)..."
    mkdir -p "$DIRNAME"
    if [ $? -ne 0 ]
    then
        echo Video directory preparation failed. >&2
        exit 2
    fi
    
    ## Download videos (all files in <http://192.168.1.254/DCIM/MOVIE/>)
    echo "Downloading video files..."
    pavuk -mode normal -dont_leave_dir -nostore_index -noRobots -noCGI -base_level 4 -nthreads 1 -cdir "$DIRNAME" "http://192.168.1.254/DCIM/MOVIE/"
    if [ $? -ne 0 ]
    then
        echo Videos downloading failed. >&2
        exit 3
    fi
    
    ## Issue MicroSD format command
    echo "Formatting MicroSD card..."
    pavuk -quiet -lmax 1 -limit_inlines -dumpfd 1 "http://192.168.1.254/?custom=1&cmd=3010&par=1" | grep -q "<Status>0</Status>"
    if [ $? -ne 0 ]
    then
        echo MicroSD card formatting failed. >&2
        exit 4
    fi
    
    ## Insert wireless LAN deconfiguration commands here (if desired).
    
    echo Completed.
    

    This script is tested on Debian GNU/Linux 7.0 i386 (Pavuk 0.9.35), with SJCAM SJ4000 WiFi (G20140116V01 firmware). It should also continue downloading correctly even when the previous attempt was stopped in the middle.

     
  • Nutchanon Wetchasit

    And below is an example backup script for Unix-like system, using a well-known Wget as downloader.

    Note that Wget will delete each video file on the camera after it finished downloading, so card formatting is not needed- thus picture files are left intact. (This is due to Wget's accept/reject filter working post-download, so they can't keep deletion links from being hit)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    #!/bin/sh
    # sj4000vbackup-wget.sh: Simple SJCAM SJ4000 WiFi video backup script,
    #                        based on Wget downloader
    # 
    # Written (2017) by Nutchanon Wetchasit
    # Released to public domain under Creative Commons Zero 1.0
    # <https://creativecommons.org/publicdomain/zero/1.0/>
    # 
    # Usage: ./sj4000vbackup-wget.sh
    # 
    # This script will download all videos from SJCAM SJ4000 WiFi action camera
    # located at 192.168.1.254 into a subdirectory named after current date
    # in `YYYY-MM-DD` format (subdirectory will be created if necessary),
    # and delete each downloaded video from the camera.
    # 
    # Note: If downloads were interrupted in the middle, re-running this script
    #       should correctly restart downloading for unfinished/undownloaded files.
    
    ## Insert wireless LAN configuration commands here (if desired).
    
    ## Prepare target directory, use YYYY-MM-DD directory name
    DIRNAME="`date +%Y-%m-%d`"
    echo "Preparing video storage directory ($DIRNAME)..."
    mkdir -p "$DIRNAME"
    if [ $? -ne 0 ]
    then
        echo Video directory preparation failed. >&2
        exit 2
    fi
    
    ## Download videos (all files in <http://192.168.1.254/DCIM/MOVIE/>)
    ## also delete each of them when finished
    echo "Downloading video files..."
    wget --no-verbose --recursive --no-parent --no-host-directories --cut-dirs 2 --clobber -e "robots=off" --restrict-file-names=windows --reject "index.html,index.html.*,*@*" --directory-prefix "$DIRNAME" "http://192.168.1.254/DCIM/MOVIE/"
    if [ $? -ne 0 ]
    then
        echo Videos downloading failed. >&2
        exit 3
    fi
    
    ## Remove residual directory listing and command files (if any)
    echo "Removing residual directory listing and command file(s)..."
    rm -f "$DIRNAME/index.html"
    rm -f "$DIRNAME"/index.html.*
    rm -f "$DIRNAME"/*@del=1
    rm -f "$DIRNAME"/*@del=1.*
    
    ## Insert wireless LAN deconfiguration commands here (if desired).
    
    echo Completed.
    

    This script is tested on Debian GNU/Linux 7.0 i386 (Wget 1.13.4), with SJCAM SJ4000 WiFi (G20140116V01 firmware). It should also restart downloading incomplete files correctly even when previous attempt was stopped in the middle.

     
  • Anonymous

    Anonymous - 2017-08-19

    Wow so much good info in here.
    I'll try these step this week.
    For the router (UBNT antenna) it's a very flexible and complete firmware that can fit my need.
    I'm gonna work on widows for now.

    Thanks alot for the time.
    I'll give some news about it.
    Nico

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.