Setting up NVR-based Reolink cameras

If your keen to take it on, I can do 80% of the work needed in a few hours saving you from needing to learn how the binding works.

I’m willing to take it on. The FOSCAM code seems pretty straight forward (although those are often famous last words). Seems like we can keep most of the structure and just update the CGI syntax and result parsing. I’ll start working through the developers guide. While I’m working on that, do you want to take an initial stab the new Reolink handler class? I can then use that as a base line to troubleshoot/debug.

hi, i’m using Reolink too. Camera, not NVR.
per onvif I get only the motion detection signal.
Somewhere in the internet i found a list for the api commands and i use the http binding for polling a person alarm state.

IPofCam/api.cgi?cmd=GetAiState&channel=0&user=aaaa&password=aaa
JSONPATH:$.[0].value.people.alarm_state

Reolink E1 Outdoor cam api output:

[
   {
      "cmd" : "GetAiState",
      "code" : 0,
      "value" : {
         "channel" : 0,
         "face" : {
            "alarm_state" : 0,
            "support" : 0
         },
         "people" : {
            "alarm_state" : 0,
            "support" : 1
         },
         "vehicle" : {
            "alarm_state" : 0,
            "support" : 1
         }
      }
   }
]

Maybe this is helping you…
Greets

1 Like

Thanks for the info. I hadn’t thought to look into using the HTTP binding. I think I’m going to continue to pursue the IP Camera Binding option right now as I’m interested in some of its built in features, but might use this as a fall back.

At what rate do you have to poll to make sure you don’t miss an event?

Every 3 seconds.
It’s enough for me…
I use both… Ptz preset is working fine with ipcamera binding… And the snapshot and video stream…
I use the http binding just for person detection.

For anyone that comes across this thread, I can confirm that you can use the HTTP Binding to poll the AI state with an NVR system. To access different cameras on the NVR, you simply need to change the channel reference accordingly: IPofCam/api.cgi?cmd=GetAiState&channel=0&user=aaaa&password=aaa. I should note that, you need to have the firmware v3.0.0.148_21101146 or above installed on your NVR. Prior to that, the AI option doesn’t work through the API.

One of the downsides of this approach, is that you username and password are stored in raw format within the Thing definition. There is likely a way around this, but I haven’t delved too deep into it.

@DieterK has added that functionality to the IP Camera binding and we are just waiting for a PR to be done, you can read his post here on it…

Onvif camera error message - Add-ons / Bindings - openHAB Community

It is far better to use the ONVIF methods as they are event based and the events get pushed to the binding, where how your doing it with the http binding is polling and not as good as event based methods. If you place the binding into DEBUG level logging it will tell you if the camera is reporting events that the binding does not have implemented and if you post this info, it can be added very easily.

@azureshammer Let me know when your able to compile the code and create a jar. I think the best way forward would be to use ONVIF if the dvr channel is 0, and for numbers above this, it could switch to polling so people get the best of both worlds. But this requires someone to test that actually has a camera. I would not be surprised if the API polling has added benefits and extra features. For example with Dahua and Hikvision if you get a Line Crossed alarm, the API can tell you which direction the line was crossed so you know if someone if walking towards or away from your home.

Hi Skinah,

good news!

Reolink managed to fix the issue and i was able to positivly verify the behaviour (i.e. camera is stable now).

Up to now there’s no offical build yet, i received the new FW via email.

I raised a question on when they plan to release new FW, will share any update as soon as available.

Not so good, i’m bit behind on what i stated earlier, i.e. sharing the changes at the weekend …

Will do my very best to come up with those next weekend.

Best regards,

Dieter

1 Like

I don’t know anything about reolink but I have noticed that there is a working solution for home assistant, might give you some ideas on how to integrate it.

Hi there, I’m using a Reolink E1 outdoor (no NVR) and I would be happy to provide a debug log. Unfortunaly I’m currently stuck with OH 3.0.2 as I need to fix a backup issue. Let me know if this (OH 3.0.2) isn’t an issue.

I tried the debug log.
I reinitializied the Thing and walked in Front of the cam…

