roleoroleo / onvif_simple_server

Light implementation of an onvif server intended for use in resource-constrained devices
GNU General Public License v3.0
31 stars 12 forks source link

Client testing issue for events service #13

Closed icedbeancat closed 1 week ago

icedbeancat commented 1 week ago

Hi @roleoroleo, thank you for your hard work.

I managed to successfully build the server and connect to the ONVIF Device Manager. I was able to post a GetEventProperties request. However, when I tried to create pullpoint subscription, ODM failed to do so. I did the same using the python-onvif-zeep client.

I only edited the IFS portions of the code since the interface that I am using is different. Else, I ran everything as is. Was I mistaken that the server can implement the full event service? I am not sure what I should check and which files I should modify.

roleoroleo commented 1 week ago

Events service is supported: both PullPoint and WS base. Please, post your conf file.

icedbeancat commented 1 week ago

Below is my conf file, I run it using lighttpd.

model=Model manufacturer=Manufacturer firmware_ver=0.0.1 hardware_id=HWID serial_num=SN1234567890 ifs=eno1 port=8080 scope=onvif://www.onvif.org/Profile/Streaming

user=admin

password=admin

Advanced options

adv_fault_if_unknown=0 adv_fault_if_set=0 adv_synology_nvr=0

Profile 0

name=Profile_0 width=1920 height=1080 url=rtsp://%s/ch0_0.h264 snapurl=http://%s/cgi-bin/snapshot.sh type=H264 audio_encoder=AAC audio_decoder=G711

Profile 1

name=Profile_1 width=640 height=360 url=rtsp://%s/ch0_1.h264 snapurl=http://%s/cgi-bin/snapshot.sh type=H264 audio_encoder=AAC audio_decoder=NONE

PTZ

ptz=1 max_step_x=360 max_step_y=180 get_position=/usr/local/bin/get_position is_moving=/usr/local/bin/is_moving move_left=/usr/local/bin/ptz_move -m left move_right=/usr/local/bin/ptz_move -m right move_up=/usr/local/bin/ptz_move -m up move_down=/usr/local/bin/ptz_move -m down move_stop=/usr/local/bin/ptz_move -m stop move_preset=/usr/local/bin/ptz_move -p %d goto_home_position=/usr/local/bin/ptz_move -h set_preset=/usr/local/bin/ptz_presets.sh -a add_preset -m %s set_home_position=/usr/local/bin/ptz_presets.sh -a set_home_position remove_preset=/usr/local/bin/ptz_presets.sh -a del_preset -n %d jump_to_abs=/usr/local/bin/ptz_move -j %f,%f jump_to_rel=/usr/local/bin/ptz_move -J %f,%f get_presets=/usr/local/bin/ptz_presets.sh -a get_presets

EVENT

events=3

Event 0

topic=tns1:VideoSource/MotionAlarm source_name=VideoSourceConfigurationToken source_value=VideoSourceToken input_file=/tmp/onvif_notify_server/motion_alarm

Event 1

topic=tns1:RuleEngine/MyRuleDetector/PeopleDetect source_name=VideoSourceConfigurationToken source_value=VideoSourceToken input_file=/tmp/onvif_notify_server/human_detection

Event 2

topic=tns1:RuleEngine/MyRuleDetector/VehicleDetect source_name=VideoSourceConfigurationToken source_value=VideoSourceToken input_file=/tmp/onvif_notify_server/vehicle_detection

Event 3

topic=tns1:RuleEngine/MyRuleDetector/DogCatDetect source_name=VideoSourceConfigurationToken source_value=VideoSourceToken input_file=/tmp/onvif_notify_server/animal_detection

Event 4

topic=tns1:RuleEngine/MyRuleDetector/BabyCryingDetect source_name=VideoSourceConfigurationToken source_value=VideoSourceToken input_file=/tmp/onvif_notify_server/baby_crying

Event 5

topic=tns1:AudioAnalytics/Audio/DetectedSound source_name=VideoSourceConfigurationToken source_value=VideoSourceToken input_file=/tmp/onvif_notify_server/sound_detection

roleoroleo commented 1 week ago

Configuration is ok. What type of error do you have?

Are you able to capture network traffic?

icedbeancat commented 1 week ago

When testing with the ODM I got: Error during events subscription (unable to create pull point), so most likely a fault message reply. But when i access the logs at /var/log/onvif_simple_server.log, it is empty. Same for testing with python-onvif-zeep client:

Traceback (most recent call last): File "/home/peseyes/Documents/hikvision/myvenv/lib/python3.10/site-packages/onvif/client.py", line 23, in wrapped return func(*args, kwargs) File "/home/peseyes/Documents/hikvision/myvenv/lib/python3.10/site-packages/onvif/client.py", line 153, in wrapped return call(params, callback) File "/home/peseyes/Documents/hikvision/myvenv/lib/python3.10/site-packages/onvif/client.py", line 140, in call ret = func(params) File "/home/peseyes/Documents/hikvision/myvenv/lib/python3.10/site-packages/zeep/proxy.py", line 46, in call return self._proxy._binding.send( File "/home/peseyes/Documents/hikvision/myvenv/lib/python3.10/site-packages/zeep/wsdl/bindings/soap.py", line 135, in send return self.process_reply(client, operation_obj, response) File "/home/peseyes/Documents/hikvision/myvenv/lib/python3.10/site-packages/zeep/wsdl/bindings/soap.py", line 229, in process_reply return self.process_error(doc, operation) File "/home/peseyes/Documents/hikvision/myvenv/lib/python3.10/site-packages/zeep/wsdl/bindings/soap.py", line 391, in process_error raise Fault( zeep.exceptions.Fault: Unable to create pull point

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/peseyes/Documents/hikvision/simple.py", line 13, in pullpt = events_srv.CreatePullPointSubscription() File "/home/peseyes/Documents/hikvision/myvenv/lib/python3.10/site-packages/onvif/client.py", line 26, in wrapped raise ONVIFError(err) onvif.exceptions.ONVIFError: Unknown error: Unable to create pull point

Here is my strace output when I try to connect to events service: epoll_wait(4, [{events=EPOLLIN, data={u32=1680410160, u64=94825968371248}}], 1025, 1000) = 1 accept4(3, {sa_family=AF_INET, sin_port=htons(62967), sin_addr=inet_addr("192.168.1.49")}, [112 => 16], SOCK_CLOEXEC|SOCK_NONBLOCK) = 7 read(7, 0x563e642a0750, 8192) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(4, EPOLL_CTL_ADD, 7, {events=EPOLLIN|EPOLLERR|EPOLLHUP|EPOLLRDHUP, data={u32=1680484592, u64=94825968445680}}) = 0 accept4(3, 0x7ffe08795140, [112], SOCK_CLOEXEC|SOCK_NONBLOCK) = -1 EAGAIN (Resource temporarily unavailable) epoll_wait(4, [{events=EPOLLIN, data={u32=1680484592, u64=94825968445680}}], 1025, 1000) = 1 read(7, "POST /onvif/events_service HTTP/"..., 8192) = 189 newfstatat(AT_FDCWD, "/usr/local/www/onvif/events_service", {st_mode=S_IFREG|0755, st_size=143760, ...}, 0) = 0 epoll_wait(4, [{events=EPOLLIN, data={u32=1680484592, u64=94825968445680}}], 1025, 1000) = 1 read(7, "<s:Envelope xmlns:s=\"http://www."..., 8192) = 1325 pipe2([8, 9], O_CLOEXEC) = 0 fcntl(9, F_SETFL, O_RDWR|O_NONBLOCK) = 0 pipe2([10, 11], O_CLOEXEC) = 0 fcntl(10, F_SETFL, O_RDWR|O_NONBLOCK) = 0 getsockname(7, {sa_family=AF_INET, sin_port=htons(8080), sin_addr=inet_addr("192.168.1.109")}, [112 => 16]) = 0 openat(AT_FDCWD, "/usr/local/www/onvif", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 12 prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=10241024}) = 0 prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=10241024}) = 0 mmap(NULL, 36864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7fb3a3449000 rt_sigprocmask(SIG_BLOCK, ~[], [], 8) = 0 clone3({flags=CLONE_VM|CLONE_VFORK, exit_signal=SIGCHLD, stack=0x7fb3a3449000, stack_size=0x9000}, 88strace: Process 7451 attached <unfinished ...> [pid 7451] rt_sigprocmask(SIG_BLOCK, NULL, ~[KILL STOP], 8) = 0 [pid 7451] rt_sigaction(SIGHUP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fb3a325e520}, NULL, 8) = 0 [pid 7451] rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fb3a325e520}, NULL, 8) = 0 ... writev(7, [{iov_base="HTTP/1.1 200 OK\r\nContent-type: a"..., iov_len=158}, {iov_base="<?xml version=\"1.0\" encoding=\"UT"..., iov_len=3948}], 2) = 4106 shutdown(7, SHUT_WR) = 0 recvfrom(7, 0x7ffe08791200, 16384, MSG_TRUNC|MSG_DONTWAIT|MSG_NOSIGNAL, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(4, EPOLL_CTL_DEL, 7, NULL) = 0 close(10) = 0 wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], WNOHANG, NULL) = 7451 wait4(-1, 0x7ffe08795234, WNOHANG, NULL) = -1 ECHILD (No child processes) epoll_wait(4, [{events=EPOLLIN|EPOLLHUP|EPOLLRDHUP, data={u32=1680484592, u64=94825968445680}}], 1025, 1000) = 1 recvfrom(7, "", 16384, MSG_TRUNC|MSG_DONTWAIT|MSG_NOSIGNAL, NULL, NULL) = 0 epoll_ctl(4, EPOLL_CTL_DEL, 7, NULL) = 0 close(7) = 0 epoll_wait(4, [], 1025, 1000) = 0

no visible errors.

When I tested with python-onvif-zeep client with this code:

from onvif import ONVIFCamera mycam = ONVIFCamera("192.168.1.109", 8080, "admin", "admin") device_srv = mycam.create_devicemgmt_service() events_srv = mycam.create_events_service() print(events_srv.GetServiceCapabilities())

i got this output: { '_value_1': None, 'WSSubscriptionPolicySupport': True, 'WSPullPointSupport': True, 'WSPausableSubscriptionManagerInterfaceSupport': False, 'MaxNotificationProducers': None, 'MaxPullPoints': None, 'PersistentNotificationStorage': None, '_attr_1': { } } [{ 'Name': 'VideoSourceConfig', 'UseCount': 2, 'SourceToken': 'VideoSourceToken', 'Bounds': { 'x': 0, 'y': 0, 'width': 1920, 'height': 1080 }, '_value_1': None, 'Extension': None, 'token': 'VideoSourceConfigToken', '_attr_1': { } }]

roleoroleo commented 1 week ago

To enable debug log: echo 5 > /tmp/onvif_simple_server.debug You will find debug files in /var/log

Capturing network traffic helps debugging.