device

package
v0.90.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultInitialConnectionAttempts = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregateMessage

type AggregateMessage struct {
	Interface interfaces.AstarteInterface
	Path      string
	Values    map[string]interface{}
	Timestamp time.Time
}

AggregateMessage represents a message for an Interface of aggregation type object

type Device

type Device struct {

	// AutoReconnect sets whether the device should reconnect automatically if it loses the connection
	// after establishing it. Defaults to false.
	AutoReconnect bool
	// ConnectRetry sets whether the device should retry to connect if the first connection
	// fails. Defaults to false.
	ConnectRetry bool
	// MaxRetries sets the number of attempts for the device to establish the first connection.
	// If ConnectRetry is false, MaxRetries will be ignored. Defaults to 10.
	MaxRetries int
	// RootCAs, when not nil, sets a custom set of Root CAs to trust against the broker
	RootCAs                     *x509.CertPool
	OnIndividualMessageReceived func(*Device, IndividualMessage)
	OnAggregateMessageReceived  func(*Device, AggregateMessage)
	OnErrors                    func(*Device, error)
	OnConnectionStateChanged    func(*Device, bool)
	// contains filtered or unexported fields
}

Device is the base struct for Astarte Devices

func NewDevice

func NewDevice(deviceID, realm, credentialsSecret string, pairingBaseURL string) (*Device, error)

NewDevice creates a new Device

func NewDeviceWithPersistency

func NewDeviceWithPersistency(deviceID, realm, credentialsSecret string, pairingBaseURL string, persistencyDir string) (*Device, error)

NewDeviceWithPersistency creates a new Device with a known persistency directory

func (*Device) AddInterface

func (d *Device) AddInterface(astarteInterface interfaces.AstarteInterface) error

AddInterface adds an interface to the device. The interface must be loaded with ParseInterface from the astarte-go/interfaces package. AddInterface returns `nil` if the interface was loaded successfully, or a corresponding error otherwise (e.g. interface validation failed).

func (*Device) ClearCrypto

func (d *Device) ClearCrypto() error

ClearCrypto clears all the temporary crypto files of the Device. Usually, you shouldn't need to call this function.

func (*Device) Connect

func (d *Device) Connect(result chan<- error)

Connect connects the device through a goroutine

func (*Device) Disconnect

func (d *Device) Disconnect(result chan<- error)

Disconnect disconnects the device

func (*Device) IsConnected

func (d *Device) IsConnected() bool

IsConnected returns whether the device is connected or not

func (*Device) RemoveInterface

func (d *Device) RemoveInterface(astarteInterface interfaces.AstarteInterface)

RemoveInterface removes an interface from the device

func (*Device) SendAggregateMessage

func (d *Device) SendAggregateMessage(interfaceName, interfacePath string, values map[string]interface{}) error

SendAggregateMessage sends a new message towards an Object Aggregated interface. values must be a map containing the last tip of the endpoint, with no slash, as the key, and the corresponding value as value. interfacePath should match the path of the base endpoint, without the last tip. Example: if dealing with an aggregate interface with endpoints [/my/aggregate/firstValue, /my/aggregate/secondValue], interfacePath would be "/my/aggregate", and values would be map["firstValue": <value>, "secondValue": <value>]

func (*Device) SendAggregateMessageWithTimestamp

func (d *Device) SendAggregateMessageWithTimestamp(interfaceName, interfacePath string, values map[string]interface{}, timestamp time.Time) error

SendAggregateMessageWithTimestamp sends a new message towards an Object Aggregated interface, with explicit timestamp. values must be a map containing the last tip of the endpoint, with no slash, as the key, and the corresponding value as value. interfacePath should match the path of the base endpoint, without the last tip. Example: if dealing with an aggregate interface with endpoints [/my/aggregate/firstValue, /my/aggregate/secondValue], interfacePath would be "/my/aggregate", and values would be map["firstValue": <value>, "secondValue": <value>]

func (*Device) SendIndividualMessage

func (d *Device) SendIndividualMessage(interfaceName, path string, value interface{}) error

SendIndividualMessage sends a new message towards an individual aggregation interface

func (*Device) SendIndividualMessageWithTimestamp

func (d *Device) SendIndividualMessageWithTimestamp(interfaceName, interfacePath string, value interface{}, timestamp time.Time) error

SendIndividualMessageWithTimestamp sends a new message towards an individual aggregation interface, with explicit timestamp

type IndividualMessage

type IndividualMessage struct {
	Interface interfaces.AstarteInterface
	Path      string
	Value     interface{}
	Timestamp time.Time
}

IndividualMessage represents a message for an Interface of aggregation type individual

Jump to

Keyboard shortcuts

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