mqttadapter

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package mqttadapter is a package to process mqtt message publish messages to EdgeCore and subscribe to EdgeCore messages

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMessageData

func CreateMessageData(name string, valueType string, value string) (msg []byte, err error)

CreateMessageData create binary data for structure of DeviceData

func CreateMessageState

func CreateMessageState(state string) (msg []byte, err error)

CreateMessageState create binary data for structure of DeviceData

func CreateMessageTwinUpdate

func CreateMessageTwinUpdate(name string, valueType string, value string) (msg []byte, err error)

CreateMessageTwinUpdate create twin update message.

func SendData

func SendData(ctx context.Context, id string, instance *configmap.DeviceInstance, drivers models.ProtocolDriver, mqttClient mqttclient.MqttClient, wg *sync.WaitGroup, dic *di.Container, mutex *common.Lock)

SendData send twin to third-part application according to timer

func SendDeviceState

func SendDeviceState(ctx context.Context, id string, instance *configmap.DeviceInstance, drivers models.ProtocolDriver, mqttClient mqttclient.MqttClient, wg *sync.WaitGroup, dic *di.Container, mutex *common.Lock)

SendDeviceState send device's state to EdgeCore according to timer

func SendTwin

func SendTwin(ctx context.Context, id string, instance *configmap.DeviceInstance, drivers models.ProtocolDriver, mqttClient mqttclient.MqttClient, wg *sync.WaitGroup, dic *di.Container, mutex *common.Lock)

SendTwin send twin to EdgeCore according to timer

func SyncInfo

func SyncInfo(dic *di.Container, message mqtt.Message)

SyncInfo callback function of Mqtt subscribe message. The function will update device's value according to the message sent from the cloud

func UpdateDevice

func UpdateDevice(dic *di.Container, message mqtt.Message)

UpdateDevice callback function of Mqtt subscribe message. The function support for dynamically adding/removing devices

Types

type BaseMessage

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

BaseMessage the base structure of mqttadapter message.

type DataMetadata

type DataMetadata struct {
	Timestamp int64  `json:"timestamp"`
	Type      string `json:"type"`
}

DataMetadata data metadata.

type DataValue

type DataValue struct {
	Value    string       `json:"value"`
	Metadata DataMetadata `json:"metadata"`
}

DataValue data value.

type DeviceData

type DeviceData struct {
	BaseMessage
	Data map[string]*DataValue `json:"data"`
}

DeviceData device data structure.

type DeviceTwinDelta

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

DeviceTwinDelta twin delta.

type DeviceTwinResult

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

DeviceTwinResult device get result.

type DeviceTwinUpdate

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

DeviceTwinUpdate the structure of device twin update.

type DeviceUpdate

type DeviceUpdate struct {
	BaseMessage
	State      string              `json:"state,omitempty"`
	Attributes map[string]*MsgAttr `json:"attributes"`
}

DeviceUpdate device update.

type DriverUnit

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

DriverUnit the structure necessary to send a message

type MsgAttr

type MsgAttr struct {
	Value    string        `json:"value"`
	Optional *bool         `json:"optional,omitempty"`
	Metadata *TypeMetadata `json:"metadata,omitempty"`
}

MsgAttr the struct of device attr

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 structure of device twin.

type StatusData

type StatusData struct {
	MqttClient mqttclient.MqttClient
	// contains filtered or unexported fields
}

StatusData the structure of device status.

func (*StatusData) Run

func (sd *StatusData) Run()

Run start timer function to get device's status and send it to mqtt broker

type TwinData

type TwinData struct {
	Name       string
	Type       string
	Topic      string
	Value      string
	MqttClient mqttclient.MqttClient
	// contains filtered or unexported fields
}

TwinData the structure of device twin

func (*TwinData) Run

func (td *TwinData) Run()

Run start timer function to get device's twin or data, and send it to mqtt broker

type TwinValue

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

TwinValue the structure 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