helper

package
v0.0.0-...-2d43aa0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DeviceETPrefix            = "$hw/events/device/"
	DeviceETStateUpdateSuffix = "/state/update"
	TwinETUpdateSuffix        = "/twin/update"
	TwinETCloudSyncSuffix     = "/twin/cloud_updated"
	TwinETGetSuffix           = "/twin/get"
	TwinETGetResultSuffix     = "/twin/get/result"
)
View Source
var Client MQTT.Client
View Source
var ClientOpts *MQTT.ClientOptions
View Source
var ControllerWg sync.WaitGroup
View Source
var TwinAttributes []string

Functions

func ChangeDeviceState

func ChangeDeviceState(state string, deviceID string)

ChangeDeviceState function is used to change the state of the device

func ChangeTwinValue

func ChangeTwinValue(updateMessage DeviceTwinUpdate, deviceID string)

ChangeTwinValue sends the updated twin value to the edge through the MQTT broker

func GetTwin

func GetTwin(updateMessage DeviceTwinUpdate, deviceID string)

GetTwin function is used to get the device twin details from the edge

func HubClientInit

func HubClientInit(server, clientID, username, password string) *MQTT.ClientOptions

HubclientInit create mqtt client config

func MqttConnect

func MqttConnect(mqttMode int, mqttInternalServer, mqttServer string)

MqttConnect function felicitates the MQTT connection

func OnTwinMessageReceived

func OnTwinMessageReceived(client MQTT.Client, message MQTT.Message)

OnTwinMessageReceived callback function which is called when message is received

func SyncToCloud

func SyncToCloud(updateMessage DeviceTwinUpdate, deviceID string)

SyncToCloud function syncs the updated device twin information to the cloud

func TwinSubscribe

func TwinSubscribe(deviceID string)

subscribe function subscribes the device twin information through the MQTT broker

Types

type BaseMessage

type BaseMessage struct {
	EventID   string `json:"event_id"`
	Timestamp int64  `json:"timestamp"`
}

BaseMessage the base struct of event message

type DeviceStateUpdate

type DeviceStateUpdate struct {
	State string `json:"state,omitempty"`
}

DeviceStateUpdate is the structure used in updating the device state

type DeviceTwinResult

type DeviceTwinResult struct {
	BaseMessage
	Twin map[string]*MsgTwin `json:"twin"`
}

DeviceTwinResult device get result

var TwinResult DeviceTwinResult

type DeviceTwinUpdate

type DeviceTwinUpdate struct {
	BaseMessage
	Twin map[string]*MsgTwin `json:"twin"`
}

DeviceTwinUpdate the struct of device twin update

func CreateActualUpdateMessage

func CreateActualUpdateMessage(updatedTwinAttributes map[string]string) DeviceTwinUpdate

CreateActualUpdateMessage function is used to create the device twin update message

type MsgTwin

type MsgTwin struct {
	Expected        *TwinValue    `json:"expected,omitempty"`
	Actual          *TwinValue    `json:"actual,omitempty"`
	Optional        *bool         `json:"optional,omitempty"`
	Metadata        *TypeMetadata `json:"metadata,omitempty"`
	ExpectedVersion *TwinVersion  `json:"expected_version,omitempty"`
	ActualVersion   *TwinVersion  `json:"actual_version,omitempty"`
}

MsgTwin the struct of device twin

type Token

type Token interface {
	Wait() bool
	WaitTimeout(time.Duration) bool
	Error() error
}

Token interface to validate the MQTT connection.

var TokenClient Token

type TwinValue

type TwinValue struct {
	Value    *string        `json:"value,omitempty"`
	Metadata *ValueMetadata `json:"metadata,omitempty"`
}

TwinValue the struct of twin value

type TwinVersion

type TwinVersion struct {
	CloudVersion int64 `json:"cloud"`
	EdgeVersion  int64 `json:"edge"`
}

TwinVersion twin version

type TypeMetadata

type TypeMetadata struct {
	Type string `json:"type,omitempty"`
}

TypeMetadata the meta of value type

type ValueMetadata

type ValueMetadata struct {
	Timestamp int64 `json:"timestamp,omitempty"`
}

ValueMetadata the meta of value

Jump to

Keyboard shortcuts

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