QuantumEntangledAndy / neolink

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

Registering new push notification token: Error("missing field `token`", line: 7, column: 1) }) #288

Open si458 opened 1 month ago

si458 commented 1 month ago

Describe the bug i keep getting these error logs inside the docker image

[2024-08-08T14:58:15Z DEBUG neolink::common::pushnoti] Registering new push notification token
[2024-08-08T14:58:22Z WARN  neolink::common::pushnoti] Issue connecting to push notifications server: Http(reqwest::Error { kind: Decode, source: Error("missing field `token`", line: 7, column: 1) })
[2024-08-08T14:58:25Z DEBUG neolink::common::pushnoti] Push notification details are saved to Some("/root/.config/neolink/./neolink_token.toml")

but checking /root/.config/neolink/./neolink_token.toml reveals the is no file? and also im not getting any push notifications either from my device when events happen?

To Reproduce Steps to reproduce the behavior. Example:

bind = "0.0.0.0"
[mqtt]
broker_addr = "core-mosquitto" # Address of the mqtt server
port = 1883 # mqtt servers port
credentials = ["simon", "password"] # mqtt server login details
[[cameras]]
name = "frontdoor"
username = "admin"
password = "password"
uid = "952700XXXXXXXX"
address = "192.168.23.226"
stream = "subStream"
idle_disconnect = true
[cameras.pause]
on_client = true # Should pause when no rtsp client
[cameras.mqtt]
enable_motion = true  # motion detection
enable_light = false   # flood lights only avaliable on some camera
enable_battery = true # battery updates in `/status/battery_level`
enable_preview = true # preview image in `/status/preview`
enable_floodlight = false # preview image in `/status/floodlight_tasks`
battery_update = 60000  # Number of ms between `/status/battery_level` updates
preview_update = 60000  # Number of ms between `/status/preview` updates
floodlight_update = 60000 # Number of ms between `/status/floodlight_tasks` updates
[cameras.mqtt.discovery]
topic = "homeassistant"
features = ["battery","reboot","camera","motion"]

Expected behavior i was expecting to be able to get notifications and then the battery/image/motion to refresh in mqtt but never happens

Versions

[2024-08-08T15:04:22Z INFO  neolink] Neolink f15fdaefbcfe5cde3b0289c1e106cb85f6d3d39b release
neolink version: neolink 0.6.3-rc.3
neolink mode: mqtt
neolink log: debug

Reolink camera model and firmware: Argus Pro 1202_491_352_28

si458 commented 1 month ago

OK I think the issue is coming from the fact it's adding a fullstops in the file name https://github.com/QuantumEntangledAndy/neolink/blob/master/src%2Fcommon%2Fpushnoti.rs#L103

si458 commented 1 month ago

@QuantumEntangledAndy this is the full output running in debug mode (im using the HA addon which just uses the :latest docker image) and as explained the token file is NEVER created, the file isnt there?

