neolink icon indicating copy to clipboard operation
neolink copied to clipboard

Mqtt battery draining

Open jl1990 opened this issue 2 years ago • 22 comments

Describe the bug MQTT keeps the cameras active and drains the battery

To Reproduce Steps to reproduce the behavior. Example:

  1. Run MQTT
  2. Cameras will never be disconnected and battery drainage will happen

Expected behavior MQTT server should keep running, but cameras should be disconnected when we are not using them. Reconnection could be done when we need to execute a command in any of them.

Versions NVR software: - Neolink software: Last version Reolink camera model and firmware: Argus 3 pro

jl1990 avatar Apr 20 '23 19:04 jl1990

The issue with doing that is, if we are not connected how do we monitor the motion detection. We need to be logged in to get the motion events

QuantumEntangledAndy avatar Apr 20 '23 22:04 QuantumEntangledAndy

The issue with doing that is, if we are not connected how do we monitor the motion detection. We need to be logged in to get the motion events

Sir, can you leverage the email trigger to avoid needing to stay connected? Maybe using new-tokio-smtp or similar. Sorry if that was asked about previously and did not make sense.

Hoppersusa avatar Apr 21 '23 01:04 Hoppersusa

Maybe. Id also like to investigate the push messages. I suspect that the camera sends messages to Reolink for that so maybe we can get updates from there.

QuantumEntangledAndy avatar Apr 21 '23 01:04 QuantumEntangledAndy

Push would be ideal if you can leverage that.

Hoppersusa avatar Apr 21 '23 02:04 Hoppersusa

Yes, what you guys mention sounds great also and meanwhile something like that is investigated and implemented, maybe it's possible to turn off motion if you don't use it (my case) by config. My main use case is enable/disable the cameras and checking their pir status for the moment. For the motion events I already receive email + notifications from the app.

jl1990 avatar Apr 21 '23 07:04 jl1990

I'll see about making the motion optional and issuing it more as a on demand client instead. Maybe I can put a command for explicit connect/disconnect for the camera. Then you can tell mqtt when to listen and when your done issuing command for now.

QuantumEntangledAndy avatar Apr 25 '23 07:04 QuantumEntangledAndy

I'm in the process of reverse engineering the push notifications. I have worked out the messages for my ios device, but I've hit a problem. I can emulate a push receiver for google (andriod) but not for ios. To continue I would need to observe the packets from an andriod to the camera.

For IOS it is this:

<?xml version="1.0" encoding="UTF-8" ?>
<body>
<PushInfo version="1.1">
<token>PHONES_UNIQUE_APNS</token>
<phoneType>reo_iphone</phoneType>
<clientID>SOMEID</clientID>
</PushInfo>
</body>

Does anyone here have an andriod and the ability to intercept packets sent from their andriod to their camera?

I'll try some things like guessing the phoneType as reo_andriod etc and see where it goes but official confirmation would be easier

QuantumEntangledAndy avatar May 18 '23 07:05 QuantumEntangledAndy

I found some references to:

reo_fcm

as clientType.

jl1990 avatar May 18 '23 17:05 jl1990

Thanks I dumped the apk and found that too. It seems to accept the message now. But it is still not sending me the actual push messages. I'm wondering if I need to base64 encode the token or anything.

QuantumEntangledAndy avatar May 18 '23 22:05 QuantumEntangledAndy

Tracking this in #85

QuantumEntangledAndy avatar May 19 '23 06:05 QuantumEntangledAndy

PhoneType has a typo, it should be "Android" although I am sure this is not the problem. Just warning

jl1990 avatar May 19 '23 07:05 jl1990

That's just the selection option. What matters is the reo_fcm bit

QuantumEntangledAndy avatar May 19 '23 07:05 QuantumEntangledAndy

But yeah my typos are everywhere

QuantumEntangledAndy avatar May 19 '23 07:05 QuantumEntangledAndy

Hi,

Any update on this? Can we help somehow?

Thanks

jl1990 avatar Jun 19 '23 16:06 jl1990

Mostly I just don't have a lot of time. I do little things I can here and there.

If you can code your welcome to have a go at getting it started.

Easiest change would probably be adding a command to start and stop the camera and its associated threads. (The eventcam stuff)

QuantumEntangledAndy avatar Jun 19 '23 16:06 QuantumEntangledAndy

For anyone coming to this issue. With 0.6.1 we have the the mqtt topic neolink/config you can enable/disable or add/revove cameras in this config through mqtt to force a disconnect and help save battery.

QuantumEntangledAndy avatar Sep 24 '23 07:09 QuantumEntangledAndy

WIP disconnect on idle is on the branch feature/push_mqtt current build seems to be working.

Needs the following idle_disconnect = true in the toml

[[cameras]]
# usual options like name and pass
idle_disconnect = true

On no active users/motion for 30s is will disconnect the camera. When an active user OR a push notification is received it will reconnect

You can watch it in the mqtt at neolink/camname/status will swap from connected to disconnected also the last push notification raw json data is dumped into neolink/camname/notification

QuantumEntangledAndy avatar Sep 26 '23 07:09 QuantumEntangledAndy

Finally got it to build on github here you might need to install openssl

QuantumEntangledAndy avatar Sep 26 '23 13:09 QuantumEntangledAndy

So does this mean, the camera will never sleep, when mqtt is connected/enabled right now?

When talking about "active user" does this mean RTMP?

I mean, I am using Frigate and want to send the cam to sleep as long as the PIR is not detecting motion. When motion is detected, the camera should wake up and it's video stream should be analyzed by frigate. But of course frigate keeps an open connection to neolink for this.

