onvif

package module
v0.0.0-...-25bac83 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 13 Imported by: 0

README

onvif protocol

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.

Installation

To install the library, use go get:

go get github.com/190948804/onvif

Supported services

The following services are implemented:

  • Device
  • Media
  • PTZ
  • Imaging
  • Event
  • Discovery
  • Auth(More Options)
  • Soap
  • Record

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)

Great Thanks

Enhanced and Improved from: goonvif

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

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",
	"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",
	"trc":     "http://www.onvif.org/ver10/recording/wsdl",
	"tse":     "http://www.onvif.org/ver10/search/wsdl",
	"trp":     "http://www.onvif.org/ver10/replay/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 GetAvailableDevicesAtSpecificEthernetInterface

func GetAvailableDevicesAtSpecificEthernetInterface(interfaceName string) ([]Device, error)

GetAvailableDevicesAtSpecificEthernetInterface ...

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) GetDeviceInfo

func (dev *Device) GetDeviceInfo() DeviceInfo

GetServices return available endpoints

func (*Device) GetEndpoint

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

GetEndpoint returns specific ONVIF service endpoint address

func (*Device) GetServices

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

GetServices return available endpoints

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
	Username   string
	Password   string
	HttpClient *http.Client
}

type DeviceType

type DeviceType int

DeviceType alias for int

const (
	NVD DeviceType = iota
	NVS
	NVA
	NVT
)

Onvif Device Tyoe

func (DeviceType) String

func (devType DeviceType) String() string

Jump to

Keyboard shortcuts

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