bartbutenaers / node-red-contrib-onvif-nodes

Node Red nodes for communicating with OnVif compliant IP devices
Apache License 2.0
65 stars 25 forks source link

Problems with PTZ Action Goto Preset Position #36

Closed MarkusHeringlehner closed 6 months ago

MarkusHeringlehner commented 7 months ago

Hello Bart,

thanks for your great Onvif nodes 👍

In principle, the functions I need work great.

I have a small problem with the PTZ node...

With the action "Get preset positions" I am able to read my presets. The response I get is a list of objects, e.g:

House: 1 Yard: 2 ...

I would like to use the "Goto preset position" action. Unfortunately I have not yet been able to configure the action so that the camera moves to the preset position according to my preset.

It would be great if you could give me a tip on what I'm doing wrong!

Thank you!

Best regards Markus

bartbutenaers commented 6 months ago

Hi @MarkusHeringlehner,

Sorry for the delay! I am very short of free time...

What do you man that you have not been able yet to configure the action? Do you get an error, or does your cam does weird things? Or do you need an example flow? Or something else?

Bart

SveinHaDD commented 6 months ago

Hi.

I may have the same problem and have some more information.

All functions reading from camera seems to work great.

setPreset works and is confirmed in the Tapo camera app (position appears in the app and it works as expected).

When using gotoPreset, NodeRed logs "Preset token with name first does not exist." and camera don't move.

Same error log with Tapo C200 and C500 cameras.

Svein.....

Edit: Maybe reading presets from the camera is the problem. In the C500 camera, I have 7 named presets but when invoking "Get Presets" the result is this: {"Preset1":1,"Preset2":2,"Preset3":3,"Preset4":4,"Preset5":5,"Preset6":6,"Preset7":7,"Preset8":8}

SveinHaDD commented 6 months ago

Did a quick and dirty modification of the file onvif-ptz.js from line 386 to remove the error catching and supply a fixed preset number instead:

                        // When the preset token doesn't exists, we cannot goto it ...
                        //if (!preset) {
                        //    console.warn("Preset token with name " + presetName + " does not exist.");
                        //    return;
                        //}
                        console.warn("Options: " + options.preset);
                        options.preset = "3";//preset; 
                        console.warn("Options: " + options.preset);

The camera moved to preset position #3 and in the console log this appeared:

Options: undefined
Options: 3

Hope this helps in locating the real error.

MarkusHeringlehner commented 6 months ago

Hi Bart!

At first - Thanks for your quick response - Great!!!

I would have buyed you a few coffees, but I have no "buy me a coffee account"... Do you got PayPal?

When I try to move my camera to preset Position 2 for example, the camera does nothing ...

According to @SveinHaDD's post, today It took a quick look at the onvif-ptz.js too...

Is it really necessary to call "node.deviceConfig.cam.getPresets(options, function(err, stream, xml)"

I guess in the profileToken for "gotoPreset" there are other parameters than are required for "getPresets"!?

If I take a look in the case "relativeMove" or "gotoHomePosition" the code is a lot easier than the "gotoPreset" Code...

Maybe the problem is located there...

I would be happy if you can fix this issue in the next weeks or if you will send me a sample flow!

Thanks a lot!

Regards - Markus

gotoPreset

                case "gotoPreset":
                    var options = {
                        'profileToken': profileToken
                    };

                    // We will not ask the user to specify the preset token in the input message, to avoid that the preset tokens will
                    // need to be stored somewhere in the Node-Red flow.  Instead the user can specify a preset NAME, and we will lookup
                    // to which existing preset token this name corresponds...
                    node.deviceConfig.cam.getPresets(options, function(err, stream, xml) {
                        // Get the preset token of the specified preset name
                        var preset = stream[presetName];

                        // When the preset token doesn't exists, we cannot goto it ...
                        if (!preset) {
                            console.warn("Preset token with name " + presetName + " does not exist.");
                            return;
                        }

                        options.preset = preset; 

                        // TODO enkel doorgeven indien gedefinieerd.
                        options.speed = {
                            x: panSpeed,
                            y: tiltSpeed,
                            z: zoomSpeed
                        };

                        // Create/update the preset, based on the preset token.  The device will save the current camera parameters
                        // (XY coordinates, zoom level and a focus adjustment) so that the device can move afterwards to that saved 
                        // preset position (via the GotoPreset action).
                        node.deviceConfig.cam.gotoPreset(options, function(err, stream, xml) {
                            utils.handleResult(node, err, stream, xml, newMsg);
                        });
                    });

                    break;                                             

