onvif

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2022 License: MIT Imports: 24 Imported by: 0

README

Onvif library

Simple management of onvif IP-devices cameras. onvif is an implementation of ONVIF protocol for managing onvif IP devices. The purpose of this library is convenient and easy management of IP cameras and other devices that support ONVIF standard.

Overview

This repository is forked from: use-go/onvif

Supported services

The following services are implemented:

  • Device
  • Media
  • PTZ
  • Event
  • Discovery

Using

General concept
  1. Connecting to the device
  2. Authentication (if necessary)
  3. Defining Data Types
  4. Carrying out the required method
Connecting to the device

If there is a device on the network at the address 192.168.13.42, and its ONVIF services use the 1234 port, then you can connect to the device in the following way:

dev, err := onvif.NewDevice(onvif.DeviceParams{Xaddr: "192.168.13.42:1234"})

The ONVIF port may differ depending on the device , to find out which port to use, you can go to the web interface of the device. Usually this is 80 port.

Authentication

If any function of the ONVIF services requires authentication, you must use the Authenticate method.

device := onvif.NewDevice(onvif.DeviceParams{Xaddr: "192.168.13.42:1234", Username: "username", Password: password})
Defining Data Types

Each ONVIF service in this library has its own package, in which all data types of this service are defined, and the package name is identical to the service name and begins with a capital letter. onvif defines the structures for each function of each ONVIF service supported by this library. Define the data type of the GetCapabilities function of the Device service. This is done as follows:

capabilities := device.GetCapabilities{Category:"All"}

Why does the GetCapabilities structure have the Category field and why is the value of this field All?

