How to attach a control script??

Forum for questions and support relating to the 1.24.x releases only.
Locked
jondecker76
Posts: 35
Joined: Wed Sep 29, 2010 12:48 am

How to attach a control script??

Post by jondecker76 »

Ok, I've made a control script that is working from the command line. Now I just need to figure out how to make ZM use it....

I created a new control type (Vivotek VS7100), and set up its capabilities.

Now I just need to know:
A) Where the control script should go? Right in /usr/share/zoneminder (default location in Ubuntu install)?

B) How do I tell ZM to use this script? I'm guessing that maybe i would put "/usr/share/zmcontrol-vivotek_vs7100.pl" in the protocol field of the control type?

thanks!
jondecker76
Posts: 35
Joined: Wed Sep 29, 2010 12:48 am

Post by jondecker76 »

just giving this a bump...

Surely someone knows how to attach a control script to a camera in ZM?
jondecker76
Posts: 35
Joined: Wed Sep 29, 2010 12:48 am

Post by jondecker76 »

Well, I have probably over 20 hours into this now. I'm absolutely baffled that there exists no real documentation on how to do this! (I'm a very accomplished programmer, but that can't help me if there is no documentation nor anybody on the forums that can help)

What I have so far:
- It seems that control scripts are in /usr/share/perl5/ZoneMinder/Control
- It also seems that control scripts no longer end in .pl - but in .pm
- I modified one of the supplied scripts to try to control one of my cameras. This still won't work, however. I only get the following error in zmwatch.log when I try to control the camera:

Code: Select all

10/05/10 16:51:51.265633 zmcontrol[3049].ERR [Error check failed: '401 Unauthorized']
I turned off authorization of my camera, so there should be no authorization required - I can verify this by manually entering some of the control commands directly into firefox


Does anybody know if I'm at least on the right track?

thanks
jondecker76
Posts: 35
Joined: Wed Sep 29, 2010 12:48 am

Post by jondecker76 »

ok, got some simple pan and tilt working - though I'm still trying to figure out why some of the advanced features aren't working yet (such as pan and tilt speed)
mnemcik
Posts: 2
Joined: Wed Oct 06, 2010 7:11 am

Post by mnemcik »

I can't figure out how to do this either. Can you provide any clues on what you have done so far?
jondecker76
Posts: 35
Joined: Wed Sep 29, 2010 12:48 am

Post by jondecker76 »

From what I've found, most all documentation currently available is outdated. It appears that old versions of ZM used a different control scheme (using files named zmcontrol-cameraName.pl) and worked off of a bunch of parameters passed to the script. Almost all examples I've found off of the net follow this scheme.

Below is what I've found about the "new" object oriented scheme for making your own control scripts. It still amazes me that there is no documentation on this!


Ok, so far simple things are working quite well. Here is what has worked so far:

1) Set up your monitor and get the video working
2) In the monitor settings, go to the control tab, and check the "controllable" box
3) Since your camera is almost certainly not listed under Control Type, click the "edit" link right next to the dropdown.
4) In the new window that appears, click "Add New Control"
5) You will now be presented with a Control Capability form. In the main tab, enter the name of the camera (Vivotek VS7100, for example), set type to remote, and lastly for protocol - make a new unique identifier without spaces (mine is VivotekVS7100). Remember how you spelled it EXACTLY including capitalization - you will need to match it in 2 other places later!
6) Under the "move" tab, check the Can Move checkbox. To start out simple, also check the Can Move Continuous checkbox.
7) Under the Pan, Tilt and Zoom boxes, just check the "Can Pan"/"Can Tilt"/"Can Zoom" checkboxes (well, maybe not zoom if your camera doesn't support it)
8) Hit the save button. This should be enough that you can start working on your script - You can always come back here later to do some tweakign and add more capabilities. FYI - what these capability settings do, is change the way the HTML is generated for the control buttons.
9) Now that you've saved, you should be back to the monitor settings. Under the control tab still, enter your control address (this should normally be the IP address you used in the source tab. Of course, if you need authentication, use the format of username:password@IPaddress

