Debugging a Control script
Debugging a Control script
I am attempting to get a control script for a Keekoon camera working. I started with onvif.pm and have read all the others, rather a lot of Perl monk stuff and quite a lot of Perl manual. I am at the point where I need to get some debugging info out into logs and I just can't seem to even get that working usefully.
My basic strategy is to use the Control Address in the following format: http://admin:adminpass@10.10.10.1:80, parse it into the real URL along with basic auth and send that to the camera.
This is the offending script: http://pastebin.com/jJWK4y5w
I would like to dump the URL I think I'm gathering in line 129-130 but it never even appears in the logs/db when I put a Debug( $url); line in 131(ish). I've also tried a few other ways of putting in Debug statements but it never seems to work. I have restarted ZM quite a few times, and spent a fair amount of time on stack overflow ...
It is a big ask to beg someone to cast a quick eye across my script but beyond making sure that it at least passes "perl -Mstrict -Mdiagnostics -cw Keekoon.pm" as a lint test and staring at it until my eyes water, I am at a loss as to what I've done wrong, with respect to debug output or functionally.
Cheers
Jon
My basic strategy is to use the Control Address in the following format: http://admin:adminpass@10.10.10.1:80, parse it into the real URL along with basic auth and send that to the camera.
This is the offending script: http://pastebin.com/jJWK4y5w
I would like to dump the URL I think I'm gathering in line 129-130 but it never even appears in the logs/db when I put a Debug( $url); line in 131(ish). I've also tried a few other ways of putting in Debug statements but it never seems to work. I have restarted ZM quite a few times, and spent a fair amount of time on stack overflow ...
It is a big ask to beg someone to cast a quick eye across my script but beyond making sure that it at least passes "perl -Mstrict -Mdiagnostics -cw Keekoon.pm" as a lint test and staring at it until my eyes water, I am at a loss as to what I've done wrong, with respect to debug output or functionally.
Cheers
Jon
Re: Debugging a Control script
try replacing Debug with Info. Debug logs only show up if Debugging is enabled in ZM (typically off)
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.
Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
- knight-of-ni
- Posts: 2406
- Joined: Thu Oct 18, 2007 1:55 pm
- Location: Shiloh, IL
Re: Debugging a Control script
You are doing this a bit out of order. Put ZoneMinder and Perl aside for the moment.
The first thing you should do is determine what all the available ptz command URLs are for your camera.
Determine the command which makes the camera pan right, then write it down.
Determine the command which makes the camera pan left, then write it down.
Can the camera zoom? Figure out what command makes it do that and write it down.
PTZ Patrols?
Manual IR Control?
You get the idea.
Every camera is different. Unless you have some piece of evidence which says otherwise, you cannot assume the commands to do these PTZ functions are the same as any other camera. For example, the script you chose to start with, onvif.pm, uses a command syntax of "/decoder_control.cgi?command={ptz_command}". Unless your camera has the same firmware of some known camera or you have an API document that tells you what the PTZ comamnds are, this camera probably does not accept commands via decoder_control.cgi. It is probably something else, and that is what you have to figure out first before you do anything else.
UPDATE: Google took me to your other ZoneMinder post which mentions the API here: http://www.keekoonvision.com/for-developers-a
Well sure enough, according to that it does use decoder_control.cgi, so here what you should do next:
1) manually build some of those URLs by hand and paste them into your browser. Verify the camera reacts in the way you expect.
2) confirm your Perl script does not have any errors by calling it from the command line:
If there are no problems with the syntax, then Perl should return to the command line without any output at all. If you get any kind of response then there is a problem with your syntax.
3) After completing steps 1 & 2, it is now time to test the script in zoneminder. Before you do that, install and run wireshark. With Wireshark running, try to control the camera from ZoneMinder. You should see the commands go out in plain text. Compare what you see to what the output is really supposed to be.
If you still need help, then we need to see the contents of your ZoneMinder logs, with debug enabled, from the moment prior to opening the monitor to just after your press a PTZ command.
The first thing you should do is determine what all the available ptz command URLs are for your camera.
Determine the command which makes the camera pan right, then write it down.
Determine the command which makes the camera pan left, then write it down.
Can the camera zoom? Figure out what command makes it do that and write it down.
PTZ Patrols?
Manual IR Control?
You get the idea.
Every camera is different. Unless you have some piece of evidence which says otherwise, you cannot assume the commands to do these PTZ functions are the same as any other camera. For example, the script you chose to start with, onvif.pm, uses a command syntax of "/decoder_control.cgi?command={ptz_command}". Unless your camera has the same firmware of some known camera or you have an API document that tells you what the PTZ comamnds are, this camera probably does not accept commands via decoder_control.cgi. It is probably something else, and that is what you have to figure out first before you do anything else.
UPDATE: Google took me to your other ZoneMinder post which mentions the API here: http://www.keekoonvision.com/for-developers-a
Well sure enough, according to that it does use decoder_control.cgi, so here what you should do next:
1) manually build some of those URLs by hand and paste them into your browser. Verify the camera reacts in the way you expect.
2) confirm your Perl script does not have any errors by calling it from the command line:
Code: Select all
perl /path/to/your/script/onvif.pm
3) After completing steps 1 & 2, it is now time to test the script in zoneminder. Before you do that, install and run wireshark. With Wireshark running, try to control the camera from ZoneMinder. You should see the commands go out in plain text. Compare what you see to what the output is really supposed to be.
If you still need help, then we need to see the contents of your ZoneMinder logs, with debug enabled, from the moment prior to opening the monitor to just after your press a PTZ command.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
All of these can be found at https://zoneminder.blogspot.com/
Re: Debugging a Control script
I do know that this works:knnniggett wrote:You are doing this a bit out of order. Put ZoneMinder and Perl aside for the moment.
The first thing you should do is determine what all the available ptz command URLs are for your camera.
-- 8< --
Every camera is different. Unless you have some piece of evidence which says otherwise, you cannot assume ...
Code: Select all
# curl -XGET -u user:pass "http://cam.example.co.uk:80/decoder_control.cgi?command=1
Thanks for the reply, a good session with tcpdump -> Wireshark is on the cards I think. Actually now I come to think of it, pfSense has it built in and I am routing from ZM to the camera - bonus!
Cheers
Jon
- knight-of-ni
- Posts: 2406
- Joined: Thu Oct 18, 2007 1:55 pm
- Location: Shiloh, IL
Re: Debugging a Control script
Yes, pfSense has tcpdump, but the network path between server and camera needs to route through the firewall in order for that instance of tcpdump to see the traffic. If camera and server are on the same local lan, then you will need to install wireshark or tcpdump on the zoneminder server.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
All of these can be found at https://zoneminder.blogspot.com/
Re: Debugging a Control script
Yay - finally got it working. Just need to get it tidied up a bit and get presets working.
Thanks for the comments, sometimes you just need to hear a friendly voice *sob*
Cheers
Jon
Thanks for the comments, sometimes you just need to hear a friendly voice *sob*
Cheers
Jon
- knight-of-ni
- Posts: 2406
- Joined: Thu Oct 18, 2007 1:55 pm
- Location: Shiloh, IL
Re: Debugging a Control script
Glad you got it working.
A couple of things you can do now:
- add the programming steps for this camera to the wiki
- submit your ptz script along with the line of SQL in the dB, which maps the script into the web console, as a pull request on our github site. It will then be included in a future version of zoneminder. https://github.com/ZoneMinder/ZoneMinder
A couple of things you can do now:
- add the programming steps for this camera to the wiki
- submit your ptz script along with the line of SQL in the dB, which maps the script into the web console, as a pull request on our github site. It will then be included in a future version of zoneminder. https://github.com/ZoneMinder/ZoneMinder
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
All of these can be found at https://zoneminder.blogspot.com/
Re: Debugging a Control script
https://wiki.zoneminder.com/Keekoon - done
I dumped the working script in the wiki page along with instructions. Although I have a github account, a sysadmin has to draw the line somewhere. How can I take the piss out of devops if I go around doing pull requests with git? I shall have to refer you to xkcd 1597.
I'll work it out eventually.
By SQL in the DB do you mean the output of: USE zm; SELECT * FROM Controls WHERE Name = "Keekoon"; given my module is called Keekoon ?
Cheers
Jon
I dumped the working script in the wiki page along with instructions. Although I have a github account, a sysadmin has to draw the line somewhere. How can I take the piss out of devops if I go around doing pull requests with git? I shall have to refer you to xkcd 1597.
I'll work it out eventually.
By SQL in the DB do you mean the output of: USE zm; SELECT * FROM Controls WHERE Name = "Keekoon"; given my module is called Keekoon ?
Cheers
Jon
- knight-of-ni
- Posts: 2406
- Joined: Thu Oct 18, 2007 1:55 pm
- Location: Shiloh, IL
Re: Debugging a Control script
You want to create a pull request similar to this:
https://github.com/ZoneMinder/ZoneMinder/pull/1305
What I did there is add the new control script and add one line of sql to the file db/zm_create.sql.in
The required line of sql is copied from the Controls table in your database. You will need to change the integer value of the Id column to NULL. Once you paste the line below all the other control script entries in the sql file, it should be pretty intuitive what it needs to look like by comparing it to the others.
First fork ZoneMinder from the github site
Git commands are:
The github web console will notice you pushed a new branch to your fork and will ask you if you want to do a pull request. Push the green button.
https://github.com/ZoneMinder/ZoneMinder/pull/1305
What I did there is add the new control script and add one line of sql to the file db/zm_create.sql.in
Basically, yes.By SQL in the DB do you mean the output of: USE zm; SELECT * FROM Controls WHERE Name = "Keekoon"; given my module is called Keekoon ?
The required line of sql is copied from the Controls table in your database. You will need to change the integer value of the Id column to NULL. Once you paste the line below all the other control script entries in the sql file, it should be pretty intuitive what it needs to look like by comparing it to the others.
First fork ZoneMinder from the github site
Git commands are:
Code: Select all
cd
git clone https://github.com/{your_github_Account_name}/ZoneMinder
cd ZoneMinder
git checkout -b keekon
cp /path/to/keekon.pm ./scripts/ZoneMinder/lib/ZoneMinder/Control/
#edit db/zm_create.sql.in with new line of sql
cd ~/ZoneMinder
git add .
git commit
#enter a description
git push origin keekon
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
All of these can be found at https://zoneminder.blogspot.com/
Re: Debugging a Control script
Thanks. When I've finished messing around with decking I'll get onto it. It's possible even I can follow instructions that clear.
Cheers
Jon
Cheers
Jon