gotoHomePosition

                case "gotoHomePosition":
                    var options = {
                        'profileToken': profileToken,
                        'speed': {
                            'x': panSpeed,
                            'y': tiltSpeed,
                            'zoom': zoomSpeed
                        }
                    };

                    // Let the camera go to the home position.
                    // Make sure a home position is set in advance, otherwise you get a 'No HomePosition' error.
                    node.deviceConfig.cam.gotoHomePosition(options, function(err, stream, xml) {
                        utils.handleResult(node, err, stream, xml, newMsg);
                    });

                    break;
bartbutenaers commented 6 months ago

Hi @SveinHaDD,

Thanks for joining! That REALLY helps a lot...

When using gotoPreset, NodeRed logs "Preset token with name first does not exist." and camera don't move.

I see in your error message that this node has been instructed to go to the preset position with name "first", but that hasn't been created yet on your camera:

image

Could this - hopefully ... - be due to incorrect usage of my example flow perhaps?

image

At the time being I made this flow to use it like this:

  1. You inject a message to create a preset location with the name "first".
  2. You inject a message to goto the preset location with the name "first".

So in step 2 you go to the preset position with the SAME name as you have created in step 1.

Could it be perhaps that the preset location name has not been changed in step 2?

have 7 named presets but when invoking "Get Presets" the result is this: {"Preset1":1,"Preset2":2,"Preset3":3,"Preset4":4,"Preset5":5,"Preset6":6,"Preset7":7,"Preset8":8}

I have no idea where the extra preset name could be fetched. Are you sure you have only 7 preset locations?

Do you got PayPal?

No I quitted my Paypal account a month ago, because the cooperation between bymeacoffee and paypal has been interrupted. Anyway the amount of people that take the time to buy a coffee is very disappointing low, so don't worry about that!!

Is it really necessary to call "node.deviceConfig.cam.getPresets(options, function(err, stream, xml)"

It is too long ago. Can't remember the exact details anymore, without digging into it again. But at first sight most of the ptz functions use a similar mechanism, so I assume it should work (since the other functions also work for the both of you.

Could you also check my first comment about the preset name "first" in the change node of step 2. Otherwise I have no idea yet where the preset name "first" would be defined...

SveinHaDD commented 6 months ago

Hi @bartbutenaers

Sorry for not expressing myself more clearly.

My Tapo cameras have 8 preset positions. I had occupied 6 and your flow example occupied position 7 with the name "first". When I open my Tapo app, position 7 exists and is named "first" and it also works as expected from the app. So far so good...

When reading presets from the camera, I get: {"Preset1":1,"Preset2":2,"Preset3":3,"Preset4":4,"Preset5":5,"Preset6":6,"Preset7":7,"Preset8":8}

This tells me that the names is unreadable for some reason since all preset names is shown as preset number.

For my use, the preset number is doing the job well enough as a workaround if this is easier to implement, I don't need to use preset names.

Somewhere in the code, there seems to be some kind of glitch that is unable to read the preset names and therefore exits with "Preset token with name first does not exist." even when the preset "first" really exists in the camera.

setPreset works, removePreset don't

MarkusHeringlehner commented 6 months ago

Hi, @bartbutenaers, @SveinHaDD

Thanks for your Information... My problem got solved 👍

  1. Primary I had stored a few presetPositions on the Camera by using the Manufacturer CameraInterface (Webinterface / App).
  2. I tryed to use the NodeRed PTZ action "gotoPosition", but nothing happened...
  3. After reading SveinHa's post, I tryed to set the same positions (as stored with the Manufacturer CameraInterface) by using NodeRed PTZ action "setPosition" (with the same parameters and names) -> It works like magic - Perfect!

For me this issue is done -> @SveinHaDD please close Issue when done or create new issue - Thanks!!!

Thanks Bart - You did a great job - I like your work (Please tell me if you reopen a PayPal account -> I would have bought you a few coffees if I had an account...!)

bartbutenaers commented 6 months ago

@MarkusHeringlehner, Glad to hear that it works for you now!! Hopefully we still can solve the root case, so you don't need workarounds...

@SveinHaDD, I have no idea why you cannot read the preset names from your cam. Is it a bug in my code, or a bug in the onvif library that this node uses, or a bug in the Tapo cam Onvif firmware. No idea...

If you want, I can 'try' to debug it myself. If you can somehow make one of your cams available public on your router, so I can access it and debug the flow. No success garanteed!!! If you want me to do this, you can can contact me on Discourse and send me a private message with the connection details. Please use a cam that doesn't reveal me too much information about your private life ;-)

SveinHaDD commented 6 months ago
  1. After reading SveinHa's post, I tryed to set the same positions (as stored with the Manufacturer CameraInterface) by using NodeRed PTZ action "setPosition" (with the same parameters and names) -> It works like magic - Perfect!

No successs for me... I deleted all preset positions, created "first" and "second" preset but when trying to go to these presets, nothing happens with the camera (exactly the same with c200 and c500 cameras) and console log show these messages:

Preset token with name first does not exist.
Preset token with name second does not exist.

If you want, I can 'try' to debug it myself. If you can somehow make one of your cams available public on your router, so I can access it and debug the flow. No success garanteed!!! If you want me to do this, you can can contact me on Discourse and send me a private message with the connection details. Please use a cam that doesn't reveal me too much information about your private life ;-)

That would be great Bart.

I can open a port in my router (which port(s) do you need?) for NodeRed access and if you create a Tapo account, I can share one camera with you (never done it but I believe you shoule get a fairly ok access directly to the camera this way).

MarkusHeringlehner commented 6 months ago

Hi @SveinHaDD

In your comment https://github.com/bartbutenaers/node-red-contrib-onvif-nodes/issues/36#issuecomment-1855407475 you wrote, that you have modified the onvif-ptz.js with preset position "3" and your camera moved.

In the comment before you wrote, that when you call the action "getPresets" you got the answer "Preset1":1,"Preset2":2,"Preset3":3,"Preset4":4,"Preset5":5,"Preset6":6,"Preset7":7,"Preset8":8

I think now you will get the answer "first": 1, "second": 2, and so on...

On my camera test yesterday I set some new presents by using the action setPreset. In my tests before I had set all presets by using the camera app.

For example, I set the preset "Test": 9 and used afterwards the gotoPreset action with presetName 9 and it worked!

I hope this will help!

Regards - Markus

SveinHaDD commented 6 months ago

Thanks Markus. I just need to find out where the preset name or number originates. The way I did it, it was a fixed number that was not settable from NodeRed. Preset number is fine for me but it need to be a bit better implemented than what I did for testing.

Next week, I will have quite a bit more spare time...

bartbutenaers commented 6 months ago

I can open a port in my router (which port(s) do you need?) for NodeRed access and if you create a Tapo accoun

I assume that it would be enough if you do port forwarding on your router of the port that you have configured in the onvif config node screen, towards the ip address of your camera. Then hopefully I can access it from my Node-RED flow. And if you can share a username/password via Discourse private message. I am not going to start installing and learning the Tapo app, since I have no time to play with my own camera's. Hope you understand...

SveinHaDD commented 6 months ago

Port opened and details sent on Discourse.

FYI: Those cameras that I manage that is connected to BlueIris, I can do PTZ control, both manually and gotoPreset, both directly from BlueIris UI and from NodeRed via MQTT to BlueIris so ONVIF control of these cameras do work.

I also manage a couple of cameras NOT connected to BlueIris and those need the NodeRed ONVIF-nodes to work..

bartbutenaers commented 6 months ago

After spending some time with @SveinHaDD on Discourse, we finally figured out together what was going wrong. The readme page has been updated to explain the difference between preset names and preset tokens, to avoid that others make the same mistake in the future...