traccargo

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: MIT Imports: 14 Imported by: 0

README

traccargo

Traccargo is the Golang library for fetching devices information and device position updates from Traccar opensource GPS tracking system

It supports only requests for devices and device positions, also it supports live updates for devices, poistions and events from traccar websocket endpoint.

Usage example

var traccarURL = ""
var traccarToken = ""
var testDeviceID int64 = 0

func main() {
	trc, err := traccargo.NewTraccar(traccarURL, traccarToken)
	if err != nil {
		panic(err)
	}
  
  //write debug messages to the console
	trc.LogCommunicationWriter = os.Stdout
	trc.LogWriter = os.Stdout

  //get device position
	position, err := trc.Position(testDeviceID)

	if err != nil {
		panic(err)
	}

	fmt.Printf("Device %d: time %v, Position [%.6f %.6f]\n", position.DeviceID, position.FixTime, position.Latitude, position.Longitude)

  //subscribe to live traccar updates
	err = trc.SubscribeUpdates(func(m *traccargo.WsMessage) {
		fmt.Printf("new message received\n")
	})

	if err != nil {
		panic(err)
	}

  //just a rest
	time.Sleep(time.Second * 100)

	trc.Close()
}

Documentation

Index

Constants

View Source
const (
	ENC_URI  encoding = 1
	ENC_JSON encoding = 2
)

Variables

View Source
var (
	TRACCAR_ERROR_UNREACHABLE = errors.New("server is unreachable")
	TRACCAR_ERROR_AUTH        = errors.New("server auth is failed")
	TRACCAR_ERROR_FAILED      = errors.New("operation can't be performed")
	TRACCAR_ERROR_UNKNOWN     = errors.New("unknown error")
	TRACCAR_ERROR_NOTFOUND    = errors.New("object not found")
)

Functions

This section is empty.

Types

type Traccargo

type Traccargo struct {
	LogWriter              io.Writer //for debug purpose. All significant operation and error events is written to this io.Writer if defined
	LogCommunicationWriter io.Writer //for debug purpose. All JSON responses will be written to this io.Writer if defined
	// contains filtered or unexported fields
}

func NewTraccar

func NewTraccar(apiUrl string, authToken string) (tr *Traccargo, err error)

creates a traccar instance

func (*Traccargo) Close

func (t *Traccargo) Close()

func (*Traccargo) Position

func (t *Traccargo) Position(deviceId int64) (position models.Position, err error)

returns the device position from traccar server

func (*Traccargo) Positions

func (t *Traccargo) Positions() (positions []*models.Position, err error)

returns all devices positions from traccar server

func (*Traccargo) Session

func (t *Traccargo) Session() (user models.User, err error)

authorizes to the traccar server and returns User object

func (*Traccargo) SubscribeUpdates

func (t *Traccargo) SubscribeUpdates(handler func(m *WsMessage)) (err error)

subscribes to live traccar updates WebSocket connection to the traccar api endpoint will be established and keeps alive the callback function calls on every update

func (*Traccargo) UnsubscribeUpdates

func (t *Traccargo) UnsubscribeUpdates()

finish websocket connection and live updates subscription

type WsMessage

type WsMessage struct {
	Devices   *[]models.Device
	Positions *[]models.Position
	Event     *[]models.Event
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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