goonvif

package module
Version: v0.0.0-...-fe8f6f0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 13 Imported by: 0

README

Goonvif

Easy management of IP devices, including cameras. Goonvif is an ONVIF implementation for managing IP devices. The purpose of this library is to manage IP cameras and other devices that support the ONVIF standard easily and conveniently.

Installation

To install the library, use the go get utility:

go get github.com/talkincode/goonvif

Supported services

The following services are fully implemented:

  • Device
  • Media
  • PTZ
  • Imaging

Usage

General concept
  1. Connection to the device
  2. Authentication (if required)
  3. Definition of data types
  4. Execution of the required method
Connect to device

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

dev, err := goonvif.NewDevice("192.168.13.42:1234")

*ONVIF port may be different depending on the device and to find out which port to use, you can go to the web interface of the device. **Usually it's port 80.

Authentication

If any function of one of the ONVIF services requires authentication, the Authenticate method must be used.

device := onvif.NewDevice("192.168.13.42:1234")
device.Authenticate("username", "password")
Data Type Definition

Each ONVIF service in this library has its own package in which all data types of this service are defined, and the name of the package is identical to the service name and starts with a capital letter. Goonvif has defined structures for each function of each ONVIF service supported by this library. Let's 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 a Category field and why is the value of this field All?

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

Device GetCapabilities

An example of the GetServiceCapabilities function data type definition PTZ:

ptzCapabilities := PTZ.GetServiceCapabilities{}

You can see in the figure below that GetServiceCapabilities takes no arguments.

PTZ GetServiceCapabilities

*General data types are in the xsd/onvif package. Data types (structures) that can be common to all services are defined in the onvif package.

An example of the data type of the CreateUsers function of the Device service:

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

You can see from the figure below that in this example the CreateUsers structure field should be User, the data type of which is a User structure containing Username, Password, UserLevel fields and an optional Extension. The User structure is located in the onvif package.

Device CreateUsers

Executing the required method

To execute any function of one of the ONVIF services whose structure has been defined, the ``CallMethod'' of the device object must be used.

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

Documentation

Overview

package goonvif 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/OnvifDevice/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",
}

Functions

This section is empty.

Types

type DeviceType

type DeviceType int
const (
	NVD DeviceType = iota
	NVS
	NVA
	NVT
)

func (DeviceType) String

func (devType DeviceType) String() string

type OnvifDevice

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

deviceInfo struct represents an abstract ONVIF OnvifDevice. It contains methods, which helps to communicate with ONVIF OnvifDevice

func GetAvailableDevicesAtSpecificEthernetInterface

func GetAvailableDevicesAtSpecificEthernetInterface(interfaceName string) []OnvifDevice

func NewDevice

func NewDevice(xaddr string) (*OnvifDevice, error)

NewDevice function construct a ONVIF Device entity

func (*OnvifDevice) Authenticate

func (dev *OnvifDevice) Authenticate(username, password string)

Authenticate function authenticate client in the ONVIF Device. Function takes <username> and <password> params. You should use this function to allow authorized requests to the ONVIF Device To change auth data call this function again.

func (OnvifDevice) CallMethod

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

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

func (*OnvifDevice) GetEndpoint

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

GetEndpoint returns specific ONVIF service endpoint address

func (*OnvifDevice) GetServices

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

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL