Foscam motion/sound detection using FTP

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.
rfvdboom
Posts: 8
Joined: Tuesday 20 September 2016 8:32
Target OS: Raspberry Pi
Domoticz version: 3.5798
Location: Netherlands
Contact:

Foscam motion/sound detection using FTP

Postby rfvdboom » Tuesday 04 October 2016 22:02

Hi,

i wanted to use the motion/sound detection from my Foscam camera to create a notification. I tried a couple of tutorials, but nothing worked for me. I've found another solution that works for me. Maybe it's not the best solution, but it works!

Foscam can sent images to a FTP server when motion/sound is detected. You can find the settings in your camera. Then I use a PHP script. What does the script do:

1. it will log in on your FTP.
2. it search for files in the path ($logs_dir)
3. when it detect a file, the script will clear the directory and sent a command to a switch in Domoticz. The directory is empty again.
4. The script repeats every 10 seconds

The switch in Domoticz is a Dummy switch (motion sensor). When the switch is on, it sent a notification to PushSafer.

I use Domoticz (and PHP) for only 4 weeks now and i'm not a programmer. If you have any tips to fine tune the script? Let me know.

I hope that the solution works for people with the same problem.

grtz Ralph

Code: Select all

<?php
$i = 0;

do {

// set up the settings
$ftp_server = 'ftp.yourserver.nl'; //your ftp server
$ftpuser = 'admin'; //your ftp login
$ftppass = 'admin'; //your ftp pasword

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftpuser, $ftppass);
$logs_dir = "map1/map2/map3"; //path to directory where Foscam put images

//// Delete all files in the folder logs
ftp_chdir($conn_id, $logs_dir);
$files = ftp_nlist($conn_id, ".");
foreach ($files as $file)
{
    ftp_delete($conn_id, $file);
    file_get_contents("http://192.168.1.98:8080/json.htm?type=command&param=switchlight&idx=##&switchcmd=On"); //Put the domoticz IDX where the ## is
    echo date('H:i:s')." Sound / motion detected\r\n";


// close the connection
ftp_close($conn_id);

sleep (10); //change the update time here in seconds

} while ($i = -1);


?>

User avatar
safi78
Posts: 451
Joined: Thursday 05 September 2013 15:39
Target OS: Linux
Domoticz version: LastBeta
Location: Alkmaar, NL
Contact:

Re: Foscam motion/sound detection using FTP

Postby safi78 » Tuesday 04 October 2016 22:13

I don't know if you noticed or not, but I'm an extremely arrogant man who tends to think all of his plans will work ...

https://safiweb.nl

homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz

rfvdboom
Posts: 8
Joined: Tuesday 20 September 2016 8:32
Target OS: Raspberry Pi
Domoticz version: 3.5798
Location: Netherlands
Contact:

Re: Foscam motion/sound detection using FTP

Postby rfvdboom » Wednesday 05 October 2016 12:38

I dit, but this option didn't work for me.

rfvdboom
Posts: 8
Joined: Tuesday 20 September 2016 8:32
Target OS: Raspberry Pi
Domoticz version: 3.5798
Location: Netherlands
Contact:

Re: Foscam motion/sound detection using FTP

Postby rfvdboom » Thursday 06 October 2016 22:12

even better:

Make your pi a FTP server, using this tutorial: https://www.raspberrypi.org/documentati ... ess/ftp.md
and then use this script:

Code: Select all

$i = 0;

do {

$files = glob('map1/map2/map3/*'); // get all file names
foreach($files as $file){ // iterate files
  if(is_file($file))
    unlink($file); // delete file
    file_get_contents("http://192.168.1.98:8080/json.htm?type=command&param=switchlight&idx=38&switchcmd=On");
    echo date('H:i:s')." Sound / motion detected\r\n";
}


} while ($i = -1);

User avatar
pushsafer
Posts: 7
Joined: Sunday 18 September 2016 22:21
Target OS: Windows
Domoticz version: 3.5877
Location: Germany
Contact:

Re: Foscam motion/sound detection using FTP

Postby pushsafer » Wednesday 11 January 2017 22:51

To get a push notification from your ip camera through https://www.pushsafer.com > simple add your pushsafer email address or email alias to the ip cameras alarm / notification panel.


Return to “Show your projects”

Who is online

Users browsing this forum: No registered users and 4 guests