Skip to content

presatish/device-onvif-camera

 
 

Repository files navigation

Onvif Camera Device Service

Build Status Code Coverage Go Report Card GitHub Latest Dev Tag) GitHub Latest Stable Tag) GitHub License GitHub go.mod Go version GitHub Pull Requests GitHub Contributors GitHub Committers GitHub Commit Activity

This Onvif Camera Device Service is developed to control/communicate ONVIF-compliant cameras accessible via http in an EdgeX deployment

Onvif Features

The device service supports the onvif features listed in the following table:

Feature Onvif Web Service Onvif Function EdgeX Value Type
User Authentication Core WS-Usernametoken Authentication Object
HTTP Digest Object
Auto Discovery Core WS-Discovery Object
Device GetDiscoveryMode Object
SetDiscoveryMode Object
GetScopes Object
SetScopes Object
AddScopes Object
RemoveScopes Object
Network Configuration Device GetHostname Object
SetHostname Object
GetDNS Object
SetDNS Object
GetNetworkInterfaces Object
SetNetworkInterfaces Object
GetNetworkProtocols Object
SetNetworkProtocols Object
GetNetworkDefaultGateway Object
SetNetworkDefaultGateway Object
System Function Device GetDeviceInformation Object
GetSystemDateAndTime Object
SetSystemDateAndTime Object
SetSystemFactoryDefault Object
SystemReboot Object
User Handling Device GetUsers Object
CreateUsers Object
DeleteUsers Object
SetUser Object
Metadata Configuration Media GetMetadataConfiguration Object
GetMetadataConfigurations Object
GetCompatibleMetadataConfigurations Object
GetMetadataConfigurationOptions Object
AddMetadataConfiguration Object
RemoveMetadataConfiguration Object
SetMetadataConfiguration Object
Video Streaming Media GetProfiles Object
GetStreamUri Object
VideoEncoder Config Media GetVideoEncoderConfiguration Object
SetVideoEncoderConfiguration Object
GetVideoEncoderConfigurationOptions Object
PTZ Configuration PTZ GetNode Object
GetConfigurations Object
GetConfiguration Object
GetConfigurationOptions Object
SetConfiguration Object
Media AddPTZConfiguration Object
Media RemovePTZConfiguration Object
PTZ Actuation PTZ AbsoluteMove Object
RelativeMove Object
ContinuousMove Object
Stop Object
GetStatus Object
GetPresets Object
GotoPreset Object
RemovePreset Object
PTZ Home Position PTZ GotoHomePosition Object
SetHomePosition Object
PTZ AuxiliaryOperations PTZ SendAuxiliaryCommand Object
Event Handling Event Notify Object
Subscribe Object
Renew Object
Unsubscribe Object
CreatePullPointSubscription Object
PullMessages Object
TopicFilter Object
MessageContentFilter Object
Configuration of Analytics profile Media2 GetProfiles Object
GetAnalyticsConfigurations Object
AddConfiguration Object
RemoveConfiguration Object
Analytics Module configuration Analytics GetSupportedAnalyticsModules Object
GetAnalyticsModules Object
CreateAnalyticsModules Object
DeleteAnalyticsModules Object
GetAnalyticsModuleOptions Object
ModifyAnalyticsModules Object
Rule configuration Analytics GetSupportedRules Object
GetRules Object
CreateRules Object
DeleteRules Object
GetRuleOptions Object
ModifyRule Object

Note: The functions in the bold text are mandatory for Onvif protocol.

Custom Features

The device service also include custom function to enhance the usage for the EdgeX user.

Feature Service Function EdgeX Value Type Description
System Function EdgeX RebootNeeded Bool Read only. Used to indicate the camera should reboot to apply the configuration change
System Function EdgeX CameraEvent Bool A device resource which is used to send the async event to north bound
System Function EdgeX SubscribeCameraEvent Bool Create a subscription to subscribe the event from the camera
System Function EdgeX UnsubscribeCameraEvent Bool Unsubscribe all subscription from the camera
Media EdgeX GetSnapshot Binary Get Snapshot from the snapshot uri
Custom Metadata EdgeX CustomMetadata Object Read and write custom metadata to the camera entry in EdgeX
Custom Metadata EdgeX DeleteCustomMetadata Object Delete custom metadata fields from the camera entry in EdgeX

How does the device service work?

The Onvif camera uses Web Services standards such as XML, SOAP 1.2 and WSDL1.1 over an IP network.

  • XML is used as the data description syntax
  • SOAP is used for message transfer
  • and WSDL is used for describing the services.

The spec can refer to ONVIF-Core-Specification.

For example, we can send a SOAP request to the Onvif camera as below:

curl --request POST 'http://192.168.12.128:2020/onvif/service' \
--header 'Content-Type: application/soap+xml' \
--data-raw '<?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:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:onvif="http://www.onvif.org/ver10/schema" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" >
    <soap-env:Header>
        <Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <UsernameToken>
                <Username>myUsername</Username>
                <Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">+HKcvc+LCGClVwuros1sJuXepQY=</Password>
                <Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">w490bn6rlib33d5rb8t6ulnqlmz9h43m</Nonce>
                <Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2021-10-21T03:43:21.02075Z</Created>
            </UsernameToken>
        </Security>
    </soap-env:Header>
    <soap-env:Body>
        <trt:GetStreamUri>
            <trt:ProfileToken>profile_1</trt:ProfileToken>
        </trt:GetStreamUri>
    </soap-env:Body>
  </soap-env:Envelope>'

And the response should be like the following XML data:

<?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:chan="http://schemas.microsoft.com/ws/2005/02/duplex"
	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" xmlns:wsa5="http://www.w3.org/2005/08/addressing"
	xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2"
	xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"
	xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:tns1="http://www.onvif.org/ver10/topics"
	xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl"
	xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tdn="http://www.onvif.org/ver10/network/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl"
	xmlns:trp="http://www.onvif.org/ver10/replay/wsdl" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl">
	<SOAP-ENV:Header></SOAP-ENV:Header>
	<SOAP-ENV:Body>
		<trt:GetStreamUriResponse>
			<trt:MediaUri>
				<tt:Uri>rtsp://192.168.12.128:554/stream1</tt:Uri>
				<tt:InvalidAfterConnect>false</tt:InvalidAfterConnect>
				<tt:InvalidAfterReboot>false</tt:InvalidAfterReboot>
				<tt:Timeout>PT0H0M2S</tt:Timeout>
			</trt:MediaUri>
		</trt:GetStreamUriResponse>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Since the SOAP is a HTTP call, the device service can just do the transformation between REST(JSON) and SOAP(XML).

For the concept of implementation:

  • The device service accepts the REST request from the client, then transforms the request to SOAP format and forward it to the Onvif camera.
  • Once the device service receives the response from the Onvif camera, the device service will transform the SOAP response to REST format for the client.
                  - Onvif Web Service

                  - Onvif Function  ┌────────────────────┐
                                    │                    │
┌──────────────┐  - Input Parameter │   Device Service   │               ┌─────────────────┐
│              │                    │                    │               │                 │
│              │ REST request       │                    │ SOAP request  │                 │
│    Client  ──┼────────────────────┼──►  Transform  ────┼───────────────┼──► Onvif Camera │
│              │                    │   to SOAP request  │               │                 │
│              │                    │                    │               │                 │
└──────────────┘                    └────────────────────┘               └─────────────────┘


                                    ┌────────────────────┐
                                    │                    │
┌──────────────┐                    │   Device Service   │               ┌─────────────────┐
│              │                    │                    │               │                 │
│              │ REST response      │                    │ SOAP response │                 │
│    Client  ◄─┼────────────────────┼───  Transform   ◄──┼───────────────┼── Onvif Camera  │
│              │                    │   to REST response │               │                 │
│              │                    │                    │               │                 │
└──────────────┘                    └────────────────────┘               └─────────────────┘

General Usage

Run Unit Test

make test

Build the executable file

make build

Build docker image

Build docker image named edgex/device-onvif-camera:0.0.0-dev with the following command:

make docker

Define the device profile

The device resource should provide two attributes:

  • service indicates the web service for the Onvif
  • function indicates the SOAP action for the specified web service

For example:

deviceResources:
  - name: "Hostname"
    isHidden: false
    description: "Camera Hostname"
    attributes:
      service: "Device"
      getFunction: "GetHostname"
      setFunction: "SetHostname"
    properties:
      valueType: "Object"
      readWrite: "RW"

See the sample at cmd/res/profiles/camera.yaml

Define the device

The device's protocol properties should contain:

  • Address is the IP address of the Onvif camera
  • Port is the server port of the Onvif camera
  • AuthMode indicates the auth mode of the Onvif camera
  • SecretPath indicates the path to retrieve the username and password

For example:

[[DeviceList]]
Name = "Camera001"
ProfileName = "camera"
Description = "My test camera"
  [DeviceList.Protocols]
    [DeviceList.Protocols.Onvif]
    Address = "192.168.12.123"
    Port = 80
    # Assign AuthMode to "digest" | "usernametoken" | "both" | "none"
    AuthMode = "usernametoken"
    SecretPath = "credentials001"

See the sample at cmd/res/devices/camera.toml.example

Getting Started Guide

Tested Onvif Camera

Tested Onvif cameras with Onvif functions.

Pass parameter via URL query parameter

Get Command Parameter

Custom feature for device-onvif-go

RebootNeeded

API Usage

Onvif User Authentication

Setup Onvif User Authentication

Auto Discovery

Control Plane Events

Control Plane Events

License

Apache-2.0

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 90.3%
  • Shell 7.2%
  • Makefile 1.5%
  • Dockerfile 1.0%