fleet

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package fleet provides a low-level implementation of the NAOS fleet management protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseTopics added in v0.14.0

func BaseTopics(devices []*Device) []string

BaseTopics returns a list of base topics from the provided devices.

func Debug

func Debug(url string, baseTopics []string, delete bool, jobs int) (map[string][]byte, error)

Debug will request coredump debug information from the specified devices.

func Discover

func Discover(url string, baseTopics []string, jobs int) (map[string]DiscoverResult, error)

Discover will connect to the specified MQTT broker and discover all available parameters and metrics for the specified base topics.

func GetParams

func GetParams(url, param string, baseTopics []string, jobs int) (map[string]string, error)

GetParams will receive the provided parameter for all specified base topics.

func Monitor

func Monitor(url string, baseTopics []string, stop chan struct{}, cb func(*Heartbeat)) error

Monitor will connect to the specified MQTT broker and periodically collect heartbeat information from all specified base topics until the provided stop channel has been closed. The collected heartbeats are provided via the callback.

func Record

func Record(url string, baseTopics []string, stop chan struct{}, cb func(*LogMessage)) error

Record will enable log recording mode on all devices and yield the received log messages until the provided channel has been closed.

func SetParams

func SetParams(url, param, value string, baseTopics []string, jobs int) (map[string]string, error)

SetParams will set the provided parameter on all specified base topics.

func UnsetParams

func UnsetParams(url, param string, baseTopics []string, jobs int) error

UnsetParams will unset the provided parameter on all specified base topics.

Types

type Announcement

type Announcement struct {
	BaseTopic  string
	DeviceName string
	AppName    string
	AppVersion string
}

An Announcement is returned by Collect.

func Collect

func Collect(url string, duration time.Duration) ([]*Announcement, error)

Collect will collect Announcements from devices by connecting to the provided MQTT broker and sending the 'collect' command.

Note: Not correctly formatted announcements are ignored.

type Device added in v0.14.0

type Device struct {
	BaseTopic  string            `json:"base_topic"`
	DeviceName string            `json:"device_name"`
	AppName    string            `json:"app_name"`
	AppVersion string            `json:"app_version"`
	Parameters map[string]string `json:"parameters,omitempty"`
	Metrics    []string          `json:"metrics,omitempty"`
}

A Device represents a single device in a fleet.

type DiscoverResult added in v0.14.0

type DiscoverResult struct {
	Params  map[string]string
	Metrics []string
}

DiscoverResult represents the result of a discovery operation.

type Fleet added in v0.14.0

type Fleet struct {
	Broker  string             `json:"broker,omitempty"`
	Devices map[string]*Device `json:"devices,omitempty"`
}

A Fleet represents a fleet of devices.

func NewFleet added in v0.14.0

func NewFleet() *Fleet

NewFleet creates a new fleet.

func ReadFleet added in v0.14.0

func ReadFleet(path string) (*Fleet, error)

ReadFleet will attempt to read the fleet at the specified path.

func (*Fleet) Collect added in v0.14.0

func (f *Fleet) Collect(duration time.Duration) ([]*Device, error)

Collect will collect and update the flet with found devices for the given duration. It will return a list of devices that have been added to the fleet.

func (*Fleet) Debug added in v0.14.0

func (f *Fleet) Debug(pattern string, delete bool, jobs int) (map[*Device][]byte, error)

Debug will load the latest coredump from all matching devices. If delete is true, the coredumps are deleted from the devices after retrieval. A table of devices and their corresponding coredumps is returned.

func (*Fleet) Discover added in v0.14.0

func (f *Fleet) Discover(pattern string, jobs int) ([]*Device, error)

Discover will request all parameters and metrics from all matching devices. The fleet is updated with the reported parameters and metrics, and a list of queried devices is returned.

func (*Fleet) FilterDevices added in v0.14.0

func (f *Fleet) FilterDevices(pattern string) []*Device

FilterDevices will return a list of devices that have a name matching the supplied glob pattern.

func (*Fleet) FindDevice added in v0.14.0

func (f *Fleet) FindDevice(baseTopic string) *Device

FindDevice returns the first device that has the matching base topic.

func (*Fleet) GetParams added in v0.14.0

func (f *Fleet) GetParams(pattern, param string, jobs int) ([]*Device, error)

GetParams will request specified parameter from all matching devices. The fleet is updated with the reported value and a list of queried devices is returned.

func (*Fleet) Monitor added in v0.14.0

func (f *Fleet) Monitor(pattern string, quit chan struct{}, callback func(*Device, *Heartbeat)) error

Monitor will monitor the matching devices and update the fleet accordingly. The specified callback is called for every heartbeat with the updated device and the received heartbeat.

func (*Fleet) Ping added in v0.14.0

func (f *Fleet) Ping(pattern string, jobs int) error

Ping will send a ping message to all matching devices.

func (*Fleet) Record added in v0.14.0

func (f *Fleet) Record(pattern string, quit chan struct{}, callback func(time.Time, *Device, string)) error

Record will enable log recording on all matching devices and yield the received log messages until the provided channel has been closed.

func (*Fleet) Save added in v0.14.0

func (f *Fleet) Save(path string) error

Save will write the fleet to the specified path.

func (*Fleet) SetParams added in v0.14.0

func (f *Fleet) SetParams(pattern, param, value string, jobs int) ([]*Device, error)

SetParams will set the specified parameter on all matching devices. The fleet is updated with the saved value and a list of updated devices is returned.

func (*Fleet) UnsetParams added in v0.14.0

func (f *Fleet) UnsetParams(pattern, param string, jobs int) ([]*Device, error)

UnsetParams will unset the specified parameter on all matching devices. The fleet is updated with the unset value and a list of updated devices is returned.

func (*Fleet) Update added in v0.14.0

func (f *Fleet) Update(version, pattern string, firmware []byte, jobs int, callback func(*Device, UpdateStatus)) error

Update will update all matching devices with the specified image. The specified callback is called for every change in state or progress.

type Heartbeat

type Heartbeat struct {
	ReceivedAt     time.Time
	BaseTopic      string
	DeviceName     string
	AppName        string
	AppVersion     string
	AppPartition   string
	UpTime         time.Duration
	BatteryLevel   float64 // -1, 0 - 1
	FreeMemory     []float64
	CPUUsage       []float64 // 0 - 1
	SignalStrength int64     // -50 - -100
}

A Heartbeat gathered from a device.

type LogMessage

type LogMessage struct {
	Time      time.Time
	BaseTopic string
	Content   string
}

A LogMessage receive from a device.

type UpdateStatus

type UpdateStatus struct {
	Progress float64
	Error    error
}

UpdateStatus represents the status of a firmware update.

func Update

func Update(url string, baseTopics []string, firmware []byte, jobs int, callback func(string, UpdateStatus)) ([]UpdateStatus, error)

Update will perform a firmware update on the provided devices. If a callback is provided it will be called with the current status of the update.

Jump to

Keyboard shortcuts

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