fleet

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	SourceMQTT = "mqtt"
	SourceHub  = "hub"
)

The available device sources.

Variables

This section is empty.

Functions

func Debug

func Debug(backend Backend, devices []*Device, delete bool, jobs int) ([][]byte, error)

Debug will request coredump debug information from the specified devices. The returned list is aligned with the provided list.

func GetParams

func GetParams(backend Backend, param string, devices []*Device, jobs int) ([]string, error)

GetParams will receive the provided parameter for all specified devices. The returned list is aligned with the provided list.

func Monitor

func Monitor(backend Backend, devices []*Device, stop chan struct{}, cb func(*Heartbeat), onError func(*Device, error)) error

Monitor will periodically collect heartbeat information from all specified devices until the provided stop channel has been closed. The collected heartbeats are provided via the callback. Devices that fail are reported via the error callback as soon as they fail, potentially from multiple goroutines.

func Record

func Record(backend Backend, devices []*Device, stop chan struct{}, cb func(*LogMessage), onError func(*Device, error)) error

Record will enable log recording mode on all devices and yield the received log messages until the provided channel has been closed. Devices that fail are reported via the error callback as soon as they fail, potentially from multiple goroutines.

func SetParams

func SetParams(backend Backend, param, value string, devices []*Device, jobs int) ([]string, error)

SetParams will set the provided parameter on all specified devices. The returned list is aligned with the provided list.

func UnsetParams

func UnsetParams(backend Backend, param string, devices []*Device, jobs int) error

UnsetParams will unset the provided parameter on all specified devices.

Types

type Announcement

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

An Announcement is returned by a backend when collecting devices.

Note: Not correctly formatted announcements are ignored.

type Backend added in v0.17.0

type Backend interface {
	// Collect will collect announcements from all available devices for the
	// specified duration.
	Collect(duration time.Duration) ([]*Announcement, error)

	// Resolve will return the addressable devices for the provided fleet
	// devices. The returned list is aligned with the provided list. Devices
	// that cannot be addressed yield a device that fails when opened.
	Resolve(devices []*Device) ([]msg.Device, error)

	// Close will close the backend and all underlying connections.
	Close()
}

A Backend provides access to the devices of a fleet.

func NewBackend added in v0.17.0

func NewBackend(broker, hub, hubToken string) (Backend, error)

NewBackend will create a backend for the provided broker and hub. If both are specified, devices are resolved using their configured source.

func NewHubBackend added in v0.17.0

func NewHubBackend(base, token string) (Backend, error)

NewHubBackend will create a backend that connects to the specified NAOS hub.

func NewMQTTBackend added in v0.17.0

func NewMQTTBackend(url string) (Backend, error)

NewMQTTBackend will create a backend that connects to the specified MQTT broker.

type Device added in v0.14.0

type Device struct {
	Source     string            `json:"source,omitempty"`
	BaseTopic  string            `json:"base_topic"`
	DeviceID   string            `json:"device_id,omitempty"`
	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.

func (*Device) Address added in v0.17.0

func (d *Device) Address() string

Address returns the address used to reach the device.

type DiscoverResult added in v0.14.0

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

DiscoverResult represents the result of a discovery operation.

func Discover

func Discover(backend Backend, devices []*Device, jobs int) ([]DiscoverResult, error)

Discover will discover all available parameters and metrics for the specified devices. The returned list is aligned with the provided list.

type Fleet added in v0.14.0

type Fleet struct {
	Broker   string             `json:"broker,omitempty"`
	HubURL   string             `json:"hub_url,omitempty"`
	HubToken string             `json:"hub_token,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) Backend added in v0.17.0

func (f *Fleet) Backend() (Backend, error)

Backend will open a backend for the fleet. The caller is responsible for closing the returned backend. The hub token is read from the NAOS_HUB_TOKEN environment variable if set, otherwise from the fleet.

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) 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), onError func(*Device, error)) 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. Devices that fail are reported via the error callback.

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), onError func(*Device, error)) error

Record will enable log recording on all matching devices and yield the received log messages until the provided channel has been closed. Devices that fail are reported via the error callback.

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
	Device         *Device
	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
	Device  *Device
	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(backend Backend, devices []*Device, firmware []byte, jobs int, callback func(*Device, 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. The returned list is aligned with the provided list.

Jump to

Keyboard shortcuts

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