Running: /run.sh
--- VERSIONS ---
add-on version: 0.0.1
[2024-08-09T06:39:22Z INFO  neolink] Neolink f15fdaefbcfe5cde3b0289c1e106cb85f6d3d39b release
neolink version: neolink 0.6.3-rc.3
neolink mode: mqtt
neolink log: debug
ATTENTION: if you expected a newer Neolink version, please reinstall this Add-on!
--- Neolink ---
[2024-08-09T06:39:22Z INFO  neolink] Neolink f15fdaefbcfe5cde3b0289c1e106cb85f6d3d39b release
[2024-08-09T06:39:22Z DEBUG neolink::mqtt::mqttc] MQTT Published Startup
[2024-08-09T06:39:22Z INFO  neolink::mqtt] frontdoor: MQTT Starting
[2024-08-09T06:39:22Z INFO  neolink::utils] frontdoor: Connecting to camera at Address: 192.168.23.226, UID: 9527000XXXXXXXX
[2024-08-09T06:39:22Z DEBUG neolink::mqtt::discovery] Enabling MQTT discovery for frontdoor
[2024-08-09T06:39:22Z INFO  neolink_core::bc_protocol] frontdoor: Trying TCP discovery
[2024-08-09T06:39:22Z INFO  neolink::mqtt::discovery] Enabled MQTT discovery for frontdoor with friendly name Frontdoor
[2024-08-09T06:39:22Z DEBUG neolink::mqtt] Listening to message on frontdoor
[2024-08-09T06:39:22Z INFO  neolink_core::bc_protocol] frontdoor: Trying local discovery
[2024-08-09T06:39:22Z DEBUG neolink_core::bc_protocol::connection::discovery] Broadcasting to: [(255.255.255.255, 2015), (255.255.255.255, 2018), (172.30.33.255, 2015), (172.30.33.255, 2018)]
[2024-08-09T06:39:22Z DEBUG neolink_core::bc_protocol::connection::discovery] Also sending to [192.168.23.226:2018, 192.168.23.226:2015]
[2024-08-09T06:39:22Z DEBUG neolink_core::bc_protocol::connection::discovery] Trying a direct connect to: 255.255.255.255:2015 with tid: 46
[2024-08-09T06:39:22Z DEBUG neolink_core::bc_protocol::connection::discovery] Trying a direct connect to: 255.255.255.255:2018 with tid: 69
[2024-08-09T06:39:22Z DEBUG neolink_core::bc_protocol::connection::discovery] Trying a direct connect to: 172.30.33.255:2015 with tid: 109
[2024-08-09T06:39:22Z DEBUG neolink_core::bc_protocol::connection::discovery] Trying a direct connect to: 172.30.33.255:2018 with tid: 198
[2024-08-09T06:39:22Z DEBUG neolink_core::bc_protocol::connection::discovery] Trying a direct connect to: 192.168.23.226:2018 with tid: 72
[2024-08-09T06:39:22Z DEBUG neolink_core::bc_protocol::connection::discovery] Trying a direct connect to: 192.168.23.226:2015 with tid: 170
[2024-08-09T06:39:23Z DEBUG neolink_core::bc_protocol::connection::discovery] Registering 172.30.33.4:53984 to reolink
[2024-08-09T06:39:23Z INFO  neolink_core::bc_protocol] frontdoor: Trying remote discovery
[2024-08-09T06:39:23Z INFO  neolink_core::bc_protocol] frontdoor: Trying map discovery
[2024-08-09T06:39:24Z INFO  neolink_core::bc_protocol] frontdoor: Trying relay discovery
[2024-08-09T06:39:25Z DEBUG neolink::common::pushnoti] Push notification details are saved to Some("/root/.config/neolink/./neolink_token.toml")
[2024-08-09T06:39:25Z DEBUG neolink::common::pushnoti] Registering new push notification token
[2024-08-09T06:39:26Z INFO  neolink_core::bc_protocol] frontdoor: Remote discovery success 952700XXXXXXXX at 192.168.23.226:51881
[2024-08-09T06:39:26Z INFO  neolink::utils] frontdoor: Logging in
[2024-08-09T06:39:26Z DEBUG neolink_core::bc_protocol::login] Populating abilities
[2024-08-09T06:39:26Z DEBUG neolink_core::bc_protocol::abilityinfo] Abilities: <AbilityInfo><userName>admin</userName><system><subModule><abilityValue>general_rw, norm_rw, version_ro, uid_ro, autoReboot_rw, restore_rw, reboot_rw, shutdown_rw, dst_rw, log_ro, performance_ro, upgrade_rw, export_rw, import_rw, bootPwd_rw</abilityValue></subModule></system><network><subModule><abilityValue>port_rw, dns_rw, email_rw, ipFilter_rw, localLink_rw, pppoe_rw, upnp_rw, wifi_rw, ntp_rw, netStatus_rw</abilityValue></subModule></network><alarm><subModule><abilityValue>rfAlarm_rw</abilityValue></subModule><subModule><channelId>0</channelId><abilityValue>motion_rw</abilityValue></subModule></alarm><image><subModule><channelId>0</channelId><abilityValue>ispBasic_rw, ispAdvance_rw, ledState_rw</abilityValue></subModule></image><video><subModule><channelId>0</channelId><abilityValue>osdName_rw, osdTime_rw, shelter_rw</abilityValue></subModule></video><security><subModule><abilityValue>user_rw, userOnline_rw, bootPwd_rw</abilityValue></subModule></security><replay><subModule><channelId>0</channelId><abilityValue>replay_rw, seek_rw</abilityValue></subModule></replay><PTZ><subModule><abilityValue>control_rw, preset_rw, cruise_rw, track_rw, decoder_rw, ptzInfo_ro</abilityValue></subModule></PTZ><streaming><subModule><channelId>0</channelId><abilityValue>preview_rw, compress_rw, snap_rw, rtsp_rw, streamTable_ro</abilityValue></subModule></streaming></AbilityInfo>
[2024-08-09T06:39:26Z INFO  neolink::utils] frontdoor: Connected and logged in
[2024-08-09T06:39:28Z INFO  neolink::common::camthread] frontdoor: Camera time is already set: 2024-08-09 7:39:31.0 +00:00:00
[2024-08-09T06:39:30Z INFO  neolink::common::neocam] frontdoor: Model Argus Pro
[2024-08-09T06:39:30Z INFO  neolink::common::neocam] frontdoor: Firmware Version 1202_491_352_28
[2024-08-09T06:39:32Z WARN  neolink::common::pushnoti] Issue connecting to push notifications server: Http(reqwest::Error { kind: Decode, source: Error("missing field `token`", line: 7, column: 1) })
[2024-08-09T06:39:35Z DEBUG neolink::common::pushnoti] Push notification details are saved to Some("/root/.config/neolink/./neolink_token.toml")
[2024-08-09T06:39:35Z DEBUG neolink::common::pushnoti] Registering new push notification token
[2024-08-09T06:39:37Z WARN  neolink::common::pushnoti] Issue connecting to push notifications server: Http(reqwest::Error { kind: Decode, source: Error("missing field `token`", line: 7, column: 1) })
[2024-08-09T06:39:40Z DEBUG neolink::common::pushnoti] Push notification details are saved to Some("/root/.config/neolink/./neolink_token.toml")
[2024-08-09T06:39:40Z DEBUG neolink::common::pushnoti] Registering new push notification token
[2024-08-09T06:39:47Z WARN  neolink::common::pushnoti] Issue connecting to push notifications server: Http(reqwest::Error { kind: Decode, source: Error("missing field `token`", line: 7, column: 1) })