9) Now its time to start making a script. Its probably easiest to start modifying another one
10) In Ubuntu, the control scripts are located at /usr/share/perl5/ZoneMinder/Control, and have the extension of .pm (though they are perl sources). If you can't find it here, just open up a terminal and type:

Code: Select all

locate PanasonicIP.pm
. This should tell you where your control scripts are stored if you are using a different distro.

11) It doesn't matter which you choose to edit, but for simplicity, open the PanasonicIP.pm file in Gedit (or any text editor).. Use the "save as" feature of your text editor to save it as a new name (so we dont' mess up the original PanasonicIP.pm file). Name it exactly as you did in step 5 for the unique identifier! For example, in my protocol field, i used the string - VivotekVS7100. So here, I saved the file as VivotekVS7100.pm. Again, make sure you use the same capitalization!

12) You should now be editing your own control file. The first thing you need to do, is edit the "package" line (should be around line 25). You need to change it so your package name is listed, rather than PanasonicIP. Here is my package line after editing:

Code: Select all

package ZoneMinder::Control::VivotekVS7100;
Again, use the same exact spelling and capitalization!

13) Just as a learning experience, look at line 111. You will see that the HTTP request is generated by the Control Address you entered under the sources tab in your monitor setup, and the command parameter passed into this function.

14) Starting with the CameraReset sub, are all of the definitions you will have to edit. Start by removing anything your camera doesn't support (such as CameraReset, MoveMap, etc)... You should be left with moveConUp, moveConDown, moveConLeft and moveConRight.

15) Another learning note: These are used because we chose "Continuous Movement" when we set up the control type. If we would have chose "Absolute Movement", then we would be using moveAbsUp... etc sub name. If we would have chose "Relative Movement", then we would be using moveRelUp....etc sub names. If we had chose "Can Move", but didn't specify Absolute, Relative or Continuous - then the sub names would simply be up,down,left and right.

16) Ok, so now you have your control file weeded down so that the only control subs you have are moveConUp/down/left/right.
You can now edit the $cmd variable with your own control address - but don't include the IP. For example, in my control file, my $cmd string for moveConUp:

Code: Select all

my $cmd = "/cgi-bin/viewer/camctrl.cgi?camid=1&move=up&speedtilt=5";
17) Notice that I hard-coded my camid and speedtilt. You should be able to pull these in from your settings. The documentation has some information, but this is out of date, as I have found some that no longer work (device, for example).
http://www.zoneminder.com/wiki/index.ph ... ol_Scripts

Here is a brief example of how I can use the tiltspeed parameter:

Code: Select all

sub moveConUp
{
    my $self = shift;
    my $params = shift; #bring in the parameters
    my $tiltspeed = $self->getParam( $params, 'tiltspeed' ); #and get the tiltspeed

    printMsg( "Move Up" );
    my $cmd = "/cgi-bin/viewer/camctrl.cgi?camid=1&move=up&speedtilt=$tiltspeed";
    $self->sendCmd( $cmd );
}
18) Thats pretty much it - though I'm still trying to figure out some of the more advanced features. I'd also like to figure out a better way to log things for easier debugging - maybe I'll just write my own library for that. Also, be sure to check out some of the other control scripts as they may give you some hints on other functionality.



If you find anything else out, please add it here. Once I've got everything, I'll do a good wiki page on how to do it. I'd be interested in hearing if this worked for you
mnemcik
Posts: 2
Joined: Wed Oct 06, 2010 7:11 am

Post by mnemcik »

That got me closer, but I eventually found out that because I am using local file as the source, ZM doesn't allow for a control type to be selected. Once I selected Remote as the source, then I was able to select a protocol in the control tab. Once I did that, I changed back to file as source and I have image and control.

Some trouble shooting tips I found here
http://www.zoneminder.com/wiki/index.php/Rovio

I purchased a cheapo camera, GP-280
http://www.zoneminder.com/forums/viewto ... cf760be5dd
not knowing its limitations. So the only way I have found how to get an image is with axmjpeg which means I save to a file. Not ideal, but at least I can use the camera with ZM.
jondecker76
Posts: 35
Joined: Wed Sep 29, 2010 12:48 am

Post by jondecker76 »

if its an MJPEG camera, you should be able to use the stream directly

Is the location of the stream known?
Locked