I have a cheap PTZ camera called a wanscam. It will reboot at random and go back to its home position. Otions in the camera dont work to tell it to ignore go to center on boot. So to get the camera to always be pointing in the right spot I wrote a command to go to a set position every so many minutes.
I had to write some code in this control file. http://stuff.jaygroh.com/zoneminder/wanscam.pm
Its a modification of the foscam script. Its kind of a mess since I was trying to get things working and I never cleaned it up. I dont think there is anything in there thats is causing this issue.
Now I wrote a simple script to reset all 3 of my cameras. http://stuff.jaygroh.com/zoneminder/test.sh
The command is
zmcontrol.pl --id 23 --command=presetGoto1
Now at the command line if I manualy type in
sudo zmcontrol.pl --id 23 --command=presetGoto1
It will work fine. The PTZ controls in zoneminder web page will continue to work.
If I run that script as a cron job under root or even just put in the command in the cron job under root the PTZ controls dont work in zoneminder. They are there but unresponsive. I dont understand what is casusing the PTZ controls to go unresponsive only when the commands are ran in a cron job.
Does anyone know how to fix this issue?
PTZ is disabled when running a cron job script
-
- Posts: 1
- Joined: Sat Oct 20, 2012 6:09 pm
Re: PTZ is disabled when running a cron job script
Just on that, I have a Wanscam PTZ camera too, and I'm not using that control file, and my camera still reboots randomly, so I don't think it's the script at all that's causing the issue.theforce wrote:I have a cheap PTZ camera called a wanscam. It will reboot at random and go back to its home position. Otions in the camera dont work to tell it to ignore go to center on boot. So to get the camera to always be pointing in the right spot I wrote a command to go to a set position every so many minutes.
I had to write some code in this control file, [url for location of:wanscam.pm]
Its a modification of the foscam script. Its kind of a mess since I was trying to get things working and I never cleaned it up. I dont think there is anything in there thats is causing this issue.
I don't have a solution to the problem, but I'm looking into it!
Re: PTZ is disabled when running a cron job script
I think I found the solution! 
Do not run the script under the root crontab. When you run the script under root it will create a file /tmp/zmcontrol-(monitor num).sock
This file is created by root but needs access by www-data. The file stays I'm guessing until zoneminder is restarted or the box is rebooted. To fix this issue do the following.
sudo su www-data
crontab -e
Insert your script and settings. Save.
exit
Now the script will run and create the files as user www-data and you can control the cameras from the web interface in between when the script is set to run.
So far it has worked for me. Let me know if this works for you.

Do not run the script under the root crontab. When you run the script under root it will create a file /tmp/zmcontrol-(monitor num).sock
This file is created by root but needs access by www-data. The file stays I'm guessing until zoneminder is restarted or the box is rebooted. To fix this issue do the following.
sudo su www-data
crontab -e
Insert your script and settings. Save.
exit
Now the script will run and create the files as user www-data and you can control the cameras from the web interface in between when the script is set to run.
So far it has worked for me. Let me know if this works for you.
Re: PTZ is disabled when running a cron job script
I've tried to add monitor to localZoneminder using "Remote Zoneminder" in Presets, but no success. I suppose that problem is in the monitor ID. I tried to use name and monitor ID as on remote Zoneminder but still nothing.
KazUyA
Re: PTZ is disabled when running a cron job script
It can be a couple of things:theforce wrote:
Now I wrote a simple script to reset all 3 of my cameras. http://stuff.jaygroh.com/zoneminder/test.sh
The command is
zmcontrol.pl --id 23 --command=presetGoto1
Now at the command line if I manualy type in
sudo zmcontrol.pl --id 23 --command=presetGoto1
It will work fine. The PTZ controls in zoneminder web page will continue to work.
If I run that script as a cron job under root or even just put in the command in the cron job under root the PTZ controls dont work in zoneminder. They are there but unresponsive. I dont understand what is casusing the PTZ controls to go unresponsive only when the commands are ran in a cron job.
Does anyone know how to fix this issue?
cron jobs do not have the same environmental variables and PATH as you have on the command line.
It is possible that when you you run it as a cron job it cant find a script or library it depends upon. Write a simple wrapper script that set up the PATH the same as in a cronjob and then executes the zmcontrol script.
or (more likely)
If you run the zmcontrol script as anybody other than the web server user then it can block the PTZ controls from working in the web interface. This is because zmcontrol creates a socket file, as the user you run it as, that can not be accessed by less privileged users. This means your "sudo zmcontrol.pl ..." creates the socket as user root and the web server user can not access it.
On my system the webserver runs as the user "wwwrun" so in my case I would have to run something like:
Code: Select all
su - -c "/usr/bin/zmcontrol.pl --id 2 --command=presetGoto --preset=1" wwwrun