pergolafabio / Hikvision-Addons

Home Assistant: Hikvision Doorbell
166 stars 36 forks source link

DS-KD8003-IME1 with DS-KD-KP code support #204

Open AYahoo opened 2 months ago

AYahoo commented 2 months ago

Is there an existing feature request for this?

Add-on

None

Your feature request

DS-KD-KP, is a numeric pad with a access control code to open relays on the KD8003, I would love to have the ability to know which user entered and if the wrong password has been pressed to know if someone is trying to mess with the code, guess it, or just playing with it. I'm sure I saw it on the SDK in the past.

AYahoo commented 1 month ago

Hey, Tried to build with the SDK version that you gave me. It's running. But I still get the same Alarm Type 0.

After some investigation, what I receive in the NVR, is an EVENT (NET_DVR_VIDEO_INTERCOM_EVENT), and not ALARM. Is there any way you can listen to events?

It seems that the Keypad is an EVENT, and not an alarm. That's maybe why we see the AlarmType 0...

pergolafabio commented 1 month ago

hi, the addon is already listening for events:

https://github.com/pergolafabio/Hikvision-Addons/blob/1a0ab1a80effc26039ab3b90a6a59d764e4e8b78/hikvision-doorbell/src/mqtt.py#L280

this is from SDK: https://open.hikvision.com/hardware/structures/NET_DVR_VIDEO_INTERCOM_EVENT.html

as you can see they are added, so not sure why its not in the debug log... https://github.com/pergolafabio/Hikvision-Addons/blob/1a0ab1a80effc26039ab3b90a6a59d764e4e8b78/hikvision-doorbell/src/sdk/hcnetsdk.py#L173

pergolafabio commented 1 month ago

so my guess, the 8003 is reporting wrong ... maybe a firmware bug

Khyonox commented 1 month ago

so my guess, the 8003 is reporting wrong ... maybe a firmware bug

Hey there, I've been following this issue for a little while now, since we're facing a similar problem with KD-8003-IME1-B (only the B revision). We reached out to Hikvision tech support via tpp.hikvision.com, and they stated that this is NOT, in fact, a firmware bug 🤔

image image

AYahoo commented 1 month ago

Funny enough, just 5 minutes ago I sent Hikvision an email regarding the issue :)

Thanks for the info.

Khyonox commented 1 month ago

Funny enough, just 5 minutes ago I sent Hikvision an email regarding the issue :)

Thanks for the info.

Both attachments that they sent us. Looks like it's possible to somehow obtain pAlarmData from that structure NET_DVR_ALARM_ISAPI_INFO event_type

Khyonox commented 1 month ago

Funny enough, just 5 minutes ago I sent Hikvision an email regarding the issue :)

Thanks for the info.

At this point, im not sure where the issue is lol, we tested different SDK versions, multiple 8003 B revision doorbells, and the B revision sends event with zero data in alarmData param. I hope they will give you at least some info

pergolafabio commented 1 month ago

uhmm, i think the "illegal card swipe" event is already working on my addon? i think this event is triggerd Want this issue about the code entry? thats something else

pergolafabio commented 1 month ago

nm, quickly tested it, seems illega card swipe isnt logged either... maybe its because the addon is using the arming mode on the devices

pergolafabio commented 1 month ago

i opened ivms, and i dont see those events there either, or maybe i didnt configiure ivms right, i never use it :-)

pergolafabio commented 1 month ago

ahh, maybe we need to link the camera to the event? seems all my events arent linked to the 8003

image

pergolafabio commented 1 month ago

@AYahoo , you tried a new SDK lib right? can you try it again, but then in Windows using the SDK for windows? i have seen different behaviours in the past using the Windows SDK, maybe there is just an issue with the Linux version

pergolafabio commented 1 month ago

here is the correct path:

hcnetsdk_path = ".\lib-windows64\HCNetSDK.dll"

https://github.com/pergolafabio/Hikvision-Addons/blob/1a0ab1a80effc26039ab3b90a6a59d764e4e8b78/hikvision-doorbell/src/sdk/utils.py#L47

Khyonox commented 1 month ago

uhmm, i think the "illegal card swipe" event is already working on my addon? i think this event is triggerd Want this issue about the code entry? thats something else

Im not sure if our issue is related to this, but it's similar, since in both cases alarm_isapi_info shows empty pAlarmData param

AYahoo commented 1 month ago

uhmm, i think the "illegal card swipe" event is already working on my addon? i think this event is triggerd Want this issue about the code entry? thats something else

Im not sure if our issue is related to this, but it's similar, since in both cases alarm_isapi_info shows empty pAlarmData param