output from docker container

root@a14d3924-neolink-latest:/# cd /root/.config/neolink/
root@a14d3924-neolink-latest:~/.config/neolink# ls -lah
total 8.0K
drwxr-xr-x 2 root root 4.0K Aug  9 07:39 .
drwx------ 1 root root 4.0K Aug  9 07:39 ..
root@a14d3924-neolink-latest:~/.config/neolink# 
QuantumEntangledAndy commented 1 month ago

From your logs it seems that what is failing is not the file but the http request. I suspect this is an upstream issue because Google just pulled the api we use for push notifications. To fix this I would need the Reolink public vaspid which I don't have. I suspect going forward in just going to have to drop push notification support

QuantumEntangledAndy commented 1 month ago

We use this for push notification https://github.com/RandomEngy/fcm-push-listener and it says:

will stop working on June 20, 2024, since Google is shutting down an API it calls. You'll need to upgrade by that time for the library to keep working.

And the new upgraded version requires vapid keys

I've had two separate attempts to find a vapid key by dumping the Reolink android apk but haven't found it

HBK1 commented 1 month ago

I am also using HA plugin latest. Please drop or comment out the notification support for now. I have problem with a camera and it is hard to use debug as the logs are flooded by this error.

si458 commented 1 month ago

@HBK1 I just stopped the HA addon all together as my camera is battery powered and I'm only interested when it gets movement and HA gets motion and an image refresh!

HBK1 commented 1 month ago

Ok, but since notification is not working anyway it is no point flooding the logs while trying to find a solution if any. My cameras was also battery powered but I fixed power supply as it was draining the batteries to fast.

QuantumEntangledAndy commented 1 month ago

To disable push notifications put push_notifications = false in each of your [[cameras]] config. But without it we can't reliably wake up the camera when there is motion

QuantumEntangledAndy commented 1 month ago

As long as push_notifications=false is in every camera setup then it should not event try and connect to the push server

HBK1 commented 1 month ago

Thank you, it works! I was trying to find how to disable it but no luck.

si458 commented 1 month ago

