iotdevice

package
v0.6.3-0...-d8fb617 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("closed")

ErrClosed the client is already closed.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is iothub device client.

func New

func New(
	transport transport.Transport, creds transport.Credentials, opts ...ClientOption,
) (*Client, error)

New returns new iothub client.

func NewFromConnectionString

func NewFromConnectionString(
	transport transport.Transport, cs string, opts ...ClientOption,
) (*Client, error)

NewFromConnectionString creates a device client based on the given connection string.

func NewFromX509Cert

func NewFromX509Cert(
	transport transport.Transport,
	deviceID, hostName string, crt *tls.Certificate,
	opts ...ClientOption,
) (*Client, error)

func NewFromX509FromFile

func NewFromX509FromFile(
	transport transport.Transport,
	deviceID, hostname, certFile, keyFile string,
	opts ...ClientOption,
) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

Close closes transport connection.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect connects to the iothub all subsequent calls will block until this function finishes with no error so it's clien's responsibility to connect in the background by running it in a goroutine and control other method invocations or call in in a synchronous way.

func (*Client) DeviceID

func (c *Client) DeviceID() string

DeviceID returns iothub device id.

func (*Client) RegisterMethod

func (c *Client) RegisterMethod(ctx context.Context, name string, fn DirectMethodHandler) error

RegisterMethod registers the given direct method handler, returns an error when method is already registered. If f returns an error and empty body its error string used as value of the error attribute in the result json.

func (*Client) RetrieveTwinState

func (c *Client) RetrieveTwinState(ctx context.Context) (desired, reported TwinState, err error)

RetrieveTwinState returns desired and reported twin device states.

func (*Client) SendEvent

func (c *Client) SendEvent(ctx context.Context, payload []byte, opts ...SendOption) error

SendEvent sends a device-to-cloud message. Panics when event is nil.

func (*Client) SubscribeEvents

func (c *Client) SubscribeEvents(ctx context.Context) (*EventSub, error)

SubscribeEvents subscribes to cloud-to-device events and returns a subscription struct.

func (*Client) SubscribeTwinUpdates

func (c *Client) SubscribeTwinUpdates(ctx context.Context) (*TwinStateSub, error)

SubscribeTwinUpdates registers fn as a desired state changes handler.

func (*Client) UnregisterMethod

func (c *Client) UnregisterMethod(name string)

UnregisterMethod unregisters the named method.

func (*Client) UnsubscribeEvents

func (c *Client) UnsubscribeEvents(sub *EventSub)

UnsubscribeEvents makes the given subscription to stop receiving messages.

func (*Client) UnsubscribeTwinUpdates

func (c *Client) UnsubscribeTwinUpdates(sub *TwinStateSub)

UnsubscribeTwinUpdates unsubscribes the given handler from twin state updates.

func (*Client) UpdateTwinState

func (c *Client) UpdateTwinState(ctx context.Context, s TwinState) (int, error)

UpdateTwinState updates twin device's state and returns new version. To remove any attribute set its value to nil.

type ClientOption

type ClientOption func(c *Client)

ClientOption is a client configuration option.

func WithLogger

func WithLogger(l logger.Logger) ClientOption

WithLogger changes default logger, default it an stdout logger.

type DirectMethodHandler

type DirectMethodHandler func(p map[string]interface{}) (map[string]interface{}, error)

DirectMethodHandler handles direct method invocations.

type EventSub

type EventSub struct {
	// contains filtered or unexported fields
}

func (*EventSub) C

func (s *EventSub) C() <-chan *common.Message

func (*EventSub) Err

func (s *EventSub) Err() error

type ModuleClient

type ModuleClient struct {
	Client
}

ModuleClient is iothub device client adapted for use with a module connection

func NewModule

func NewModule(
	transport transport.Transport, creds transport.Credentials, opts ...ClientOption,
) (*ModuleClient, error)

NewModule returns a new ModuleClient struct

func NewModuleFromConnectionString

func NewModuleFromConnectionString(
	transport transport.Transport,
	cs, gatewayHostName, moduleGenerationID, workloadURI string,
	edge bool,
	opts ...ClientOption,
) (*ModuleClient, error)

NewModuleFromConnectionString returns a ModuleClient struct with credentials based off of a supplied connection string

func NewModuleFromEnvironment

func NewModuleFromEnvironment(
	transport transport.Transport,
	edge bool,
	opts ...ClientOption,
) (*ModuleClient, error)

func (*ModuleClient) Broker

func (c *ModuleClient) Broker() string

Broker returns broker property from client's credential property

func (*ModuleClient) Gateway

func (c *ModuleClient) Gateway() string

Gateway returns gateway hostname property from client's credential property

func (*ModuleClient) GenerationID

func (c *ModuleClient) GenerationID() string

GenerationID returns generation ID property from client's credential property

func (*ModuleClient) ModuleID

func (c *ModuleClient) ModuleID() string

ModuleID returns module ID property from client's credential property

type ModuleSharedAccessKeyCredentials

type ModuleSharedAccessKeyCredentials struct {
	SharedAccessKeyCredentials        // embedded SharedAccessKeyCredentials struct
	ModuleID                   string // moduleID
	Gateway                    string // name of host gateway
	GenerationID               string // module generation ID
	WorkloadURI                string // IoT Edge workload API URI
	EdgeGateway                bool   // connect via edgeHub
}

ModuleSharedAccessKeyCredentials is a SharedAccessKeyCredentials struct adapted for module connections

func ParseModuleConnectionString

func ParseModuleConnectionString(cs string) (*ModuleSharedAccessKeyCredentials, error)

ParseModuleConnectionString returns a ModuleSharedAccessKeyCredentials struct with some properties derrived from a supplied connection string

func ParseModuleEnvironmentVariables

func ParseModuleEnvironmentVariables() (*ModuleSharedAccessKeyCredentials, error)

func (*ModuleSharedAccessKeyCredentials) GetBroker

GetBroker returns gateway host name if UseEdgeGateway is true, else returns IoT Hub host name

func (*ModuleSharedAccessKeyCredentials) GetCertificate

func (c *ModuleSharedAccessKeyCredentials) GetCertificate() *tls.Certificate

GetCertificate returns nil. Only here to satisfy Credentials interface

func (*ModuleSharedAccessKeyCredentials) GetGateway

func (c *ModuleSharedAccessKeyCredentials) GetGateway() string

GetGateway returns Gateway Host Name

func (*ModuleSharedAccessKeyCredentials) GetGenerationID

func (c *ModuleSharedAccessKeyCredentials) GetGenerationID() string

GetGenerationID returns GenerationID

func (*ModuleSharedAccessKeyCredentials) GetModuleID

func (c *ModuleSharedAccessKeyCredentials) GetModuleID() string

GetModuleID returns ModuleID

func (*ModuleSharedAccessKeyCredentials) GetSAK

GetSAK returns SharedAccessKey

func (*ModuleSharedAccessKeyCredentials) GetWorkloadURI

func (c *ModuleSharedAccessKeyCredentials) GetWorkloadURI() string

GetWorkloadURI returns the URI of the IoT Edge workload API

func (*ModuleSharedAccessKeyCredentials) UseEdgeGateway

func (c *ModuleSharedAccessKeyCredentials) UseEdgeGateway() bool

UseEdgeGateway returns bool to connect via edgeHub or directly to IoT Hub

type SendOption

type SendOption func(msg *common.Message) error

SendOption is a send event options.

func WithSendCorrelationID

func WithSendCorrelationID(cid string) SendOption

WithSendCorrelationID sets message correlation id.

func WithSendMessageID

func WithSendMessageID(mid string) SendOption

WithSendMessageID sets message id.

func WithSendProperties

func WithSendProperties(m map[string]string) SendOption

WithSendProperties same as `WithSendProperty` but accepts map of keys and values.

func WithSendProperty

func WithSendProperty(k, v string) SendOption

WithSendProperty sets a message option.

func WithSendQoS

func WithSendQoS(qos int) SendOption

WithSendQoS sets the quality of service (MQTT only). Only 0 and 1 values are supported, defaults to 1.

type SharedAccessKeyCredentials

type SharedAccessKeyCredentials struct {
	DeviceID string
	common.SharedAccessKey
}

func ParseConnectionString

func ParseConnectionString(cs string) (*SharedAccessKeyCredentials, error)

func (*SharedAccessKeyCredentials) GetBroker

func (c *SharedAccessKeyCredentials) GetBroker() string

GetBroker not implemented for SharedAccessKeyCredentials

func (*SharedAccessKeyCredentials) GetCertificate

func (c *SharedAccessKeyCredentials) GetCertificate() *tls.Certificate

GetCertificate not implemented for SharedAccessKeyCredentials

func (*SharedAccessKeyCredentials) GetDeviceID

func (c *SharedAccessKeyCredentials) GetDeviceID() string

func (*SharedAccessKeyCredentials) GetGateway

func (c *SharedAccessKeyCredentials) GetGateway() string

GetGateway not implemented for SharedAccessKeyCredentials

func (*SharedAccessKeyCredentials) GetGenerationID

func (c *SharedAccessKeyCredentials) GetGenerationID() string

GetGenerationID not implemented for SharedAccessKeyCredentials

func (*SharedAccessKeyCredentials) GetHostName

func (c *SharedAccessKeyCredentials) GetHostName() string

func (*SharedAccessKeyCredentials) GetModuleID

func (c *SharedAccessKeyCredentials) GetModuleID() string

GetModuleID not implemented for SharedAccessKeyCredentials

func (*SharedAccessKeyCredentials) GetSAK

func (c *SharedAccessKeyCredentials) GetSAK() string

GetSAK not implemented for SharedAccessKeyCredentials

func (*SharedAccessKeyCredentials) GetWorkloadURI

func (c *SharedAccessKeyCredentials) GetWorkloadURI() string

GetWorkloadURI not implemented for SharedAccessKeyCredentials

func (*SharedAccessKeyCredentials) UseEdgeGateway

func (c *SharedAccessKeyCredentials) UseEdgeGateway() bool

UseEdgeGateway not implemented for SharedAccessKeyCredentials

type TwinState

type TwinState map[string]interface{}

TwinState is both desired and reported twin device's state.

func (TwinState) Version

func (s TwinState) Version() int

Version is state version.

type TwinStateSub

type TwinStateSub struct {
	// contains filtered or unexported fields
}

func (*TwinStateSub) C

func (s *TwinStateSub) C() <-chan TwinState

func (*TwinStateSub) Err

func (s *TwinStateSub) Err() error

type X509Credentials

type X509Credentials struct {
	HostName    string
	DeviceID    string
	Certificate *tls.Certificate
}

func (*X509Credentials) GetBroker

func (c *X509Credentials) GetBroker() string

GetBroker not implemented for X509Credentials

func (*X509Credentials) GetCertificate

func (c *X509Credentials) GetCertificate() *tls.Certificate

func (*X509Credentials) GetDeviceID

func (c *X509Credentials) GetDeviceID() string

func (*X509Credentials) GetGateway

func (c *X509Credentials) GetGateway() string

GetGateway not implemented for X509Credentials

func (*X509Credentials) GetGenerationID

func (c *X509Credentials) GetGenerationID() string

GetGenerationID not implemented for X509Credentials

func (*X509Credentials) GetHostName

func (c *X509Credentials) GetHostName() string

func (*X509Credentials) GetModuleID

func (c *X509Credentials) GetModuleID() string

GetModuleID not implemented for X509Credentials

func (*X509Credentials) GetSAK

func (c *X509Credentials) GetSAK() string

GetSAK not implemented for X509Credentials

func (*X509Credentials) GetWorkloadURI

func (c *X509Credentials) GetWorkloadURI() string

GetWorkloadURI not implemented for X509Credentials

func (*X509Credentials) Token

func (c *X509Credentials) Token(
	resource string, lifetime time.Duration,
) (*common.SharedAccessSignature, error)

func (*X509Credentials) TokenFromEdge

func (c *X509Credentials) TokenFromEdge(
	workloadURI, module, genid, resource string, lifetime time.Duration,
) (*common.SharedAccessSignature, error)

TokenFromEdge not implemented for X509Credentials

func (*X509Credentials) UseEdgeGateway

func (c *X509Credentials) UseEdgeGateway() bool

UseEdgeGateway not implemented for X509Credentials

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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