Upload Snapshot to FTP every 10 seconds when triggered - Is it me or something else?

Moderator: leecollings

Post Reply
EDsteve
Posts: 26
Joined: Thursday 13 October 2016 11:43
Target OS: Linux
Domoticz version:
Contact:

Upload Snapshot to FTP every 10 seconds when triggered - Is it me or something else?

Post by EDsteve »

Hi,

Aim: When motion is triggered save a snapshot every xx seconds for xx times. After that upload the pictures to a FTP server.

I copied and modified this script together:

Code: Select all

#!/bin/sh
today=`/bin/date '+%d-%m-%Y__%H-%M'`;  #Used to generate file-/foldername
IP="192.168.1.102"                       # IP address Camera

#Ping IP-address of camera to see if it's online, otherwise we don't have to $
if ping -c 1 $IP > /dev/null ; then  #Grab snapshot

#Create folder named with timestamp
mkdir /home/fa/domoticz/smbfiles/ipcam/$today

#Get Snapshot from camera. Every 10 seconds for 10 times and save in new folder
for d in $(seq 1 10); do wget "http://192.168.1.102:8081/photoaf.jpg" -O /home/fa/domoticz/smbfiles/ipcam/$today/$(date +%d-%m-%Y__%H-%M-%S).jpeg; sleep 10; done;

#Send snapshots to FTP

HOST='ftp.xxxx.de'
USER='44xxxx333'
PASSWD='xxxxxx'
LOCALPATH=/home/fa/domoticz/smbfiles/ipcam/$today
FILE=*.jpeg
DIR='ipcam/'
FTPFOLDER=$today    #Create a new folder on ftp with timestamp

ftp -n $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
passive
cd $DIR
mkdir $FTPFOLDER
cd $FTPFOLDER
lcd $LOCALPATH
mput $FILE
quit
exit;
EOF

fi
The code works perfectly until the FTP part. So all snapshots are saved on mz NanoPi.

I could not figure out why these problems occur:

1. Only one, two or three pictures make it to the FTP server. Instead of 10. The FTP log gives me this without error but only two files transfered:

Code: Select all

250 OK. Current directory is /ipcam
257 "01-02-2017__21-08" : The directory was successfully created
250 OK. Current directory is /ipcam/01-02-2017__21-08
Local directory now /home/fa/domoticz/smbfiles/ipcam/01-02-2017__21-08
mput 01-02-2017__21-08-30.jpeg? 200 PORT command successful
150 Connecting to port 27380
226-File successfully transferred
226 12.972 seconds (measured here), 20.75 Kbytes per second
277031 bytes sent in 11.00 secs (24.6055 kB/s)
mput 01-02-2017__21-08-36.jpeg? 200 PORT command successful
150 Connecting to port 24601
226-File successfully transferred
226 7.986 seconds (measured here), 33.97 Kbytes per second
279261 bytes sent in 6.77 secs (40.2830 kB/s)
mput 01-02-2017__21-08-41.jpeg? mput 01-02-2017__21-08-56.jpeg? 221-Goodbye. You uploaded 541 and downloaded 0 kbytes.
221 Logout.
2. The few pictures which made it to the FTP are "broken". The originals on my NanoPi i can open but I can't open the once from the FTP server. It says "it's not a valid format" or "Can't open file".. Strange :(

What can be the reason for this? Something wrong in my script? I already tried in passive mode. But same problem.
Hope someone has a solution.

ED

P.S.: I just tried to upload one of the "broken" pictures. But the board software can not handle the file either and refuses :(
SweetPants

Re: Upload Snapshot to FTP every 10 seconds when triggered - Is it me or something else?

Post by SweetPants »

I do not see any relation to Domoticz where this Forum is for!!
EDsteve
Posts: 26
Joined: Thursday 13 October 2016 11:43
Target OS: Linux
Domoticz version:
Contact:

Re: Upload Snapshot to FTP every 10 seconds when triggered - Is it me or something else?

Post by EDsteve »

The sub forum is called "Software" and "Camera's". And this script starts when motion is triggered in Domoticz to extend the functions of Domoticz: Uploading snapshots from Camera to FTP

If that is too far OFF topic... Sorry.
If it gets deleted or not. Here what i found out about my problems:

1. I live in Indonesia where i get a new IP address every minute or so... not sure why but i think that causes upload problems.

2. The pictures were "broken" because i did not upload them in binary mode.

With this script the pictures turn out fine:

Code: Select all

#!/bin/sh
today=`/bin/date '+%d-%m-%Y__%H-%M'`;  #Used to generate file-/foldername
IP="192.168.1.102"                       # IP address Camera

#Ping IP-address of camera to see if it's online, otherwise we don't have to $
if ping -c 1 $IP > /dev/null ; then  #Grab snapshot

#Create folder named with timestamp
mkdir /home/fa/domoticz/smbfiles/ipcam/$today

#Get Snapshot from camera. Every 10 seconds for 10 times and save in new folder
for d in $(seq 1 4); do wget "http://192.168.1.102:8081/photoaf.jpg" -O /home/fa/domoticz/smbfiles/ipcam/$today/$(date +%d-%m-%Y__%H-%M-%S).jpeg; sleep 15; done;

#Send snapshots to FTP

HOST='ftp.xxxx.de'
USER='44xxxx333'
PASSWD='xxxxxx'
LOCALPATH=/home/fa/domoticz/smbfiles/ipcam/$today
FILE=*.jpeg
DIR='ipcam/'
FTPFOLDER=$today    #Create a new folder on ftp with timestamp

ftp -n $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
passive
cd $DIR
mkdir $FTPFOLDER
cd $FTPFOLDER
lcd $LOCALPATH
bin
bin
mput $FILE
quit
exit;
EOF

fi
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest