Version: v0.3.0 Latest Latest

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

Go to latest
Published: Apr 27, 2021 License: Apache-2.0 Imports: 13 Imported by: 0





View Source
const (
	LOGIN                 = 0x0110
	LOGIN_ACCEPT          = 0x0111
	ALIVE_REQUEST         = 0x0112
	ALIVE_RESPONSE        = 0x0113
	START_PREVIEW         = 0x01FF
	TAKE_PICTURE          = 0xA038
	PICTURE_SAVED         = 0xA039
View Source
const (
	// RemoveHandler instructs the network code to remove this handler after execution
	RemoveHandler = true
	// KeepHandler instructs the network code to keep this handler after execution
	KeepHandler = false


This section is empty.


func AutodiscoverCamera

func AutodiscoverCamera(verbose bool) (net.IP, error)

AutodiscoverCamera will try to find a camera using UDP Broadcasts

func CreateCommandPacket

func CreateCommandPacket(command uint32) []byte

CreateCommandPacket prepares a command packet to be sent to the camera

func CreateLoginPacket

func CreateLoginPacket(username, password string) []byte

CreateLoginPacket creates a Login packet to be sent to the camera

func CreatePacket

func CreatePacket(header Header, payload []byte) []byte

CreatePacket creates a packet ready to be sent to the camera

// Prepare a Header
header := CreateCommandHeader(TAKE_PICTURE)
payload := []byte{}

// Create the packet
packet := CreatePacket(header, payload)

fmt.Printf("Packet Data: %X\n", packet)

Packet Data: ABCD00000000A038


type Camera

type Camera struct {
	// contains filtered or unexported fields

Camera contains all information and features on a single IP Camera

func CreateCamera

func CreateCamera(ipAddress net.IP, port int, username, password string) (*Camera, error)

CreateCamera creates a new Camera instance

cameraIP := net.ParseIP("")

// Create a camera
camera := CreateCamera(cameraIP, 6666, "admin", "12345")
defer camera.Disconnect()

// Enable verbose output for debugging

// Connect to the camera and start responding to keep-alive messages

// Send a login packet to enable camera control
err := camera.Login()
if err != nil {
	fmt.Printf("Failed to Login: %s\n", err)

// Make the camera take a still image
err = camera.TakePicture()
if err != nil {
	fmt.Printf("Failed to take a picture: %s\n", err)

func (*Camera) Connect

func (c *Camera) Connect()

Connect to the camera and start responding to keepalive packets

func (*Camera) Disconnect

func (c *Camera) Disconnect()

Disconnect from the camera

func (*Camera) GetFileList

func (c *Camera) GetFileList() ([]StoredFile, error)

GetFileList retrieves a list of files stored on the cameras SD-Card

func (*Camera) GetFirmwareInfo

func (c *Camera) GetFirmwareInfo() (string, error)

GetFirmwareInfo will request firmware information from the camera

func (*Camera) Handle

func (c *Camera) Handle(messageType uint32, handleFunc MessageHandler)

Handle adds a new message handler to the list of message handlers for a given message type

func (*Camera) HandleFirst

func (c *Camera) HandleFirst(messageType uint32, handleFunc MessageHandler)

HandleFirst adds a new message handler to the start of the list of message handlers for a given message type

func (*Camera) IsConnected

func (c *Camera) IsConnected() bool

IsConnected returns true if the camera connection has not been disconnected

func (*Camera) Log

func (c *Camera) Log(format string, data ...interface{})

Log will write to stdout if this camera has been set to be verbose

func (*Camera) Login

func (c *Camera) Login() error

Login will try to login to the camera control service

func (*Camera) SendPacket

func (c *Camera) SendPacket(packet []byte) error

SendPacket sends a raw packet to the camera

func (*Camera) SetVerbose

func (c *Camera) SetVerbose(verbose bool)

SetVerbose changes the verbosity setting of this camera object

func (*Camera) StartPreviewStream

func (c *Camera) StartPreviewStream() error

StartPreviewStream starts streaming video to this host

func (*Camera) StartRecording

func (c *Camera) StartRecording() error

StartRecording starts recording video to SD-Card

func (*Camera) StopRecording

func (c *Camera) StopRecording() error

StopRecording stops recording video to SD-Card

func (*Camera) TakePicture

func (c *Camera) TakePicture() error

TakePicture instructs the camera to take a still image

type Header struct {
	Magic       uint16
	Length      uint16
	MessageType uint32

Header is an ipcamera protocol message header

func CreateCommandHeader

func CreateCommandHeader(command uint32) Header

CreateCommandHeader prepares a packet header for command packets

func (*Header) String

func (h *Header) String() string

type Message

type Message struct {
	Header  Header
	Payload []byte

Message represents a complete message from/to the camera

func (*Message) String

func (m *Message) String() string

type MessageHandler

type MessageHandler func(camera *Camera, message *Message) (bool, error)

MessageHandler is used to process incoming messages from the camera

type RTPRelay

type RTPRelay struct {
	// contains filtered or unexported fields

RTPRelay holds information on the relaying stream listener

func CreateRTPRelay

func CreateRTPRelay(ctx context.Context, targetAddress net.IP, targetPort int) *RTPRelay

CreateRTPRelay creates a UDP listener that handles live data from the camera and forwards it as an RTP stream

func (*RTPRelay) Stop

func (r *RTPRelay) Stop()

Stop stops listening for packets

type StoredFile

type StoredFile struct {
	Path string
	Size uint64

StoredFile is a file stored on the cameras sd-card

Jump to

Keyboard shortcuts

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