Page 1 of 1

how to turn a camera into a presence detector?

Posted: Saturday 05 November 2016 16:08
by brannou
Hi all,

As I bought several cameras before installing Domoticz on my Synology NAS, I'd like to know how I could turn them into presence detectors...
For the moment, I can already use them in Domoticz to take pictures which are trigered by other detectors but what I'm looking for is different:
When they detect a presence, these cameras (D-Link DCS-935L) can send pictures (via ftp) on my Synology NAS. So, I'd like to detect a change in the directory where these files are stored and sent this information to Domoticz. The change would be the number of directories inside this directory, since for each new detection a new directory is created with the new images.

I'm not an IT specialist... but when I run the following command on my NAS, I can get the number I'm looking for
find /volume1/homes/.../Cameras -type d | wc -l

Can I "os-execute" such a command to get this number in Domoticz LUA?? Or something else?

I tried with:
uservariables["Count"] = tostring(os.execute('sudo find /volume1/.../Cameras -type d | wc -l'))
I get the value "True" but no number...

With
uservariables["Count"] = os.execute('sudo find /volume1/.../Cameras -type d | wc -l')
I don't get anything...

I need help and probably a training too...

Any idea?

Thanks for your help,

BR

Re: how to turn a camera into a presence detector?

Posted: Saturday 05 November 2016 17:26
by Egregius
You'll need a script that runs in a loop with your command. Store the number in a variable and if number is chabged do something.
Probably bash or python will do good here.

Re: how to turn a camera into a presence detector?

Posted: Saturday 05 November 2016 19:50
by brannou
I'm not sure I'll be able to do that... I was just looking for something simple that would run in LUA.
I thought I could get the result (number of directories) from my "find" command through a simple "os.execute" but I doubt now!

Re: how to turn a camera into a presence detector?

Posted: Saturday 05 November 2016 22:39
by Egregius
Not so hard if you know Google.
Something like this should do it.

Code: Select all

#!/bin/bash
#Count files at start
PREV=`find /volume1/files/PiCam1/archive/ -type f | wc -l`
RUN=1
#Start endless loop
while :
do
	#Check number of files again
	NEW=`find /volume1/files/PiCam1/archive/ -type f | wc -l`
	#if new does not equal previous update prev and do your stuff
	if [ $NEW -ne $PREV ]
	then
		PREV=$NEW
		echo 'do your stuff'
		curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8084/json.htm?type=command&param=udevice&idx=6&nvalue=0&svalue=1"
	fi
	#increment the run counter
	((RUN++))
	#if loop has run 60 times exit
	if [ $RUN -eq 60 ]
	then
		exit 
	fi
	#adjust sleep and run counter as needed.
	sleep 0.9
done

Re: how to turn a camera into a presence detector?

Posted: Sunday 06 November 2016 10:14
by brannou
Thank you very much Egregius! I'll try today and I'll let you know.
Mr Google didn't help a lot here..

Regards,

BR

Re: how to turn a camera into a presence detector?

Posted: Sunday 06 November 2016 18:13
by brannou
This is awesome, I managed to have it work! (Even if, this morning, I didn't know anything about scripts and bash...)
In reality, the most difficult was to edit this script with vi on my NAS...

And afterwards, it looks so simple.

My cameras are now my new Domoticz detectors. That's great!

Thanks again Egregius!!!

BR

Re: how to turn a camera into a presence detector?

Posted: Sunday 06 November 2016 20:39
by Egregius
You're welcome ;)
If you were on a Pi you could use Inotify to watch a folder, probably a cleaner way. If you're folder isn't huge I don't think there wil be a performance penalty for your nas.

Re: how to turn a camera into a presence detector?

Posted: Monday 07 November 2016 17:02
by brannou
This is for next time...

I already use a Pi system as a 24-bit high end sound system which is connected to my Domoticz too. An alert can turn it on and make it bark or yowl as needed!
Next topic (potential headache for me) => Arm my camera with Domoticz.

Thanks,

BR

Re: how to turn a camera into a presence detector?

Posted: Monday 07 November 2016 17:27
by Egregius
Arm?
You mean enable/disable motion detection?
Use the developer console of chrome/firefox to find the url.

Re: how to turn a camera into a presence detector?

Posted: Thursday 10 November 2016 8:09
by brannou
Something else to understand...
Thanks,

BR

Re: how to turn a camera into a presence detector?

Posted: Thursday 10 November 2016 14:29
by VladGets
Egregius wrote:Not so hard if you know Google.
Something like this should do it.

Code: Select all

#!/bin/bash
#Count files at start
PREV=`find /volume1/files/PiCam1/archive/ -type f | wc -l`
RUN=1
#Start endless loop
while :
do
	#Check number of files again
	NEW=`find /volume1/files/PiCam1/archive/ -type f | wc -l`
	#if new does not equal previous update prev and do your stuff
	if [ $NEW -ne $PREV ]
	then
		PREV=$NEW
		echo 'do your stuff'
		curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8084/json.htm?type=command&param=udevice&idx=6&nvalue=0&svalue=1"
	fi
	#increment the run counter
	((RUN++))
	#if loop has run 60 times exit
	if [ $RUN -eq 60 ]
	then
		exit 
	fi
	#adjust sleep and run counter as needed.
	sleep 0.9
done
that's what I was looking for
thanks

Re: how to turn a camera into a presence detector?

Posted: Tuesday 22 November 2016 20:12
by brannou
My DCS935L camera "set Motion" page is this one: http://192.168.1.xxx/setup.asp?menu=setup&page=motion

But how can I check the "Set Motion" box + save it, via an html command?

I found the following line inside the html code but what can I do with it?
<input id="input_motion_enable" type="checkbox" onchange="onEnableMotion();">

Still a mystery to me...

BR

Re: how to turn a camera into a presence detector?

Posted: Tuesday 22 November 2016 21:53
by Egregius
Use the developer mode of Firefox/Chrome and set it on the network tab.
Then check the box and hit submit. You'll see the request to activate motion.
Then uncheck the box and hit sublit, you'll see the request to deactivate it.

Re: how to turn a camera into a presence detector?

Posted: Wednesday 23 November 2016 9:47
by brannou
Hi Egregius,

I found such things...
http://192.168.1.xxx/setup.asp?menu=setup&page=motion
http://192.168.1.xxx/motion_data.asp?103
http://192.168.1.xxx/motion.asp?token=103

Can I launch these from Blockly? All at once?

Thanks,

BR