Yes I did. I can try with the windows one.

But from what I understand from the replay, is that if you get an alarm type 0, you should get the NET_DVR_ALARM_ISAPI_INFO type, and there you will have all the info, as the screenshot that was attached.

pergolafabio commented 1 month ago

Have you tried that client demo? I already have all those ACS events in the addon, just need a way to link it... I know other people using face terminals intercoms, they get ACS events reporting in the addon

https://github.com/pergolafabio/Hikvision-Addons/blob/dev/hikvision-doorbell/src/sdk/acsalarminfo.py

AYahoo commented 1 month ago

Been browsing the ClientDemo code, Trying to figure out what's the equivalent to "lCommand" property in your code. That's what is distinguishing the different type of alarms from ISAPI Alarm, to different type of alarm.

image

pergolafabio commented 1 month ago

i checked mine DS-KD8003 , its giving an NET_DVR_VIDEO_INTERCOM_ALARM and not an COMM_ISAPI_ALARM one on invalid keypad entry

the alarmtype in my case is 0 instead of the ones listed

https://open.hikvision.com/hardware/structures/NET_DVR_VIDEO_INTERCOM_ALARM.html

2024-05-27 18:41:02.139 | INFO     | event:video_intercom_alarm:120 - Video intercom alarm from DS-KD8003
2024-05-27 18:41:02.140 | WARNING  | mqtt:video_intercom_alarm:364 - Received unknown alarm type: 0
pergolafabio commented 1 month ago

and those screenshots they send you is the alertstream, you can see an example here: https://www.hikvisioneurope.com/eu/portal/portal/Technology%20Partner%20Program/03-How%20to/How%20to%20get%20real-time%20event%20in%20listening%20mode.pdf

but that alertstream i have never seen it working on Intercoms, its for cameras

Khyonox commented 1 month ago

I think i have some progress on this. Attached screenshot of invalid card on KD8003-B image

pergolafabio commented 1 month ago

ah, thats interesting? what did you do ?

Khyonox commented 1 month ago

And here is the JSON I get if I try to enter an invalid code on the DS-KD-KP module image

Khyonox commented 1 month ago

ah, thats interesting? what did you do ?

I think pAlarmData param in NET_DVR_ALARM_ISAPI_INFO struct in sdk code should be a pointer to a char, and then you can get any data from pAlarmData with length of dwAlarmDataLen

pergolafabio commented 1 month ago

do you have the code running, can you share it?

pergolafabio commented 1 month ago

or can you submit a PR ?

Khyonox commented 1 month ago

Changed pAlarmData param to a pointer with char type:

class NET_DVR_ALARM_ISAPI_INFO(Structure):
fields = [
("pAlarmData", POINTER(char)),
("dwAlarmDataLen", DWORD),
("byDataType", BYTE),
("byPicturesNumber", BYTE),
("byRes", BYTE * 2),
("pPicPackData", NET_DVR_ALARM_ISAPI_PICDATA),
("byRes2", BYTE * 32),
]

And then we can read data string at pAlarmData location via string_at:

    async def isapi_alarm(
            self,
            doorbell: Doorbell,
            command: int,
            device: NET_DVR_ALARMER,
            alarm_info: NET_DVR_ALARM_ISAPI_INFO,
            buffer_length,
            user_pointer: c_void_p):
        pAlarmData = alarm_info.pAlarmData
        alarmDataLen = alarm_info.dwAlarmDataLen
        byDataType = alarm_info.byDataType
        alarmDataBuffer = ctypes.string_at(pAlarmData, alarmDataLen)
Khyonox commented 1 month ago

Still, need to check if data type is xml, since NET_DVR_ALARM_ISAPI_INFO can send xml too

pergolafabio commented 1 month ago

I hope these events are documented somewhere, dont think they are the same as below:

https://open.hikvision.com/hardware/structures/NET_DVR_ACS_ALARM_INFO.html

Khyonox commented 1 month ago

Im not sure. Just checked their SDK client demo and docs for it, not found anything really

pergolafabio commented 1 month ago

MINOR_INVALID_CARD | 0x09

This one is in my SDK, but the event 150 is not , i can just add it, those docs are not always up to date

pergolafabio commented 1 month ago

