Hedgehog cam syncing
One thing I wanted for my hedgehog cam videos is that they get copied from the raspberry pi to some network storage for easier access.
First up I needed some network storage. My BT HomeHub has a USB port that allows you to insert a thumb drive and it will appear as a windows share. I inserted a 64GB drive and it did appear.
Unfortunately while MotionEyeOS does have the ability to upload the captured files through a setting in the user interface it only supports FTP, SFTP, Google Drive or Dropbox. To copy files to a windows share it would need to support SMB. Another approach was needed.
MotionEyeOS has the ability to run a command after a media file has been created, so I created a shell script that would upload the media file to the SMB share for my thumb drive.
I have enabled the 'Run a command' option and added the following text into the command field.
/root/upload_to_share.sh %f %Y-%m-%d
Then I create the 'upload_to_share.sh' script on the pi. I SSH'd in to the pi and the first step is to remount the filesystem as writeable.
mount -o remount,rw,noatime,sync /
First up I needed some network storage. My BT HomeHub has a USB port that allows you to insert a thumb drive and it will appear as a windows share. I inserted a 64GB drive and it did appear.
Unfortunately while MotionEyeOS does have the ability to upload the captured files through a setting in the user interface it only supports FTP, SFTP, Google Drive or Dropbox. To copy files to a windows share it would need to support SMB. Another approach was needed.
MotionEyeOS has the ability to run a command after a media file has been created, so I created a shell script that would upload the media file to the SMB share for my thumb drive.
I have enabled the 'Run a command' option and added the following text into the command field.
/root/upload_to_share.sh %f %Y-%m-%d
Then I create the 'upload_to_share.sh' script on the pi. I SSH'd in to the pi and the first step is to remount the filesystem as writeable.
mount -o remount,rw,noatime,sync /
Then using vi I created upload_to_share.sh in the /root home directory.
#!/bin/bash
basefile="$(basename -- $1)"
SMBOPTIONS="--socket-options='TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=131072 SO_SNDBUF=131072'"
echo SMBOPTIONS=$SMBOPTIONS
smbclient -U nige% \
//192.168.1.254/Intenso \
--directory hedgehogcam \
-c "mkdir $2"
smbclient \
-U nige% \
//192.168.1.254/Intenso \
--directory hedgehogcam \
$SMBOPTIONS \
-c "put $1 $2/$basefile"
and don't forget to make the file executable
chmod +x upload_to_share.sh
That should be enough to have your media files uploaded to a windows share.
Comments
Post a Comment