QuantumEntangledAndy / neolink

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

Awaking through notification works for a limited time #166

Closed Adammantium closed 5 months ago

Adammantium commented 1 year ago

Describe the bug Hello, its me again, sorry to bother you again. I had a issue with the cameras not going to idle a few days ago, now i have to opposite issue. The notification waking doesn't seem to work properly. If i start the program it will work for half an hour or something, but then it wont wake up again. I also tried resetting the neolink_token.toml with no change in behaviour.

To Reproduce Steps to reproduce the behavior. Example:

  1. Create this configuration file:
    
    bind = "0.0.0.0"

[mqtt] broker_addr = "127.0.0.1" # Address of the mqtt server port = 1883 # mqtt servers port credentials = ["main", "qnuVMFNj0sfkGOgUhCgmJnGNofAYQV"] # mqtt server login details

[[cameras]] name = "reolink1" username = "admin" password = """ uid = "" address = ""****.151" stream = "both" idle = true discovery = "local"

[[cameras]] name = "reolink2" username = "admin" password = """ uid = """ address = ""****.157" stream = "both" idle = true discovery = "local"

[cameras.mqtt.discovery] topic = "homeassistant" features = ["camera", "ir", "motion", "battery"]


2. Launch Neolink: neolink mqtt --config ...

**Expected behavior**
The cameras will wake up by the notification.
I tested it on 2 different phones, they are getting the reolink app notification, just the neolink service wont wake up.

**Versions**
NVR software:
Neolink software: c09bc13598552c3d2a026a3abd422f1c83330bff (+last few version of the [feature/push_mqtt](https://github.com/QuantumEntangledAndy/neolink/tree/feature/push_mqtt) branch)
Reolink camera model and firmware: Reolink Argus Eco (v3.0.0.1981_23040606)
OS: Linux Debian 12

[Log.txt](https://github.com/QuantumEntangledAndy/neolink/files/12805433/Log.txt)
Let me know if you need any of the IDs or if i can test some other stuff.
QuantumEntangledAndy commented 1 year ago

Lets try something in the log there is a push notification UID: [PUSH_NOT_ID_2] that UID is something we generate when registering

Can you run this command in the terminal (assuming you have curl installed)

curl -X GET 'https://pushx.reolink.com/listeners/[PUSH_NOT_ID_2]/devices' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept: */*' -H 'Accept-Language: en-GB,en; q=0.9' -H 'Cookie:'

It will ask reolink to report on all cameras registered with that push id, so we can see if reolink unregistered it

Success should look something like this

{"status":{"code":0,"detail":"OK"},"data":[{"uid":"UID","secret":"CHARS"}]}
Adammantium commented 1 year ago

Seems to work fine:

{"status":{"code":0,"detail":"OK"},"data":[{"uid":"uui of cam 1","secret":"..."},{"uid":"uuid of cam 2","secret":"..."}]}

I can send you the uncensored stuff via mail if you need it.

Adammantium commented 1 year ago

I just checked pi hole and i can see the server is definitely doing something: image Nothing in the neolink log, but its pulling the pushx domain.

Edit: nvm... it was the command i executed, but at least the domain isnt blocked.

QuantumEntangledAndy commented 1 year ago

Then I'm not quite sure. Perhaps I am meant to reregister the FCM from time to time, but I havent seen anything to indicate that I should do that

Adammantium commented 1 year ago

If you send me like a curl command i can try sending it manually via cron and ill see if that helps. The google domains are contacted successfully when starting: image

QuantumEntangledAndy commented 1 year ago

Most of this I just delegate to https://github.com/RandomEngy/fcm-push-listener

Can you tell if the socket to mtalk.google.com:5228 is kept open?

Adammantium commented 1 year ago

Seems like its open:

tcp   ESTAB      0      0    192.168.178.10:52676   108.177.15.188:5228
tcp   ESTAB      0      0    192.168.178.10:52690   108.177.15.188:5228
QuantumEntangledAndy commented 1 year ago

Do you know if you are in the connected or disconnected state? When you get a push notfication, perhaps it dosent' send if the camera says we are connected to them

Adammantium commented 12 months ago

I will check it again, we just got some new cameras, i will try it with them so i dont have to run outside the whole time :)

Adammantium commented 12 months ago

Okay, so, i just did some testing, the notifcations didnt work at first while it was connected, it looked like motion stayed off, wenn the cameras disconnected and i waved infront of cam 3, it reconnected cam 1 and updated the notification on there, cam 3 stayed disconnected with the old notification.

Adammantium commented 12 months ago

image

Adammantium commented 12 months ago

Okay, now its not working anymore at all, i left it disconnected for 30 minutes. No camera is waking up now, but the notification on the phone still works. The sockets are still open and connected as well.

QuantumEntangledAndy commented 12 months ago

So basic things to ask.

Adammantium commented 12 months ago
  • Has the last will been sent (offline on the neolink/status)

neolink status is on connected image

  • is there anything in the log about any threads stopping?

Nope, nothing, last message is the shutdown stuff:

Okt 05 14:09:04 srv neolink[1511486]: [2023-10-05T12:09:04Z DEBUG neolink::common::neocam] reolink3: Idle
Okt 05 14:09:04 srv neolink[1511486]: [2023-10-05T12:09:04Z DEBUG neolink::common::neocam] reolink3: Disconnect On Request
Okt 05 14:09:04 srv neolink[1511486]: [2023-10-05T12:09:04Z DEBUG neolink_core::bc_protocol::connection::bcconn] BcConnection::shutdown Cancel
Okt 05 14:09:04 srv neolink[1511486]: [2023-10-05T12:09:04Z DEBUG neolink_core::bc_protocol::connection::udpsource] UdpPayloadInner::new SendToSocket Cancel
  • does it reconnect when you use mqtt explorer to post the neolink/camname/query/preview message

Yes, this works perfectly fine, will immediately connect the camera and update the preview. It wont update the notification nor will it fix the issue with waking up, it will still not wake on notification as soon as its disconnected again.

QuantumEntangledAndy commented 12 months ago

Sure I just wanted to check if the wake up was broken, these sort of question help narrow down the source. So if I an understanding this right it just wakes up one of the cameras? Perhaps I need to change the push UID to be unique for each camera or do it from a central interface

Adammantium commented 12 months ago

So in summary:

Maybe you dont need different UIDs for each camera and the push notification. It seems like the notification itself contains the UID already, so you can probably determine the camera this way. I dont know if its already using that.

QuantumEntangledAndy commented 12 months ago

Yes thats the alternative to create central fcm receiver and pass the messages to the right camera. Would be a larger refractor though and would mean also storing the UID somewhere in the camera data which I don't actual do atm. So going to make them unique first

Adammantium commented 12 months ago

Do you think it might have something to do with my setup? If you want i can do some more testing before you rewrite your code, just to be sure.

Adammantium commented 12 months ago

I just restarted neolink and tested again, now camera 2 reacted to motion of camera 3. So its probably the last socket that got connected for push notifications that will handle all notifications.

QuantumEntangledAndy commented 12 months ago

Im going to put in the work to make a central push notification receiver since I want only the one config file and having it read/write by three different threads at once is just asking for race errors.

Adammantium commented 12 months ago

I really appreciate the effort

QuantumEntangledAndy commented 12 months ago

Can you see if this one works for the push notifications I think it is but need extra tests

Adammantium commented 12 months ago

It seems like I can't download the builds anymore. The builds on the buttom don't let me click them anymore. Can you send me a direct link to the amd64 linux file?

Adammantium commented 12 months ago

Okay, i was able to download it from my phone. I will test it later today :)

QuantumEntangledAndy commented 12 months ago

Have to be logged in to see a download link so maybe it was that. Or maybe it wasn't built yet. Sometimes I send a link while building, usually when I need to do something else and don't have time to follow up.

Adammantium commented 12 months ago

Yeah, i wasn't logged in. That was probably it.

I tested the version, and the issue seems to be the same. After about half an hour the cameras dont wake up again, no messages in the console. I'm currently not at home so I can't check MQTT directly.

I will do some more testing in about 6 hours.

Adammantium commented 12 months ago

I haven't completely tested if its waking up the correct camera yet. But from what i was seeing inside the log, it seems to be working.

Adammantium commented 11 months ago

Okay, i tested it some more. So its waking up the correct camera that triggered the notification and its only updating the notification on that specific camera in MQTT. But its still not waking them up if they have idled for like 30 minutes. No messages inside the log as well.

Adammantium commented 11 months ago

Just tested the Neolink 0.6.3-rc.1. It seems to be working and is waking up the cameras on notification now. But it also wakes them up every few minutes draining the battery. Is there a option im missing?

QuantumEntangledAndy commented 11 months ago

I noticed that too. I think it's the re-re-registration of the push notifications. Think of got it fixed on my testing branch but haven't had a chance to actually test it.

Adammantium commented 11 months ago

Let me know if you need someone to test it

QuantumEntangledAndy commented 11 months ago

Sure try this build

Adammantium commented 11 months ago

Just tested the build, it still wakes up the camera every few minutes without a notification. Seems like the reregistering of the notification will receive the last notification the camera send. So its waking up the camera again, maybe you need to remember the timestamp or something from the last notification and only wake up from a notification if its not the same as the last one.

QuantumEntangledAndy commented 11 months ago

We cache the uid of the notification to filter them. But Perhaps it's in the notification part further down if it's restarting because of an error.

Adammantium commented 11 months ago

I checked the log, I can't see any errors. I'll send it later

Adammantium commented 11 months ago

neolink.log

Adammantium commented 5 months ago

Any update on this? Seems like the current master branch is pretty solid. Sometimes I'm having the issue that a few cams keep getting activated. It seems to happen as soon as the first notification comes in, it will always trigger with the same notification, even hours after the specified Alarm Time inside the notification. It just seems like its getting stuck with that one notification. Maybe it's not getting dismissed and it keeps to be sent to neolink? Is there a way to clear the notifications?

Edit: Seems like its the same issue as in #235. I wouldn't mind waking up my cameras every hour or so, maybe we can make the delay configurable for now?

QuantumEntangledAndy commented 5 months ago

I actually have a fix in on another branch. I'm just waiting on some reports from other users about stability

Adammantium commented 5 months ago

What branch is it? I would be happy to test :)

Edit: I will be using the fix/argus3_disc branch, just has a lot of logging :D

QuantumEntangledAndy commented 5 months ago

I think the argus3_disc does indeed have it. Just be aware that the docker on that one has been modified to record memory profile data and only runs for half an hour on docker at a time.

Adammantium commented 5 months ago

For the last day it was working flawlessly. The cameras woke up on movement and my push notifications through home assistant where pretty much on point. There was no high battery drain, they even charged by 2-3%. I will reopen this ticket if the issue comes back, but for now i consider it solved!

Thank you 👍

Adammantium commented 5 months ago

Update: Still running perfectly fine, no restarts needed, no battery drain