@QuantumEntangledAndy any suggestions for my setup? If I disable the push notifications then how can my HA get notified when a motion happens? If i remove the idle_disconnect = true then it polls every 60 seconds for battery/picture but this drains the battery badly (even tho it's on solar power!) I'm only really interested in on motion, get a picture and let me know what the battery level is

QuantumEntangledAndy commented 1 month ago

You can't get notified without push notifications thats why we use them. You could send a manual wake up command over mqtt when you need the picture and battery to update.

Longer term through the two possible solutions I see would be 1. get push notifications up again, 2. Use the email from the camera instead. If your script foo is good you can do 2 yourself

You can also change the frequency that updates are polled in the mqtt configuration for the camera

QuantumEntangledAndy commented 1 month ago

Also if you have a neolink_token.toml from before the shutdown it should still work since only the part about getting the token was pulled

si458 commented 1 month ago

@QuantumEntangledAndy I changed the preview of image and battery to every 60mins, and the battery ran flat within 8 hours. Not enough time for the solar panel to kick in and start charging the battery again!

I will have sadly try the email option.

I don't think the push notifications have ever worked on my HA but will look at old backups see if I can find that folder/file as I don't think that folder is backed up by default because it's not inside the config folder for HA !

QuantumEntangledAndy commented 1 month ago

Perhaps you can try this?

By sending control/wakeup 5 the camera will wake up for 5 mins

You can also send control/preview to make it wake up and then grab a picture and go back to sleep

si458 commented 1 month ago

@QuantumEntangledAndy this is what I already do as such. I have the idle_disconnect as true, then 2 buttons on my HA dashboard, one for battery, one for preview so I can ask the mqtt whenever I want,

Altho I've have noticed doesn't matter weather I query preview or battery, they both get refreshed at the same time?

Bug maybe?

But it's only partially helpful as I still aren't notified about any motions!

So I have no idea, if the camera stops any motion at all as the motion mqtt is always unknown/off

QuantumEntangledAndy commented 1 month ago

Not a bug, there's a background thread that polls the battery and image as long as the camera is connected. You can disable those background threads in the mqtt config and then your buttons should be the only way to update the battery and preview

QuantumEntangledAndy commented 1 month ago

Motion mqtt is very specific type of motion, not my definition but the Reolink one.

It is the motion that triggers the MD alarm on msg id 33.

Some cameras (especially battery) don't produce msg id 33 and instead use PIR which isn't recorded as a motion state in mqtt

The only way I have found to get triggers on the PIR is push notifications and email there's no camera->client direct message about it

QuantumEntangledAndy commented 1 month ago

I'm exploring the new fcm push notification. Seeing if there's anyone to acquire the vapid key.

si458 commented 1 month ago

I'm exploring the new fcm push notification. Seeing if there's anyone to acquire the vapid key.

Great! If u need a hand, let me know. I have android and reolink app with a battery powered camera!

QuantumEntangledAndy commented 1 month ago

I actually don't have an android (was thinking to setup an emulator), are you tech savvy enough to setup something like a mitmproxy on the android and then reinstall reolink? It would be great if we could observe this message https://fcmregistrations.googleapis.com/v1/projects/{project_id}/registrations where {project_id} should be reolink-login, since this message contains the public key

si458 commented 1 month ago

Yes and no! But let me google it, and I'll look into it for you! So it's the first time they ask for notifications u want ? Not me turning on notifications for the camera in the app or both?

QuantumEntangledAndy commented 1 month ago

I'm not sure, you can try turning it off and on and see, but I think this is setup when you give it permission at startup

si458 commented 1 month ago

@QuantumEntangledAndy just a side note, I don't think the idle_disconnect=true is working correctly? I have it set it but from the logs it shows it connects fine but after 5-10mins. No logs saying it disconnected? And it's still draining my cameras battery!

bind = "0.0.0.0"

[mqtt]
broker_addr = "core-mosquitto" # Address of the mqtt server
port = 1883 # mqtt servers port
credentials = ["simon", "password"] # mqtt server login details

[[cameras]]
name = "frontdoor"
username = "admin"
password = "password"
uid = "95270QWXXXXXXXXX"
address = "192.168.23.226"
stream = "subStream"
#debug = true
#discovery = "local"
idle_disconnect = true
push_notifications = false

#[cameras.pause]
#on_motion = true  # Should pause when no motion
#on_client = true  # Should pause when no rtsp client
#timeout = 2.1     # How long to wait after motion stops before pausing

[cameras.mqtt]
enable_motion = false       # motion detection
enable_light = false        # flood lights only avaliable on some camera
enable_battery = true       # battery updates in `/status/battery_level`
enable_preview = true       # preview image in `/status/preview`
enable_floodlight = false   # preview image in `/status/floodlight_tasks`
battery_update = 3600000    # Number of ms between `/status/battery_level` updates
preview_update = 3600000    # Number of ms between `/status/preview` updates
floodlight_update = 3600000 # Number of ms between `/status/floodlight_tasks` updates

[cameras.mqtt.discovery]
topic = "homeassistant"
features = ["battery","reboot","camera"]
QuantumEntangledAndy commented 1 month ago

Idle disconnect works by taking out a permit when certain commands are run

I would need a bit more information to pin down which command is not dropping its permit (should auto drop when it goes out of scope)

si458 commented 1 month ago

@QuantumEntangledAndy OK so I've set idle_disconnect=true and then wrote a HA automation, every hour, it asks for a preview update /query/preview and this indeed refreshes the battery and the picture! Great!

And I've even checked the logs of neolink and indeed every hour, it does show connections to reolink for ip then connects to camera and returns abilities etc

But the battery is still draining dead! Within 8 hours from 100% to 15%

I don't think it's disconnecting properly? As again, I see no debug disconnect comments or logs or anything like that?

So is it maybe just reconnecting over and over? Rather than actually disconnecting after the 30secs?

QuantumEntangledAndy commented 1 month ago

I'll probably need to put in some more debug prints in places that can fail with the permit and then try to work it out from that. It's late here so I'll try adding them tomorrow when on the train to work.

I'm also working on getting mail notification setup automatically (provided there's a direct route between camera and neolink). Will see how that goes.

