Documentation ¶
Index ¶
- Constants
- type AggregateMessage
- type Device
- func (d *Device) AddInterface(astarteInterface interfaces.AstarteInterface) error
- func (d *Device) ClearCrypto() error
- func (d *Device) Connect(result chan<- error)
- func (d *Device) Disconnect(result chan<- error)
- func (d *Device) IsConnected() bool
- func (d *Device) RemoveInterface(astarteInterface interfaces.AstarteInterface)
- func (d *Device) SendAggregateMessage(interfaceName, interfacePath string, values map[string]interface{}) error
- func (d *Device) SendAggregateMessageWithTimestamp(interfaceName, interfacePath string, values map[string]interface{}, ...) error
- func (d *Device) SendIndividualMessage(interfaceName, path string, value interface{}) error
- func (d *Device) SendIndividualMessageWithTimestamp(interfaceName, interfacePath string, value interface{}, timestamp time.Time) error
- type IndividualMessage
Constants ¶
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 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 ¶
ClearCrypto clears all the temporary crypto files of the Device. Usually, you shouldn't need to call this function.
func (*Device) Disconnect ¶
Disconnect disconnects the device
func (*Device) IsConnected ¶
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 ¶
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