The figure below shows the documentation for the GetCapabilities. It can be seen that the function takes one Category parameter and its value should be one of the following: 'All', 'Analytics',' Device ',' Events', 'Imaging', 'Media' or 'PTZ'`.

Device GetCapabilities

An example of defining the data type of GetServiceCapabilities function in PTZ:

ptzCapabilities := ptz.GetServiceCapabilities{}

The figure below shows that GetServiceCapabilities does not accept any arguments.

PTZ GetServiceCapabilities

Common data types are in the xsd/onvif package. The types of data (structures) that can be shared by all services are defined in the onvif package.

An example of how to define the data type of the CreateUsers function in Devicemgmt:

createUsers := device.CreateUsers{User: onvif.User{Username:"admin", Password:"qwerty", UserLevel:"User"}}

The figure below shows that ,in this example, the CreateUsers structure field must be a User whose data type is the User structure containing the Username, Password, UserLevel, and optional Extension fields. The User structure is in the onvif package.

Device CreateUsers

Carrying out the required method

To perform any function of one of the ONVIF services whose structure has been defined, you must use the CallMethod of the device object.

createUsers := device.CreateUsers{User: onvif.User{Username:"admin", Password:"qwerty", UserLevel:"User"}}
device := onvif.NewDevice(onvif.DeviceParams{Xaddr: "192.168.13.42:1234", Username: "username", Password: password})
device.Authenticate("username", "password")
resp, err := dev.CallMethod(createUsers)

Documentation

Overview

Package onvif is developed to provide an ONVIF client implementation on Go programming language

Index

Constants

View Source
const (
	DeviceWebService    = "Device"
	EventWebService     = "Event"
	MediaWebService     = "Media"
	Media2WebService    = "Media2"
	PTZWebService       = "PTZ"
	AnalyticsWebService = "Analytics"
)

Onvif WebService

View Source
const (
	// WebService - Device
	GetHostname              = "GetHostname"
	SetHostname              = "SetHostname"
	GetDNS                   = "GetDNS"
	SetDNS                   = "SetDNS"
	GetNetworkInterfaces     = "GetNetworkInterfaces"
	SetNetworkInterfaces     = "SetNetworkInterfaces"
	GetNetworkProtocols      = "GetNetworkProtocols"
	SetNetworkProtocols      = "SetNetworkProtocols"
	GetNetworkDefaultGateway = "GetNetworkDefaultGateway"
	SetNetworkDefaultGateway = "SetNetworkDefaultGateway"

	GetDeviceInformation    = "GetDeviceInformation"
	GetSystemDateAndTime    = "GetSystemDateAndTime"
	SetSystemDateAndTime    = "SetSystemDateAndTime"
	SetSystemFactoryDefault = "SetSystemFactoryDefault"
	SystemReboot            = "SystemReboot"

	GetUsers    = "GetUsers"
	CreateUsers = "CreateUsers"
	DeleteUsers = "DeleteUsers"
	SetUser     = "SetUser"

	GetDiscoveryMode = "GetDiscoveryMode"
	SetDiscoveryMode = "SetDiscoveryMode"
	GetScopes        = "GetScopes"
	SetScopes        = "SetScopes"
	AddScopes        = "AddScopes"
	RemoveScopes     = "RemoveScopes"

	// WebService - Media
	GetMetadataConfiguration            = "GetMetadataConfiguration"
	GetMetadataConfigurations           = "GetMetadataConfigurations"
	AddMetadataConfiguration            = "AddMetadataConfiguration"
	RemoveMetadataConfiguration         = "RemoveMetadataConfiguration"
	SetMetadataConfiguration            = "SetMetadataConfiguration"
	GetCompatibleMetadataConfigurations = "GetCompatibleMetadataConfigurations"
	GetMetadataConfigurationOptions     = "GetMetadataConfigurationOptions"
	GetProfiles                         = "GetProfiles"
	GetStreamUri                        = "GetStreamUri"
	GetVideoEncoderConfiguration        = "GetVideoEncoderConfiguration"
	GetVideoEncoderConfigurations       = "GetVideoEncoderConfigurations"
	SetVideoEncoderConfiguration        = "SetVideoEncoderConfiguration"
	GetVideoEncoderConfigurationOptions = "GetVideoEncoderConfigurationOptions"

	// WebService - Media2
	GetAnalyticsConfigurations = "GetAnalyticsConfigurations"
	AddConfiguration           = "AddConfiguration"
	RemoveConfiguration        = "RemoveConfiguration"

	// WebService - PTZ
	GetNodes                = "GetNodes"
	GetNode                 = "GetNode"
	GetConfigurations       = "GetConfigurations"
	GetConfiguration        = "GetConfiguration"
	GetConfigurationOptions = "GetConfigurationOptions"
	SetConfiguration        = "SetConfiguration"
	AddPTZConfiguration     = "AddPTZConfiguration"
	RemovePTZConfiguration  = "RemovePTZConfiguration"
	AbsoluteMove            = "AbsoluteMove"
	RelativeMove            = "RelativeMove"
	ContinuousMove          = "ContinuousMove"
	Stop                    = "Stop"
	GetStatus               = "GetStatus"
	SetPreset               = "SetPreset"
	GetPresets              = "GetPresets"
	GotoPreset              = "GotoPreset"
	RemovePreset            = "RemovePreset"
	GotoHomePosition        = "GotoHomePosition"
	SetHomePosition         = "SetHomePosition"
	SendAuxiliaryCommand    = "SendAuxiliaryCommand"

	// WebService - Event
	GetEventProperties          = "GetEventProperties"
	CreatePullPointSubscription = "CreatePullPointSubscription"
	PullMessages                = "PullMessages"
	Unsubscribe                 = "Unsubscribe"
	Subscribe                   = "Subscribe"
	Renew                       = "Renew"

	// WebService - Analytics
	GetSupportedAnalyticsModules = "GetSupportedAnalyticsModules"
	GetAnalyticsModules          = "GetAnalyticsModules"
	CreateAnalyticsModules       = "CreateAnalyticsModules"
	DeleteAnalyticsModules       = "DeleteAnalyticsModules"
	GetAnalyticsModuleOptions    = "GetAnalyticsModuleOptions"
	ModifyAnalyticsModules       = "ModifyAnalyticsModules"

	GetSupportedRules = "GetSupportedRules"
	GetRules          = "GetRules"
	CreateRules       = "CreateRules"
	DeleteRules       = "DeleteRules"
	GetRuleOptions    = "GetRuleOptions"
	ModifyRules       = "ModifyRules"
)

Onvif WebService function

View Source
const (
	DigestAuth        = "digest"
	UsernameTokenAuth = "usernametoken"
	Both              = "both"
	NoAuth            = "none"
)

Onvif Auth Mode

Variables

View Source
var AnalyticsFunctionMap = map[string]Function{

	GetSupportedAnalyticsModules: &analytics.GetSupportedAnalyticsModulesFunction{},
	GetAnalyticsModules:          &analytics.GetAnalyticsModulesFunction{},
	CreateAnalyticsModules:       &analytics.CreateAnalyticsModulesFunction{},
	DeleteAnalyticsModules:       &analytics.DeleteAnalyticsModulesFunction{},
	GetAnalyticsModuleOptions:    &analytics.GetAnalyticsModuleOptionsFunction{},
	ModifyAnalyticsModules:       &analytics.ModifyAnalyticsModulesFunction{},

	GetSupportedRules: &analytics.GetSupportedRulesFunction{},
	GetRules:          &analytics.GetRulesFunction{},
	CreateRules:       &analytics.CreateRulesFunction{},
	DeleteRules:       &analytics.DeleteRulesFunction{},
	GetRuleOptions:    &analytics.GetRuleOptionsFunction{},
	ModifyRules:       &analytics.ModifyRulesFunction{},
}
View Source
var DeviceFunctionMap = map[string]Function{

	GetHostname:              &device.GetHostnameFunction{},
	SetHostname:              &device.SetHostnameFunction{},
	GetDNS:                   &device.GetDNSFunction{},
	SetDNS:                   &device.SetDNSFunction{},
	GetNetworkInterfaces:     &device.GetNetworkInterfacesFunction{},
	SetNetworkInterfaces:     &device.SetNetworkInterfacesFunction{},
	GetNetworkProtocols:      &device.GetNetworkProtocolsFunction{},
	SetNetworkProtocols:      &device.SetNetworkProtocolsFunction{},
	GetNetworkDefaultGateway: &device.GetNetworkDefaultGatewayFunction{},
	SetNetworkDefaultGateway: &device.SetNetworkDefaultGatewayFunction{},

	GetDeviceInformation:    &device.GetDeviceInformationFunction{},
	GetSystemDateAndTime:    &device.GetSystemDateAndTimeFunction{},
	SetSystemDateAndTime:    &device.SetSystemDateAndTimeFunction{},
	SetSystemFactoryDefault: &device.SetSystemFactoryDefaultFunction{},
	SystemReboot:            &device.SystemRebootFunction{},

	GetUsers:    &device.GetUsersFunction{},
	SetUser:     &device.SetUserFunction{},
	CreateUsers: &device.CreateUsersFunction{},
	DeleteUsers: &device.DeleteUsersFunction{},

	GetDiscoveryMode: &device.GetDiscoveryModeFunction{},
	SetDiscoveryMode: &device.SetDiscoveryModeFunction{},
	GetScopes:        &device.GetScopesFunction{},
	SetScopes:        &device.SetScopesFunction{},
	AddScopes:        &device.AddScopesFunction{},
	RemoveScopes:     &device.RemoveScopesFunction{},
}
View Source
var EventFunctionMap = map[string]Function{
	GetEventProperties:          &event.GetEventPropertiesFunction{},
	CreatePullPointSubscription: &event.CreatePullPointSubscriptionFunction{},
	PullMessages:                &event.PullMessagesFunction{},
	Unsubscribe:                 &event.UnsubscribeFunction{},
	Subscribe:                   &event.SubscribeFunction{},
	Renew:                       &event.RenewFunction{},
}
View Source
var Media2FunctionMap = map[string]Function{
	GetProfiles:                &media2.GetProfilesFunction{},
	GetAnalyticsConfigurations: &media2.GetAnalyticsConfigurationsFunction{},
	AddConfiguration:           &media2.AddConfigurationFunction{},
	RemoveConfiguration:        &media2.RemoveConfigurationFunction{},
}
View Source
var MediaFunctionMap = map[string]Function{

	GetMetadataConfiguration:            &media.GetMetadataConfigurationFunction{},
	GetMetadataConfigurations:           &media.GetMetadataConfigurationsFunction{},
	AddMetadataConfiguration:            &media.AddMetadataConfigurationFunction{},
	RemoveMetadataConfiguration:         &media.RemoveMetadataConfigurationFunction{},
	SetMetadataConfiguration:            &media.SetMetadataConfigurationFunction{},
	GetCompatibleMetadataConfigurations: &media.GetCompatibleMetadataConfigurationsFunction{},
	GetMetadataConfigurationOptions:     &media.GetMetadataConfigurationOptionsFunction{},

	GetProfiles:  &media.GetProfilesFunction{},
	GetStreamUri: &media.GetStreamUriFunction{},

	GetVideoEncoderConfiguration:        &media.GetVideoEncoderConfigurationFunction{},
	GetVideoEncoderConfigurations:       &media.GetVideoEncoderConfigurationsFunction{},
	SetVideoEncoderConfiguration:        &media.SetVideoEncoderConfigurationFunction{},
	GetVideoEncoderConfigurationOptions: &media.GetVideoEncoderConfigurationOptionsFunction{},

	AddPTZConfiguration:    &media.AddPTZConfigurationFunction{},
	RemovePTZConfiguration: &media.RemovePTZConfigurationFunction{},
}
View Source
var PTZFunctionMap = map[string]Function{

	GetNodes: &ptz.GetNodesFunction{},
	GetNode:  &ptz.GetNodeFunction{},

	GetConfigurations:       &ptz.GetConfigurationsFunction{},
	GetConfiguration:        &ptz.GetConfigurationFunction{},
	GetConfigurationOptions: &ptz.GetConfigurationOptionsFunction{},
	SetConfiguration:        &ptz.SetConfigurationFunction{},

	AbsoluteMove:   &ptz.AbsoluteMoveFunction{},
	RelativeMove:   &ptz.RelativeMoveFunction{},
	ContinuousMove: &ptz.ContinuousMoveFunction{},
	Stop:           &ptz.StopFunction{},
	GetStatus:      &ptz.GetStatusFunction{},

	SetPreset:    &ptz.SetPresetFunction{},
	GetPresets:   &ptz.GetPresetsFunction{},
	GotoPreset:   &ptz.GotoPresetFunction{},
	RemovePreset: &ptz.RemovePresetFunction{},

	GotoHomePosition: &ptz.GotoHomePositionFunction{},
	SetHomePosition:  &ptz.SetHomePositionFunction{},

	SendAuxiliaryCommand: &ptz.SendAuxiliaryCommandFunction{},
}
View Source
var Xlmns = map[string]string{
	"onvif":   "http://www.onvif.org/ver10/schema",
	"tds":     "http://www.onvif.org/ver10/device/wsdl",
	"trt":     "http://www.onvif.org/ver10/media/wsdl",
	"tr2":     "http://www.onvif.org/ver20/media/wsdl",
	"tev":     "http://www.onvif.org/ver10/events/wsdl",
	"tptz":    "http://www.onvif.org/ver20/ptz/wsdl",
	"timg":    "http://www.onvif.org/ver20/imaging/wsdl",
	"tan":     "http://www.onvif.org/ver20/analytics/wsdl",
	"xmime":   "http://www.w3.org/2005/05/xmlmime",
	"wsnt":    "http://docs.oasis-open.org/wsn/b-2",
	"xop":     "http://www.w3.org/2004/08/xop/include",
	"wsa":     "http://www.w3.org/2005/08/addressing",
	"wstop":   "http://docs.oasis-open.org/wsn/t-1",
	"wsntw":   "http://docs.oasis-open.org/wsn/bw-2",
	"wsrf-rw": "http://docs.oasis-open.org/wsrf/rw-2",
	"wsaw":    "http://www.w3.org/2006/05/addressing/wsdl",
}

Xlmns XML Scheam

Functions

This section is empty.

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device for a new device of onvif and DeviceInfo struct represents an abstract ONVIF device. It contains methods, which helps to communicate with ONVIF device

func NewDevice

func NewDevice(params DeviceParams) (*Device, error)

NewDevice function construct a ONVIF Device entity

func (*Device) CallMethod

func (dev *Device) CallMethod(method interface{}) (*http.Response, error)

CallMethod functions call an method, defined <method> struct. You should use Authenticate method to call authorized requests.

func (*Device) CallOnvifFunction

func (dev *Device) CallOnvifFunction(serviceName, functionName string, data []byte) (interface{}, error)

func (*Device) GetDeviceInfo

func (dev *Device) GetDeviceInfo() DeviceInfo

GetServices return available endpoints

func (*Device) GetDeviceParams

func (dev *Device) GetDeviceParams() DeviceParams

func (*Device) GetEndpoint

func (dev *Device) GetEndpoint(name string) string

GetEndpoint returns specific ONVIF service endpoint address

func (*Device) GetEndpointByRequestStruct

func (dev *Device) GetEndpointByRequestStruct(requestStruct interface{}) (string, error)

func (*Device) GetServices

func (dev *Device) GetServices() map[string]string

GetServices return available endpoints

func (*Device) SendSoap

func (dev *Device) SendSoap(endpoint string, xmlRequestBody string) (resp *http.Response, err error)

type DeviceInfo

type DeviceInfo struct {
	Manufacturer    string
	Model           string
	FirmwareVersion string
	SerialNumber    string
	HardwareId      string
}

DeviceInfo struct contains general information about ONVIF device

type DeviceParams

type DeviceParams struct {
	Xaddr              string
	EndpointRefAddress string
	Username           string
	Password           string
	HttpClient         *http.Client
	AuthMode           string
}

type DeviceType

type DeviceType int

DeviceType alias for int

const (
	NVD DeviceType = iota
	NVS
	NVA
	NVT

	ContentType = "Content-Type"
)

Onvif Device Tyoe

func (DeviceType) String

func (devType DeviceType) String() string

type DigestClient

type DigestClient struct {
	// contains filtered or unexported fields
}

DigestClient represents an HTTP client used for making requests authenticated with http digest authentication.

func NewDigestClient

func NewDigestClient(stdClient *http.Client, username string, password string) *DigestClient

NewDigestClient returns a DigestClient that wraps a given standard library http Client with the given username and password

func (*DigestClient) Do

func (dc *DigestClient) Do(endpoint string, soap string) (*http.Response, error)

type Function

type Function interface {
	Request() interface{}
	Response() interface{}
}

func FunctionByServiceAndFunctionName

func FunctionByServiceAndFunctionName(serviceName, functionName string) (Function, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL