laszlojakab / hikvision-intercom-python-demo

Hikvsion intercom Python demo
MIT License
19 stars 6 forks source link

Segmentation fault - core dumped #2

Closed pergolafabio closed 11 months ago

pergolafabio commented 2 years ago

Hey @laszlojakab I'm creating an addon for HA with your script, but when i try to run your script using python 3.9 , when i fire it, i get immediately the error : segmentation fault - core dumped

why is that? if i run it with python 3.8 , then it works?

any idea?

thnx in advance

pergolafabio commented 2 years ago

Ok, was creating add-on, but always segmentation fault seems when i use the 3.7 python image then it works

any idea?

#FROM python:3.8.12-slim
FROM python:3.7-slim
#FROM python:slim
psy0rz commented 2 years ago

I had this as well, i fixed it by removing the device_info parameter from NET_DVR_Login_V30.

(its not used anyway)

Also note that the intercom will return all the missed events as well in a slow matter, so that might be confusing at first. (just let it run and it will empty the queue slowly)

pergolafabio commented 2 years ago

aha, thats interesting!! gonna update my addon and test, apreciate the info !!!

psy0rz commented 2 years ago

awesome..ill fork this project and make a version that just publishes all the events over MQTT

pergolafabio commented 2 years ago

i created also an addon for this : https://github.com/pergolafabio/Hikvision-Addons

pergolafabio commented 2 years ago

how did you found out the segmentation issue?

psy0rz commented 2 years ago

yes i ended up here via your addon. i dont use homeassist, but node-red instead.

its pretty amazing how @laszlojakab managed to create those python bindings to a closed source library!

i used gdb to debug a bit and found out it didnt segfault when you used the wrong login credentials. so i hoped/assumed the segfault was in the last part of the login procedure, when trying to write back the device_info. so it was a bit of luck :)

pergolafabio commented 2 years ago

hmm, tested some python versions, and for some reason i was unable to reproduce the issue anymore maybe something changed in the lkatest build of pythons

i tested 7 , 8 , 9 and 10

updated now my addon also to 3.10

pergolafabio commented 2 years ago

so you changed:

device_info = NET_DVR_DEVICEINFO_V30()
user_id = HCNetSDK.NET_DVR_Login_V30(config["ip"].encode('utf-8'), 8000, config["username"].encode('utf-8'), config["password"].encode('utf-8'), device_info)

to:

# device_info = NET_DVR_DEVICEINFO_V30()
user_id = HCNetSDK.NET_DVR_Login_V30(config["ip"].encode('utf-8'), 8000, config["username"].encode('utf-8'), config["password"].encode('utf-8'))
psy0rz commented 2 years ago

correct.

might also have to do which system libraries/linux distro you have.

its a bit sketchy to use .so libraries that were compiled for another system. so i wouldn't be surprised by some weirdness/instability.

pergolafabio commented 2 years ago

ok, thnx for feedback !! :-)

psy0rz commented 2 years ago

thanks to the power of forking and python, i was done in 45 minutes :P

https://github.com/psy0rz/hikvision-intercom-mqtt

pergolafabio commented 2 years ago

Cool :+)

Have you tried also the opensips stuff?

pergolafabio commented 2 years ago

Btw, for opening , or sending stuff, loin at my GitHub, there is an example py file, so you can send commands to open a door for example

psy0rz commented 2 years ago

cool might try that in the future. my previous intercom had sip only support and was running through my asterisk server. :)

pergolafabio commented 2 years ago

yeah, but i also wanted to have video in early media stage on my indoor panels, that never works in group calls , thats why i decided to register the PBX on the priiave SIP protocol, so indoor panels still have video

kyri33 commented 2 years ago

Hi I'm still getting a seg fault when trying to run. I've removed the device_info variable. Tried on python 3.7, 3.8. Ubuntu 18 and Ubuntu 20. Does anyone know what the issue could be ?

pergolafabio commented 2 years ago

Have a look at my addon, it runs

https://github.com/pergolafabio/Hikvision-Addons/blob/main/hikvison-sdk/Dockerfile

kyri33 commented 2 years ago

Thank You. I've actually just managed to get it working with python 3.6 and Ubuntu 18. I see you're using python 10. Will try it with that since it's probably better. Thanks again

pergolafabio commented 1 year ago

hey @psy0rz , my addon was updated from 3.10.8 to 3.10.9 , and seems segmentation fault was now occuring i also tried removing device_info, but issue still occurs

any idea what could be wrong?

psy0rz commented 1 year ago

nope, mine is still running, but with python 3.8.16

pergolafabio commented 1 year ago

ah ok, yeah its a strange issue indeed :-( i reverted back the HA Addon to 3.10.8 , so working again now

but i have no idea where its coming from

pergolafabio commented 1 year ago

btw, i see you created the mqtt version i created an addon based on this script, also included sending callsignal, maybe also interesting for your project? i have a zigbee openclose sensor at the door, so when i open the door manually, i reject the call, so all stations stop ringing

also, if interested , i have the RPI lib for aarch64 support

psy0rz commented 1 year ago

its not that strange: its using precompiled libraries. to have the best chance of success, the environment needs to be as close as possible to the environment that was originally used. So its a wonder it works at all :)

thats why i'm using docker, so i can control the environment. (e.g. python:3.8, debian buster)

how did you get it to function on an arm architecture?

all the files in the original lib-directory are x86_64?

pergolafabio commented 1 year ago

yeah, i was in contact with Hikvision support and they supplied me an internal dev release, it wont be avaible to public release you can find files in below dir for aarch64, but iits even more difficult to run, it only works on Euler or Harmony os, i created my docker based on that, and it works, confirmed by lots of users

https://github.com/pergolafabio/Hikvision-Addons/tree/main/hikvision-sdk-aarch64

anyway, nothing we can do about the seg fault? maybe test a newer lib release, will that make improvements?

pergolafabio commented 1 year ago

the "official" supported OS for aarch64 lib was:

quote by hikvision:

**The tested OS systems are Phytium ,Huawei**

pergolafabio commented 1 year ago

hey @psy0rz , do you want to help with the HA Addon i created , we want to make it better, i have already some extras in it , like sending stdin messages for Open door or reject the callsignal or sending custom isapi commands

we habe more ideas to configure devices automaticly, based on mqtt , creating video stream But also not make it avaible only as addon, but an option to run it also as docker to make it suitable for everyone , not only HA but also openhab users

pergolafabio commented 1 year ago

someone started yesterday already to make it a multiarch docker, so work is started, all help is verry welcome!!

https://github.com/pergolafabio/Hikvision-Addons/pull/39

psy0rz commented 1 year ago

sorry, i'm too busy with other projects, but good luck :)

pergolafabio commented 1 year ago

No problem:+)

mion00 commented 1 year ago

Thanks @psy0rz for your hikvision-intercom-mqtt project, it inspired me to join forces with @pergolafabio and improve on the existing addon to allow it to run also as a standalone container.

psy0rz commented 1 year ago

awesome! you're welcome :D