Automatic Discovery with ONVIF and gSOAP
The Behavior
PROBE: The camera manager app sends an UDP broadcast message on a multicast IP 239.255.255.250 port 3702. This message is referred to as the "Probe" request.
PROBEMATCHES: Each camera devices that have received the UDP message responds directly on a one-by-one basis to the IP of the sender of the Probe message.
HELLO:
BYE:
The Implementation
I found it hard to integrate the ws-discovery within the onvif application due to difference in header files and colliding wsdl files and the need to manually edit a .h before running some steps that are usually automated.
So I will make a separate ws-discovery app.
- include
gsoap/plugin/wsddapi.hin your source code; - compile
gsoap/plugin/wsddapi.cwith your ONVIF application.
Windows Implementation Example for Testing / Debugging
https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/WebServicesDevicesApi/WSDiscovery/cpp/Client
Problems
UDP Multicast Broadcast not working on Windows 10
https://stackoverflow.com/questions/43475468/windows-python-udp-broadcast-blocked-no-firewall
Compile Problem #1
$> gsoap/src/soapcpp2 -c -L -x -S -d ./generated -I./gsoap-2.8/gsoap:./gsoap-2.8/gsoap/import generated/onvif.h
wsa5.h(279): *WARNING*: Duplicate declaration of 'SOAP_ENV__Fault' (already declared at line 264)
wsa5.h(289): **ERROR**: service operation name clash: struct/class 'SOAP_ENV__Fault' already declared at wsa.h:274
Solution
Change in your typemap.dat from
wsdd = <http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01>
#wsdd5 = <http://schemas.xmlsoap.org/ws/2005/04/discovery>
wsdd10 = <http://schemas.xmlsoap.org/ws/2005/04/discovery>
to
wsdd = <http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01>
wsdd5 = <http://schemas.xmlsoap.org/ws/2005/04/discovery>
#wsdd10 = <http://schemas.xmlsoap.org/ws/2005/04/discovery>
Problem
.2.1/build/OSCAR/output/libs -lmxsessmgr -lmxtools -lmxcfgfile -lcrypt -lhailogin -lmxclock -lmxfpga -lrt
./src/ServiceDiscovery_debug.o:(.data+0x0): multiple definition of `namespaces'
./src/onvif_srvd_debug.o:(.data+0x0): first defined here
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__Hello':
/home/flemieux/onvif/onvif-server/gsoap-2.8/gsoap/plugin/wsddapi.c:1205: multiple definition of `__wsdd__Hello'
./src/ServiceDiscovery_debug.o:/home/flemieux/onvif/onvif-server/src/ServiceDiscovery.c:42: first defined here
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__Bye':
/home/flemieux/onvif/onvif-server/gsoap-2.8/gsoap/plugin/wsddapi.c:1277: multiple definition of `__wsdd__Bye'
./src/ServiceDiscovery_debug.o:/home/flemieux/onvif/onvif-server/src/ServiceDiscovery.c:47: first defined here
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__Probe':
/home/flemieux/onvif/onvif-server/gsoap-2.8/gsoap/plugin/wsddapi.c:1358: multiple definition of `__wsdd__Probe'
./src/ServiceDiscovery_debug.o:/home/flemieux/onvif/onvif-server/src/ServiceDiscovery.c:51: first defined here
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__ProbeMatches':
/home/flemieux/onvif/onvif-server/gsoap-2.8/gsoap/plugin/wsddapi.c:1427: multiple definition of `__wsdd__ProbeMatches'
./src/ServiceDiscovery_debug.o:/home/flemieux/onvif/onvif-server/src/ServiceDiscovery.c:112: first defined here
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__Resolve':
/home/flemieux/onvif/onvif-server/gsoap-2.8/gsoap/plugin/wsddapi.c:1481: multiple definition of `__wsdd__Resolve'
./src/ServiceDiscovery_debug.o:/home/flemieux/onvif/onvif-server/src/ServiceDiscovery.c:116: first defined here
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__ResolveMatches':
/home/flemieux/onvif/onvif-server/gsoap-2.8/gsoap/plugin/wsddapi.c:1558: multiple definition of `__wsdd__ResolveMatches'
./src/ServiceDiscovery_debug.o:/home/flemieux/onvif/onvif-server/src/ServiceDiscovery.c:121: first defined here
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `soap_wsdd_Hello':
wsddapi.c:(.text+0xe0): undefined reference to `soap_send___wsdd__Hello'
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `soap_wsdd_Bye':
wsddapi.c:(.text+0x22c): undefined reference to `soap_send___wsdd__Bye'
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `soap_wsdd_Probe':
wsddapi.c:(.text+0x384): undefined reference to `soap_send___wsdd__Probe'
wsddapi.c:(.text+0x3f4): undefined reference to `soap_recv___wsdd__ProbeMatches'
wsddapi.c:(.text+0x580): undefined reference to `wsdd_event_ProbeMatches'
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `soap_wsdd_Resolve':
wsddapi.c:(.text+0x674): undefined reference to `soap_send___wsdd__Resolve'
wsddapi.c:(.text+0x6e4): undefined reference to `soap_recv___wsdd__ResolveMatches'
wsddapi.c:(.text+0x890): undefined reference to `wsdd_event_ResolveMatches'
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `soap_wsdd_ProbeMatches':
wsddapi.c:(.text+0xbb4): undefined reference to `soap_send___wsdd__ProbeMatches'
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `soap_wsdd_ResolveMatches':
wsddapi.c:(.text+0xd08): undefined reference to `soap_send___wsdd__ResolveMatches'
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__Hello':
wsddapi.c:(.text+0x19f0): undefined reference to `wsdd_event_Hello'
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__Bye':
wsddapi.c:(.text+0x1d98): undefined reference to `wsdd_event_Bye'
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__Probe':
wsddapi.c:(.text+0x1ffc): undefined reference to `wsdd_event_Probe'
wsddapi.c:(.text+0x20b8): undefined reference to `soap_send___wsdd__ProbeMatches'
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__ProbeMatches':
wsddapi.c:(.text+0x2344): undefined reference to `wsdd_event_ProbeMatches'
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__Resolve':
wsddapi.c:(.text+0x2530): undefined reference to `wsdd_event_Resolve'
wsddapi.c:(.text+0x25ec): undefined reference to `soap_send___wsdd__ResolveMatches'
./gsoap-2.8/gsoap/plugin/wsddapi_debug.o: In function `__wsdd__ResolveMatches':
wsddapi.c:(.text+0x2888): undefined reference to `wsdd_event_ResolveMatches'
collect2: ld returned 1 exit status
make: *** [onvif_srvd_debug] Error 1
Solution
TBD
Problem
multiple definition of `namespaces'
Solution
Change your makefile so the second generation contains both -pXYZ and -n such as :
# this will also generate soapServer.c
$(GENERATED_DIR)/soapC.c: $(GENERATED_DIR)/onvif.h
$(SOAPCPP2) -c -L -x -S -d $(GENERATED_DIR) -I$(GSOAP_DIR):$(GSOAP_IMPORT_DIR) $<
# this will also generate wsddServer.c
$(GENERATED_DIR)/wsddC.c: $(GENERATED_DIR)/onvif.h
$(SOAPCPP2) -c -L -x -S -d $(GENERATED_DIR) -pwsdd -n -I$(GSOAP_DIR):$(GSOAP_IMPORT_DIR) $(GSOAP_IMPORT_DIR)/wsdd5.h $<
The wrong one that caused the problem
# this will also generate soapServer.c
$(GENERATED_DIR)/soapC.c: $(GENERATED_DIR)/onvif.h
$(SOAPCPP2) -c -L -x -S -d $(GENERATED_DIR) -I$(GSOAP_DIR):$(GSOAP_IMPORT_DIR) $<
# this will also generate wsddServer.c
$(GENERATED_DIR)/wsddC.c: $(GENERATED_DIR)/onvif.h
$(SOAPCPP2) -c -L -x -S -d $(GENERATED_DIR) -pwsdd -I$(GSOAP_DIR):$(GSOAP_IMPORT_DIR) $(GSOAP_IMPORT_DIR)/wsdd5.h $<
Problems
After adding $(GENERATED_DIR)/wsddC.c to the list of compiled sources, we get bunch of dupplicated linkage errors:
./generated/soapC_debug.o:/home/flemieux/onvif/onvif-server/generated/soapC.c:209262: first defined here
./generated/wsddC_debug.o: In function `soap_out_wsa5__RelationshipTypeOpenEnum':
/home/flemieux/onvif/onvif-server/generated/wsddC.c:209270: multiple definition of `soap_out_wsa5__RelationshipTypeOpenEnum'
./generated/soapC_debug.o:/home/flemieux/onvif/onvif-server/generated/soapC.c:209270: first defined here
./generated/wsddC_debug.o: In function `soap_put_wsa5__RelationshipTypeOpenEnum':
/home/flemieux/onvif/onvif-server/generated/wsddC.c:209281: multiple definition of `soap_put_wsa5__RelationshipTypeOpenEnum'
./generated/soapC_debug.o:/home/flemieux/onvif/onvif-server/generated/soapC.c:209281: first defined here
./generated/wsddC_debug.o: In function `soap_get_wsa5__RelationshipTypeOpenEnum':
/home/flemieux/onvif/onvif-server/generated/wsddC.c:209288: multiple definition of `soap_get_wsa5__RelationshipTypeOpenEnum'
./generated/soapC_debug.o:/home/flemieux/onvif/onvif-server/generated/soapC.c:209288: first defined here
./generated/wsddC_debug.o: In function `soap_put__QName':
/home/flemieux/onvif/onvif-server/generated/wsddC.c:209315: multiple definition of `soap_put__QName'
./generated/soapC_debug.o:/home/flemieux/onvif/onvif-server/generated/soapC.c:209315: first defined here
./generated/wsddC_debug.o: In function `soap_get__QName':
/home/flemieux/onvif/onvif-server/generated/wsddC.c:209322: multiple definition of `soap_get__QName'
./generated/soapC_debug.o:/home/flemieux/onvif/onvif-server/generated/soapC.c:209322: first defined here
./generated/wsddC_debug.o: In function `soap_new_string':
/home/flemieux/onvif/onvif-server/generated/wsddC.c:209349: multiple definition of `soap_new_string'
./generated/soapC_debug.o:/home/flemieux/onvif/onvif-server/generated/soapC.c:209349: first defined here
./generated/wsddC_debug.o: In function `soap_put_string':
/home/flemieux/onvif/onvif-server/generated/wsddC.c:209358: multiple definition of `soap_put_string'
./generated/soapC_debug.o:/home/flemieux/onvif/onvif-server/generated/soapC.c:209358: first defined here
./generated/wsddC_debug.o: In function `soap_get_string':
/home/flemieux/onvif/onvif-server/generated/wsddC.c:209365: multiple definition of `soap_get_string'
./generated/soapC_debug.o:/home/flemieux/onvif/onvif-server/generated/soapC.c:209365: first defined here
collect2: ld returned 1 exit status
make: *** [onvif_srvd_debug] Error 1
$
Support Threads
https://supportcommunity.milestonesys.com/s/question/0D50O000049u3LTSAY/onvif-discovery-problem?t=1559148116669
https://supportcommunity.milestonesys.com/s/question/0D53X00005to9nVSAQ/how-to-fully-remove-a-device-from-xprotect-and-its-previous-settings
References
https://www.genivia.com/doc/wsdd/html/wsdd_0.html
https://sourceforge.net/p/gsoap2/bugs/999/
https://stackoverflow.com/questions/46076501/gsoap-onvif-and-discovery
https://stackoverflow.com/questions/27061083/onvif-ws-discover-1-0-client-and-event-handlers
https://github.com/mpromonet/ws-discovery/blob/master/gsoap/probe.cpp
https://github.com/johnnywww/nvtonvifserverc/blob/master/onvifHandleProbe.c
https://github.com/alb423/wsdiscovery/blob/master/mySoapStub.c
https://github.com/georgSquared/WS-Discovery
http://sett.com/ionelpop/onvif-gsoap-part-2-ws-discovery-file-generation
http://albert-oma.blogspot.com/2013/09/onvif-ws-discovery-implementation.html
Recent Comments