hey @Khyonox , what firmware do you have on your 8003 ? Probably an older one? mine doesnt give the ISAPI alarm :-(

Khyonox commented 1 month ago

hey @Khyonox , what firmware do you have on your 8003 ? Probably an older one? mine doesnt give the ISAPI alarm :-(

Interesting, im using V2.2.76 build 240226

pergolafabio commented 1 month ago

2.2.72 ? where did you download it? i'm on 2.2.62 , and i see its the latest one here? do you have rev A or rev B model ?

https://www.hikvisioneurope.com/eu/portal/?dir=portal/Technical%20Materials/07%20%20Video%20Intercom/00%20%20Product%20Firmware/01%20Door%20Station%20%28KD%20KV%20KB%29/KD%20Series/KD8003

Khyonox commented 1 month ago

Just did a firmware update, now using V2.2.76 build 240515. Still sends the ISAPI alarm 🤔 image

Khyonox commented 1 month ago

2.2.72 ? where did you download it? i'm on 2.2.62 , and i see its the latest one here? do you have rev A or rev B model ?

https://www.hikvisioneurope.com/eu/portal/?dir=portal/Technical%20Materials/07%20%20Video%20Intercom/00%20%20Product%20Firmware/01%20Door%20Station%20%28KD%20KV%20KB%29/KD%20Series/KD8003

https://www.hikvision.com/en/support/download/firmware/

image

pergolafabio commented 1 month ago

the ISAPI alarm is good

but mine sends an EVENT alarm with type 0 ... , seems it was working on 2.2.45 according to @AYahoo , but he also upgraded to 2.2.62 , and receives the same EVENT as me

we are using rev A models, 2.2.62 is the latest :-( , maybe a bug in our firmware

pergolafabio commented 1 month ago

i have build : V2.2.62 build 230204 and it seems its the latest one

AYahoo commented 1 month ago

If you can make it work with the ISAPI I'm willing to degrade to 2.2.45.

pergolafabio commented 1 month ago

we should move upwards, you guys had contact with Hikvision right? Can you ask if this is a known bug in 2.2.62 (rev A) ? since it was working an previous release 2.2.45...

Also tell it works in 2.2.72 (rev B)

AYahoo commented 1 month ago

Just did, this is the ticket:

"Hi, We are facing a problem with the module of DS-KD-KP, and DS-KD8003-IME1, Since upgrading from version 2.2.45 to version 2.2.62.

With the old firmware, we got an ISAPI event on bad pin code enter. but with the new version, 2.2.62 we get a response of alarm type 0 which is not supported according to the SDK (https://open.hikvision.com/hardware/structures/NET_DVR_VIDEO_INTERCOM_ALARM.html).

From other users we got that on DS-KD8003-IME1 REV B they have a newer firmware 2.2.72 and the behavior is fixed and they get ISAPI event.

Is it a BUG in the firmware? are we doing something wrong? "

On Wed, Jun 5, 2024, 10:08 Pergola Fabio @.***> wrote:

we should move upwards, you guys had contact with Hikvision right? Can you ask if this is a known bug in 2.2.62 (rev A) ? since it was working an previous release 2.2.45...

Also tell it works in 2.2.72 (rev B)

— Reply to this email directly, view it on GitHub https://github.com/pergolafabio/Hikvision-Addons/issues/204#issuecomment-2149041284, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPRV3SPYITHCSCDFOAW2ILZF22P3AVCNFSM6AAAAABHJORXICVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBZGA2DCMRYGQ . You are receiving this because you were mentioned.Message ID: @.***>

AYahoo commented 1 month ago

This i the replay,

Do you use ISAPI to get the event from KD8003, but get the alarm type 0? Could you please share your event example ? Thanks.

@pergolafabio Could you please help with the response?

pergolafabio commented 1 month ago

Hey, you can say we are using SDK and listining for lCommand

https://open.hikvision.com/hardware/definitions/NET_DVR_StartListen_V30.html

For the invalid key code, we are receiving this:

COMM_ALARM_VIDEO_INTERCOM | 0x1133 | Video intercom alarm information | NET_DVR_VIDEO_INTERCOM_ALARM

With : byAlarmType => 0

We should receive this instead:

COMM_ISAPI_ALARM | 0x6009 | ISAPI protocol alarm information | NET_DVR_ALARM_ISAPI_INFO

For the unknown badge , in my case i dont receive any event at all , while @Khyonox does receive the event He is using the DS-KD8003 rev B , with firmware 2.2.72

pergolafabio commented 1 month ago

Do you have some updates?

AYahoo commented 4 weeks ago

Yeah, just got a response:

Hello,

I think it is a bug as you described. For the the current event, I have checked that there is no byAlarmType=0. You can test this function in our SDK ClientDemo and privide the snaphot to show this issue. BTW, Could you please share the right event exmaple before for a check? Thanks.

pergolafabio commented 4 weeks ago

Ok, that's good news, if they confirm it as a bug ;-)

Hopefully you can get them going to create a new firmware

pergolafabio commented 1 week ago

Got some updates?