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¶m=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);
?>