si458 commented 1 month ago

@QuantumEntangledAndy thank you! take it easy! rest up! enjoy ya train ride 🚂

WhatDoor commented 2 weeks ago

Hi @QuantumEntangledAndy, any luck on this issue?

I've currently got a workaround where I intercept the notification on my phone from the Reolink app using AutoNotification and Tasker and then post an MQTT message to wake up the camera via Neolink. But not really an ideal setup wrt to reliability.

Would love to see this feature working again!

QuantumEntangledAndy commented 2 weeks ago

No progress recently. I got the basics of the smtp method setup I just haven't had time to finish it.

Also when I tired emulating the android app my laptop died (too weak a cpu etc) so I'll probably have to do this on my more powerful Linux box when I've got the time to setup that.

TLDR: Nope not yet please wait :)

Akyariss commented 2 weeks ago

I managed to install mitmproxy and observe reolink requests. I could not find https://fcmregistrations.googleapis.com/v1/projects/{project_id}/registrations let me know what i can do to find it, the mitm setup is ready

edit: i think i might have found it, let me know where i can contact you in private to test it

QuantumEntangledAndy commented 2 weeks ago

You can get my email from github if you need it

But perhaps we can discuss here with the relevant data sanitized

I expect the call to https://fcmregistrations.googleapis.com/v1/projects/{project_id}/registrations

To produce something of the form

{
    "web": {
            "application_pub_key": "THIS THING PLEASE",
            "auth": "SANITIZE THIS",
            "endpoint": "SHOULD BE: https://fcm.googleapis.com/fcm/send/{gcm_token}",
            "p256dh": "SANITIZE THIS"
        }
}

Does that match what you got?

Akyariss commented 2 weeks ago

it does not, I kept mitmproxy active from the installation of the app to the push notification trigger

After a push notification I was getting:

https://pushx.reolink.com/listeners/{numbers}
content-type: application/json; charset=utf-8
content-length: 244
accept-encoding: gzip
user-agent: okhttp/4.11.0

putting the link in the browser returns this:

{"status":{"code":0,"detail":"OK"},"data":{"clientId":"{numbers}","clientType":"reo_fcm","defaultSound":"push.wav","devices":[{"uid":"{numbers}","secret":"{numbers}"}],"status":0,"token":"token"}}

QuantumEntangledAndy commented 2 weeks ago

That seems to be similar to that documented in https://github.com/QuantumEntangledAndy/neolink/blob/master/crates/pushnoti/README.md but when I tested it the "scecret" came back blank.