common

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: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEVSTOK        = "OK"
	DEVSTERR       = "ERROR"        /* Expected value is not equal as setting */
	DEVSTDISCONN   = "DISCONNECTED" /* Disconnected */
	DEVSTUNHEALTHY = "UNHEALTHY"    /* Unhealthy status from device */
	DEVSTUNKNOWN   = "UNKNOWN"
)

Device status definition.

View Source
const (
	TopicTwinUpdateDelta = "$hw/events/device/%s/twin/update/delta"
	TopicTwinUpdate      = "$hw/events/device/%s/twin/update"
	TopicStateUpdate     = "$hw/events/device/%s/state/update"
	TopicDataUpdate      = "$ke/events/device/%s/data/update"
)

Joint the topic like topic := fmt.Sprintf(TopicTwinUpdateDelta, deviceID)

Variables

This section is empty.

Functions

func Convert

func Convert(valueType string, value string) (result interface{}, err error)

Convert string to other types

func CreateMessageData

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

CreateMessageData create data message.

func CreateMessageState

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

CreateMessageState create device status message.

func CreateMessageTwinUpdate

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

CreateMessageTwinUpdate create twin update message.

func GetDeviceID

func GetDeviceID(topic string) (id string)

GetDeviceID extract the device ID from Mqtt topic.

Types

type BaseMessage

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

BaseMessage the base structure of event message.

type Data

type Data struct {
	Properties []DataProperty `json:"dataProperties,omitempty"`
	Topic      string         `json:"dataTopic,omitempty"`
}

Data is data structure for the message that only be subscribed in edge node internal.

type DataMetadata

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

DataMetadata data metadata.

type DataProperty

type DataProperty struct {
	Metadatas    DataMetadata `json:"metadata,omitempty"`
	PropertyName string       `json:"propertyName,omitempty"`
	PVisitor     *PropertyVisitor
}

DataProperty is data property.

type DataValue

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

DataValue data value.

type DesiredData

type DesiredData struct {
	Value     string   `json:"value,omitempty"`
	Metadatas Metadata `json:"metadata,omitempty"`
}

DesiredData is the desired data.

type DeviceData

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

DeviceData device data structure.

type DeviceInstance

type DeviceInstance struct {
	ID               string `json:"id,omitempty"`
	Name             string `json:"name,omitempty"`
	ProtocolName     string `json:"protocol,omitempty"`
	PProtocol        Protocol
	Model            string            `json:"model,omitempty"`
	Twins            []Twin            `json:"twins,omitempty"`
	Datas            Data              `json:"data,omitempty"`
	PropertyVisitors []PropertyVisitor `json:"propertyVisitors,omitempty"`
}

DeviceInstance is structure to store device in deviceProfile.json in configmap.

type DeviceModel

type DeviceModel struct {
	Name        string     `json:"name,omitempty"`
	Description string     `json:"description,omitempty"`
	Properties  []Property `json:"properties,omitempty"`
}

DeviceModel is structure to store deviceModel in deviceProfile.json in configmap.

type DeviceProfile

type DeviceProfile struct {
	DeviceInstances []DeviceInstance `json:"deviceInstances,omitempty"`
	DeviceModels    []DeviceModel    `json:"deviceModels,omitempty"`
	Protocols       []Protocol       `json:"protocols,omitempty"`
}

DeviceProfile is structure to store in configMap.

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 Metadata

type Metadata struct {
	Timestamp string `json:"timestamp,omitempty"`
	Type      string `json:"type,omitempty"`
}

Metadata is the metadata for data.

type MqttClient

type MqttClient struct {
	Qos        byte
	Retained   bool
	IP         string
	User       string
	Passwd     string
	Cert       string
	PrivateKey string
	Client     mqtt.Client
}

MqttClient is parameters for Mqtt client.

func (*MqttClient) Connect

func (mc *MqttClient) Connect() error

Connect connect to the Mqtt server.

func (*MqttClient) Publish

func (mc *MqttClient) Publish(topic string, payload interface{}) error

Publish publish Mqtt message.

func (*MqttClient) Subscribe

func (mc *MqttClient) Subscribe(topic string, onMessage mqtt.MessageHandler) error

Subscribe subscribe a Mqtt topic.

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 Property

type Property struct {
	Name         string      `json:"name,omitempty"`
	DataType     string      `json:"dataType,omitempty"`
	Description  string      `json:"description,omitempty"`
	AccessMode   string      `json:"accessMode,omitempty"`
	DefaultValue interface{} `json:"defaultValue,omitempty"`
	Minimum      int64       `json:"minimum,omitempty"`
	Maximum      int64       `json:"maximum,omitempty"`
	Unit         string      `json:"unit,omitempty"`
}

Property is structure to store deviceModel property.

type PropertyVisitor

type PropertyVisitor struct {
	Name          string `json:"name,omitempty"`
	PropertyName  string `json:"propertyName,omitempty"`
	ModelName     string `json:"modelName,omitempty"`
	CollectCycle  int64  `json:"collectCycle"`
	ReportCycle   int64  `json:"reportCycle,omitempty"`
	PProperty     Property
	Protocol      string          `json:"protocol,omitempty"`
	VisitorConfig json.RawMessage `json:"visitorConfig"`
}

PropertyVisitor is structure to store propertyVisitor in deviceProfile.json in configmap.

type Protocol

type Protocol struct {
	Name                 string          `json:"name,omitempty"`
	Protocol             string          `json:"protocol,omitempty"`
	ProtocolConfigs      json.RawMessage `json:"protocolConfig,omitempty"`
	ProtocolCommonConfig json.RawMessage `json:"protocolCommonConfig,omitempty"`
}

Protocol is structure to store protocol in deviceProfile.json in configmap.

type ReportedData

type ReportedData struct {
	Value     string   `json:"value,omitempty"`
	Metadatas Metadata `json:"metadata,omitempty"`
}

ReportedData is the reported data.

type Timer

type Timer struct {
	Function func()
	Duration time.Duration
	Times    int
}

Timer is to call a function periodically.

func (*Timer) Start

func (t *Timer) Start()

Start start a timer.

type Twin

type Twin struct {
	PropertyName string `json:"propertyName,omitempty"`
	PVisitor     *PropertyVisitor
	Desired      DesiredData  `json:"desired,omitempty"`
	Reported     ReportedData `json:"reported,omitempty"`
}

Twin is the set/get pair to one register.

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