fsedarkalex avatar Oct 13 '23 23:10 fsedarkalex

Ok so the feature for idle disconnect is still in active development, it not in any formal release or on the main branch


The definition of active use depends on your config.

If you run just mqtt and idle_disconnect it will be disconnected 90% of the time unless you send a command over mqtt, inwhich case it will wake up the camera to run your command

If you have rtsp active, then your settings for on_motion and on_client matter, if both motion and clinet are false it will stay connected at all times. if eitehr motion or client are true then it will disconnect if there is neither motion detected or client connected.

Current issues:

  • Clients dropping us during pause, no frames are send so most clients e.g. frigate will drop up
  • BI client has a weird gray screen not sure why, don't own a windows to test this
  • Push notification thread is stopping, we use push notificaitons to wake up on motion, but for some reason the fcm listener stops working after about half an hour

QuantumEntangledAndy avatar Oct 14 '23 03:10 QuantumEntangledAndy

Thank you @QuantumEntangledAndy for the detailed clarification! This puts the puzzle pieces together.

Great work so far!

fsedarkalex avatar Oct 14 '23 21:10 fsedarkalex

For the BI issue... Maybe I have a similar issue with the branch version on Frigate now.

In Camera overview I can see a single frame and in "Bird View" (which should sho a live stream) the respective frame stays all white. Seems like ffmpeg is crashing.

2023-10-14 22:27:03.279752593  [2023-10-14 22:27:03] frigate.app                    INFO    : Output process started: 424
2023-10-14 22:27:03.279756590  [2023-10-14 22:27:03] frigate.app                    INFO    : Camera processor not started for disabled camera frontdoor
2023-10-14 22:27:03.289736701  [2023-10-14 22:27:03] frigate.app                    INFO    : Camera processor started for einfahrt: 427
2023-10-14 22:27:03.289741490  [2023-10-14 22:27:03] frigate.app                    INFO    : Capture process not started for disabled camera frontdoor
2023-10-14 22:27:03.299281445  [2023-10-14 22:27:03] frigate.app                    INFO    : Capture process started for einfahrt: 429
2023-10-14 22:27:10.606798182  [2023-10-14 22:27:10] frigate.video                  ERROR   : einfahrt: Unable to read frames from ffmpeg process.
2023-10-14 22:27:10.607002706  [2023-10-14 22:27:10] frigate.video                  ERROR   : einfahrt: ffmpeg process is not running. exiting capture thread...
2023-10-14 22:27:23.328616233  [2023-10-14 22:27:23] watchdog.einfahrt              ERROR   : Ffmpeg process crashed unexpectedly for einfahrt.
2023-10-14 22:27:23.328714508  [2023-10-14 22:27:23] watchdog.einfahrt              ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
2023-10-14 22:27:23.328789087  [2023-10-14 22:27:23] ffmpeg.einfahrt.detect         ERROR   : rtsp://*:*@192.168.XXX.YYY:9999/Einfahrt/sub: Operation not permitted
2023-10-14 22:27:30.753542194  [2023-10-14 22:27:30] frigate.video                  ERROR   : einfahrt: Unable to read frames from ffmpeg process.
2023-10-14 22:27:30.753699620  [2023-10-14 22:27:30] frigate.video                  ERROR   : einfahrt: ffmpeg process is not running. exiting capture thread...
2023-10-14 22:27:33.344056648  [2023-10-14 22:27:33] watchdog.einfahrt              ERROR   : Ffmpeg process crashed unexpectedly for einfahrt.
2023-10-14 22:27:33.344153660  [2023-10-14 22:27:33] watchdog.einfahrt              ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
2023-10-14 22:27:33.344230053  [2023-10-14 22:27:33] ffmpeg.einfahrt.detect         ERROR   : rtsp://*:*@192.168.XXX.YYY:9999/Einfahrt/sub: Operation not permitted
2023-10-14 22:27:38.471297188  [2023-10-14 22:27:38] frigate.video                  ERROR   : einfahrt: Unable to read frames from ffmpeg process.
2023-10-14 22:27:38.471384282  [2023-10-14 22:27:38] frigate.video                  ERROR   : einfahrt: ffmpeg process is not running. exiting capture thread...
2023-10-14 22:27:43.361065413  [2023-10-14 22:27:43] watchdog.einfahrt              ERROR   : Ffmpeg process crashed unexpectedly for einfahrt.
2023-10-14 22:27:43.361156725  [2023-10-14 22:27:43] watchdog.einfahrt              ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
2023-10-14 22:27:43.361213110  [2023-10-14 22:27:43] ffmpeg.einfahrt.detect         ERROR   : rtsp://*:*@192.168.XXX.YYY:9999/Einfahrt/sub: Invalid data found when processing input

For reference: My neolink is binding to port 9999 as it's running on the same server as frigate is. I am running it on docker in host network mode using local discovery

I find the "Operation not permitted" error interesting. This is not happening with the release version. It is specific to the push branch.

//Edit: But on HomeAssistant, the stream which I am pulling from Frigate is working. But it is way slower than it used to be. Feels like one frame every two or three seconds. So maybe its reconnecting all the time

//Edit 2: The stream is not stable on VLC, too. It has a huge delay (more than with release version) of about 20 seconds and you can see the stream sometimes hangs fo a few seconds. You see even the timer in VLC hopping sometimes. VLC is running for 5 minutes now and the timer IN VLC only shows 3:30. And it sometimes jumps back 1 or 2 seconds and continues from there. Very weird.

I did all this while constantly having motion in front of the cam. so the disconnects are NOT supposed disconnects.

fsedarkalex avatar Oct 14 '23 22:10 fsedarkalex