onvifcam

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: BSD-2-Clause Imports: 15 Imported by: 1

README

onvifcam

Client for ONVIF compatible IP cameras.

GoDoc Go Report Card

Contributions are welcome.

Usage

This package provides simplified client to interact with an ONVIF compatible IP camera.

Once the device is created with New, it must be initialized with Init. Then, GetSnapshot and GetStreamURI can be called and used straight away.

The Subscribe method creates an event subscription to the device for motion detection. The camera sends events via an HTTP POST / request. The package provides the function UnmarshalEventMessage to obtain the event's data. This function can be used by the HTTP server's handler function.

Tests

The tests require an ONVIF compatible IP camera to run.

Documentation

Index

Constants

View Source
const (
	TopicMotionAlarm = "tns1:VideoSource/MotionAlarm"

	V18 = "18" // ONVIF v18
	V23 = "23" // ONVIF v23
)

Variables

View Source
var (
	ErrAlarm error = errors.New("error unmarshaling alarm")
	ErrBeat  error = errors.New("error unmarshaling beat")
)
View Source
var (
	ErrFailedNew             = errors.New("failed to set new device")
	ErrNoURIFrame            = errors.New("failed to get URI for snapshot")
	ErrNoURIStream           = errors.New("failed to get URI for stream")
	ErrSubscribe             = errors.New("failed to subscribe")
	ErrUnmarshalEventMessage = errors.New("failed to unmarshal event message")
	ErrVersion               = errors.New("method does not exist in ONVIF version")
)
View Source
var (
	EventChanged     = "Changed"
	EventInitialized = "Initialized"
)

Functions

func IsAlarm added in v0.3.0

func IsAlarm(data string) bool

func IsBeat added in v0.3.0

func IsBeat(data string) bool

func ParseDatetime added in v0.3.0

func ParseDatetime(d string) (time.Time, error)

func UnmarshalEventMessage

func UnmarshalEventMessage(data []byte, r *EventMessage) error

UnmarshalEventMessage is normally used by the handler of the http server listening for events.

Types

type Alarm added in v0.3.0

type Alarm struct {
	AlarmStatus AlarmStatusInfo `xml:"alarmStatusInfo"`
	Datatime    string          `xml:"dataTime"`
	DeviceInfo  DeviceInfo      `xml:"deviceInfo"`
}

func AlarmUnmarshal added in v0.3.0

func AlarmUnmarshal(data string) (*Alarm, error)

type AlarmStatusInfo added in v0.3.0

type AlarmStatusInfo struct {
	MotionAlarm     bool `xml:"motionAlarm"`
	PerimeterAlarm  bool `xml:"perimeterAlarm"`
	TripwireAlarm   bool `xml:"tripwireAlarm"`
	OscAlarm        bool `xml:"oscAlarm"`
	SceneChange     bool `xml:"sceneChange"`
	ClarityAbnormal bool `xml:"clarityAbnormal"`
	ColorAbnormal   bool `xml:"colorAbnormal"`
}

type Beat added in v0.3.0

type Beat struct {
	Datatime   string     `xml:"dataTime"`
	DeviceInfo DeviceInfo `xml:"deviceInfo"`
}

func BeatUnmarshal added in v0.3.0

func BeatUnmarshal(data string) (*Beat, error)

type BodyXML

type BodyXML struct {
	Notify NotifyXML
}

type Config added in v0.2.2

type Config struct {
	Addr     string
	Username string
	Password string
	Profile  string
	Version  string
}

type DeviceInfo added in v0.3.0

type DeviceInfo struct {
	Name       string `xml:"deviceName"`
	No         string `xml:"deviceNo."`
	Sn         string `xml:"sn"`
	IPAddress  string `xml:"ipAddress"`
	MacAddress string `xml:"macAddress"`
}

type EventMessage

type EventMessage struct {
	Header HeaderXML
	Body   BodyXML
}

type HeaderXML

type HeaderXML struct {
	To     string
	Action string
}

type NotifyXML

type NotifyXML struct {
	NotificationMessage event.NotificationMessage
}

type Onvifcam

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

func New

func New(cfg *Config, httpClient *http.Client) *Onvifcam

New returns a new bare ONVIF device using basic authentication. httpClient is used also by the ONVIF device implementation. It is set to a default client if not provided.

func (*Onvifcam) GetSnapshot

func (c *Onvifcam) GetSnapshot(ctx context.Context) ([]byte, error)

GetSnapshot returns an image frame (jpeg) from the camera.

func (*Onvifcam) GetStreamURI

func (c *Onvifcam) GetStreamURI(ctx context.Context) (string, error)

GetStreamURI returns an rstp URI. For a rtsp client see https://pkg.go.dev/github.com/aler9/gortsplib#section-readme.

func (*Onvifcam) Init added in v0.2.0

func (c *Onvifcam) Init(_ context.Context) error

Init connects to the device using basic authentication and sets it up. A context is currently unused (can be set to nil) but passed for future improvement of go-onvif module.

func (*Onvifcam) Subscribe

func (c *Onvifcam) Subscribe(ctx context.Context, addr, topic, dateTimeOrDuration string) (string, error)

Subscribe returns a subscription reference address. Events are sent via http POST / request to the given http server listening in addr.

Jump to

Keyboard shortcuts

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