QuantumEntangledAndy / neolink

An RTSP bridge to Reolink IP cameras
GNU Affero General Public License v3.0
297 stars 44 forks source link

Fix/ptz stop #72

Closed AdrianosBates closed 1 year ago

AdrianosBates commented 1 year ago

Everything seems to be working as intended, and I am now able to stop my camera using MQTT after issuing a PTZ command. The code changes are relatively minor, but I am not very familiar with Rust. On a slightly related note, I added the unrecognized command to the error message and found that an 'ok' MQTT message is being passed through after every PTZ MQTT message, although I'm not familiar with how the MQTT works so I can't say why this is.

Fix #71

QuantumEntangledAndy commented 1 year ago

Do you think t would be better if instead of issueing start/stop we instead did it as move amount. Where we get neolink to issue the stop itself after the right time.

AdrianosBates commented 1 year ago

Technically this is the native way that Reolink implements the commands, but I think that in the context of sending MQTT commands it would make sense to perhaps provide another variable for a move amount, or how long the camera should move. Also, the currently existing speed/amount variable seems to have no effect, but maybe that's just my camera.

Providing a seconds to move parameter along with the speed and stopping after the seconds have elapsed would be fairly flexible and intuitive I think.

AdrianosBates commented 1 year ago

As suggested, I have committed my (perhaps naïve) implementation of the above functionality. It seems to work well in my testing and is much easier to control.

QuantumEntangledAndy commented 1 year ago

Rather than seconds can we do distance like this.

ptz up distance speed

Speed should be optional at 32

Internally we convert distance to a time so the code can mostly be the same

time = distance / speed

Sorry I can't do this myself my laptop need to get repaired so I can't code much for a week.

Also with the current code we sleep the camera control thread. This means we can't get process any new new message util after it is done. This has some advantages such as stopping simultaneous moves and being able to wait for an OK when it is done but it might cause issues. When I get my laptop back I'm thinking to move the ptz onto a thread and using some sort of locking to stop simultaneous moving. But doing this means we get OK back straight away even if PTZ fails.

AdrianosBates commented 1 year ago

No worries, I appreciate the input and I'm glad to make any changes I'm capable of. I'm not very familiar with async code, especially with how it's implemented in neolink so I figured there might be some issue with sleeping the thread.
I'll test a bit make these changes soon.

QuantumEntangledAndy commented 1 year ago

Probably want something like this;


tokio::task::spawn(async move {
//code to send start move
//code to sleep
//code to send stop 
};
QuantumEntangledAndy commented 1 year ago

Did you make any more progress with this? If you have any issues with the rust/async you could share them and I'll try to help.

QuantumEntangledAndy commented 1 year ago

I pushed some commits that should allow us to sleep by moving all the mqtt messages into their own seperate async task.

I also made the commands work based on distance rather than speed and time should be more intuitive

works like

control/ptz down control/ptz down 10

default movement it 32 smallest is 1

QuantumEntangledAndy commented 1 year ago

@AdrianosBates I am planning to merge it with my changes unless there is something you want to add?

AdrianosBates commented 1 year ago

All good with me. Thanks for picking this up. Did you happen to figure out why 'ok' messages where being passed through to MQTT during your time with this? Perhaps a different issue to be opened if not.

QuantumEntangledAndy commented 1 year ago

Yeah it is the reply on success (ok and fail on error), I need to filter out the replies

QuantumEntangledAndy commented 1 year ago

Is there a standard way to report success/fail in mqtt? I am not too familiar with what else is done with it

QuantumEntangledAndy commented 1 year ago

Ok I have got the filter in now. I will wait for the checks to pass one last time then merge. Thanks for your help here.

I don't suppose your camera has zoom? I'd like to get the controls for zoom but none of my cameras have it

QuantumEntangledAndy commented 1 year ago

Ok it's in master, i'll make a new release for this as 0.5.10

QuantumEntangledAndy commented 1 year ago

If you have any other ideas/fixes for neolink feel free to add/discuss them

sanchosk commented 1 year ago

@AdrianosBates Hi. Do you have any ko-fi account? I'd like to express my thanks for the fix that made the Reolink usable :)

AdrianosBates commented 1 year ago

@AdrianosBates Hi. Do you have any ko-fi account? I'd like to express my thanks for the fix that made the Reolink usable :)

@sanchosk Sure, I've updated my GitHub profile. Although, @QuantumEntangledAndy deserves much of the credit for this and the entire updated repo.

I don't suppose your camera has zoom? I'd like to get the controls for zoom but none of my cameras have it

@QuantumEntangledAndy Unfortunately not, although in the future I may end up buying the E1 Outdoor in which case I will check it out.

QuantumEntangledAndy commented 1 year ago

Sure, I've updated my GitHub profile. Although, @QuantumEntangledAndy deserves much of the credit for this and the entire

He was kind enough to donate to me too, thought I'd drop your name too since you did most of the hard work for this PR. (Thank you very much to both of your help/support)

Unfortunately not, although in the future I may end up buying the E1 Outdoor in which case I will check it out.

That would be great, I've had a few people use PT but noone actually owns a Z one. Theres also diagonal movements for UPLEFT etc but they don't seem to do anything on my camera.

Shoud also add the PTZ save and apply preset feature at some point to