2022-07-08 19:10:42.086 [DEBUG] [amera.internal.onvif.OnvifConnection] - Cameras  UTC dateTime is:2022-7-8T17:10:43
2022-07-08 19:10:42.087 [DEBUG] [amera.internal.onvif.OnvifConnection] - Openhabs UTC dateTime is:2022-07-08T17:10:42.086Z
2022-07-08 19:10:42.185 [DEBUG] [amera.internal.onvif.OnvifConnection] - deviceXAddr:http://192.168.0.178:8000/onvif/device_service
2022-07-08 19:10:42.186 [DEBUG] [amera.internal.onvif.OnvifConnection] - eventsXAddr:http://192.168.0.178:8000/onvif/event_service
2022-07-08 19:10:42.186 [DEBUG] [amera.internal.onvif.OnvifConnection] - mediaXAddr:http://192.168.0.178:8000/onvif/media_service
2022-07-08 19:10:42.186 [DEBUG] [amera.internal.onvif.OnvifConnection] - ptzXAddr:http://192.168.0.178:8000/onvif/ptz_service
2022-07-08 19:10:42.345 [DEBUG] [amera.internal.onvif.OnvifConnection] - GetStreamUri:rtsp://192.168.0.178:554/
2022-07-08 19:10:42.555 [DEBUG] [amera.internal.onvif.OnvifConnection] - GetSnapshotUri:/cgi-bin/api.cgi?cmd=onvifSnapPic&channel=0
2022-07-08 19:10:42.608 [DEBUG] [amera.internal.onvif.OnvifConnection] - ptzNodeToken=000
2022-07-08 19:10:42.678 [DEBUG] [amera.internal.onvif.OnvifConnection] - subscriptionXAddr=http://192.168.0.178:8000/onvif/PullSubManager?Idx=00_1
2022-07-08 19:10:42.700 [DEBUG] [amera.internal.onvif.OnvifConnection] - Processing new PTZ location now
2022-07-08 19:10:42.700 [WARN ] [amera.internal.onvif.OnvifConnection] - Binding could not determin the cameras current PTZ location. Not all cameras respond to GetStatus requests.
2022-07-08 19:10:42.753 [DEBUG] [amera.internal.onvif.OnvifConnection] - ptzConfigToken=000
2022-07-08 19:10:43.985 [DEBUG] [amera.internal.servlet.CameraServlet] - Now there are 0 autofps.mjpeg streams open.
2022-07-08 19:10:43.985 [DEBUG] [amera.internal.servlet.CameraServlet] - All autofps.mjpeg streams have stopped.
2022-07-08 19:10:56.436 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.512 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.591 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.661 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.741 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.791 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
2022-07-08 19:10:56.841 [DEBUG] [amera.internal.onvif.OnvifConnection] - Onvif Event Topic:RuleEngine/CellMotionDetector/Motion, Data:IsMotion, Value:true
etc
. 
. 
. 

Just only the CellMotion Event.
In the http binding I saw person alarm…
Do I need to link an item? Or are all onvif Events logged? I have linked only cellmotion alarm to an item.
Maybe trace log?

NO, the logs will show any event that the camera sends exactly as you have shown. This means the camera has to recognize a person to send the event and for it to show up in the logs. Some cameras are slow and not reliable at detecting a person so give it some more time standing in front of the camera without wearing a cap/hat.

Great but that will be using the API method and not using ONVIF method. The ONVIF method is better as it is using the PUSH method, whereas the API is using the POLLING method. If you camera can only send it via the API (perhaps that is the case or you have an older firmware) then that is another reason to implement the API into the IP Camera binding which is very easy to do and sounds like we have a few users that are keen to look at it.

That would be great if you can contribute those soon as I will hold off making any changes until yours are made so that we can prevent any merge conflicts that may happen.

Hi Skinah,

unfortunately i’m struggling getting access to the repo, something seems to be wrong with the token.

To make it short, attached below the changes i made compared to the 3.2 release version.

Sorry for inconvinience!

Best regards,

Dieter

diff --git a/bundles/org.openhab.binding.ipcamera/pom.xml b/bundles/org.openhab.binding.ipcamera/pom.xml
index 432be60edb…606031fa4c 100644
— a/bundles/org.openhab.binding.ipcamera/pom.xml
+++ b/bundles/org.openhab.binding.ipcamera/pom.xml
@@ -1,4 +1,6 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>

hi, me again.
I wanted to try the Onvif Events with “Onvif Device Manager”.
I was not able to get a subscription for the Onvif Events , “400 Bad Request”.
After a reboot of the Cam I got a connection with Onvif Device Manger.
But there are also no Person Alarms… Just CellMotionAlarm… damn
I tried Trace Log from the Ipcambinding and found the following:

Sending ONVIF request:Unsubscribe
2022-07-09 19:35:14.156 [TRACE] [amera.internal.onvif.OnvifConnection] - Onvif reply is:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsdd="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xmime5="http://www.w3.org/2005/05/xmlmime" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:ns1="http://www.onvif.org/ver10/actionengine/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:ns10="http://www.onvif.org/ver10/events/wsdl/PullPointBinding" xmlns:ns11="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding" xmlns:ns12="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding" xmlns:ns13="http://www.onvif.org/ver10/network/wsdl/RemoteDiscoveryBinding" xmlns:ns14="http://www.onvif.org/ver10/network/wsdl/DiscoveryLookupBinding" xmlns:tdn="http://www.onvif.org/ver10/network/wsdl" xmlns:ns3="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding" xmlns:ns4="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:ns5="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" xmlns:ns6="http://www.onvif.org/ver10/events/wsdl/EventBinding" xmlns:ns7="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" xmlns:ns8="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:ns9="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding" xmlns:tad="http://www.onvif.org/ver10/analyticsdevice/wsdl" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tls="http://www.onvif.org/ver10/display/wsdl" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:trc="http://www.onvif.org/ver10/recording/wsdl" xmlns:trp="http://www.onvif.org/ver10/replay/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:trv="http://www.onvif.org/ver10/receiver/wsdl" xmlns:tse="http://www.onvif.org/ver10/search/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><SOAP-ENV:Body><SOAP-ENV:Fault SOAP-ENV:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><SOAP-ENV:Code>
<SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value></SOAP-ENV:Code>
<SOAP-ENV:Reason><SOAP-ENV:Text xml:lang="en">Method 'Unsubscribe' not implemented: method name or namespace not recognized</SOAP-ENV:Text></SOAP-ENV:Reason></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

2022-07-09 19:35:16.185 [DEBUG] [amera.internal.onvif.OnvifConnection] - Eventloop is shutdown:true

is it possible that the "Method ‘Unsubscribe’ not implemented: " didnt let me subscribe to the Onvif Events with ‘Onvif Device Manager’? Was it locked by the ipcamerabinding?
I hope you know what I’m talking about :blush:

@matt1 I’m out of town right now, but will compile everything and test it out when I get back in a week or so.

@matt1 So, I’ve got the code setup, compiling, and creating the jar file.

1 Like

Hi Skinah,

have you been able to merge my changes into the code?

Sorry again for just sending the diffs, i’ve been traveling till now :frowning:

Kind regards,

Dieter

I tried it again. There are definitely no (onvif) people alarms to be found in the log.
Only the cellmotionalarm is displayed.
So no onvif with my Reolink E1 Outdoor cam.
Maybe with a firmware update in the future.
I stay with my http polling…
Greets.

1 Like

I do not see any detailed diff that contains anything useful, perhaps the forum cut the content short? The preferred way is via github in a PR.

Hi Skinah,

that’s bad news!

Haven’t you received my earlier email (9.7.) at all or was it cut off in the middle?

I’m aware that PR is the preferred option.
Since you mentioned you are in a hurry and i was offline for a week, to shorten it up, i send you the diifs (giving it another try, i.e. diffs attached below).

As mentioned, i’m facing access violation issues with the token.

Please let me know whether the diffs now made it.

In doubt i can give’m another try with the token at the weekend.

What i did: checkout, create branch, changed to the branch, added my changes on the branch, commited them and tried to check the branch in again.

With last step i got rejected, due to insuffiant access rights.

Any obvious mistake i made?

Thanks,

Dieter

diff --git a/bundles/org.openhab.binding.ipcamera/pom.xml b/bundles/org.openhab.binding.ipcamera/pom.xml
index 432be60edb…606031fa4c 100644
— a/bundles/org.openhab.binding.ipcamera/pom.xml
+++ b/bundles/org.openhab.binding.ipcamera/pom.xml
@@ -1,4 +1,6 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>

@matt1 I’ve started coding up a ReolinkHandler class, but have a few comments and questions:

  • It doesn’t look like the Reolink NVR allows for ONVIF functionality, only direct connection with a camera on the network (although I haven’t explicitly tried this). So, the NVR systems will have to only use polling. Not quite sure how to handle these two options.
  • I don’t understand how/when the readChannel method is called. Is it called after every HTTP request?
  • In the handleCommand method, what is the “refresh” portion of the code doing?

Thanks.

1 Like