IP Cam Surveillance script.. A little help

Post new topic   Reply to topic    DD-WRT Forum Index -> Atheros WiSOC based Hardware
Author Message
lhstes
DD-WRT Novice


Joined: 09 Nov 2012
Posts: 2

PostPosted: Wed Apr 16, 2014 21:54    Post subject: IP Cam Surveillance script.. A little help Reply with quote
So, it's like this :

1) WRT160NL ( Firmware: DD-WRT v24-sp2 (03/29/14) std)
2) Foscam fi8904w IP Cam
I'm trying to write a script that will monitor the cam and upon alarm triggered will record ~ 5min video to the usb drive

The road so far :


Code:
#!/bin/bash
cd /tmp/mnt/sda1/stuff
alarm="0"
check_alarm()
{
   ls |grep status | xargs rm
   wget "http://192.168.167.250:8000/get_status.cgi?user=stream&pwd=stream" -O  status.txt
   grep -q "alarm_status=1" status.txt && alarm="1"
}
while :
   do
      if alarm="1"; then
               wget -Q20m "http://192.168.167.250:8000/videostream.asf?user=stream&pwd=stream" -O  fi8904w_`date +%F_%H-%M-%S`.asf
      else
         sleep 10;
         check_alarm()
      fi
done

The idea is : monitor the get_status.cgi on the cam and if alarm status is active record 20MB =~ 5min of video.
Typing it in on the shell all works well, when I save it as foscam.sh I get all sorts of errors. Is there something terribly, noobishly wrong about my script. Total beginner here,mind you. Is there something wrong with my idea? Has it been done already ? Why won't it run?
Sponsor
lhstes
DD-WRT Novice


Joined: 09 Nov 2012
Posts: 2

PostPosted: Fri Apr 18, 2014 2:11    Post subject: Reply with quote
Well, if anyone is interested, I got it (I think)

First a service.sh that checks if the main script is running and starts it if not

Code:

#!/bin/sh
cd /tmp/mnt/sda1/stuff
mypid=$(ps |grep '[f]os.sh' | awk '{print $1}')
while :
do
   if [ $mypid>0 ]
   then
      sleep 10
   else
      sh fos.sh
   fi
done


and then the fos.sh that does the work

Code:
#!/bin/sh
alarm=0
check_alarm() {
   sleep 10
   ls |grep status | xargs rm
   wget "http://192.168.167.250:8000/get_status.cgi?user=stream&pwd=stream" -O  status.txt
   grep -q "alarm_status=1" status.txt && alarm=1
}
check_alarm
while :
do
   if [ $alarm = 1 ]
      then
         wget "http://192.168.167.250:8000/videostream.asf?user=stream&pwd=stream" -O  fi8904w_`date +%F_%H-%M-%S`.asf   &
         sleep 600 && kill -9 $(ps |grep '[w]get' | awk '{print $1}') $(ps |grep '[f]os.sh' | awk '{print $1}') && sh fos.sh
         #
      else
         #sleep 10
         check_alarm
   fi
done
nizo
DD-WRT Novice


Joined: 12 Feb 2015
Posts: 1

PostPosted: Thu Feb 12, 2015 9:04    Post subject: FOSCAM recording and Script Reply with quote
Hello Ihstes..

this is very interesting, I was looking for a way to record from the FOSCAM cameras I have and I do not want to run a PC or a dedicated NVR system for this matter. I was thinking about the DDWRT I got on my LinkSys router WRT610N and found your post..

I am not that technical but I have the basics right.. do you mind if you can provide a more detailed steps on how to upload your script to the router and save it there and also is it possible that I can run this same script for more than one camera, I got 4 cameras that I would like to record when an alarm is triggered

thanks
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Atheros WiSOC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum