Documentation ¶
Index ¶
- Constants
- func Convert(valueType string, value string) (result interface{}, err error)
- func CreateMessageData(name string, valueType string, value string) (msg []byte, err error)
- func CreateMessageState(state string) (msg []byte, err error)
- func CreateMessageTwinUpdate(name string, valueType string, value string) (msg []byte, err error)
- func GetDeviceID(topic string) (id string)
- type BaseMessage
- type Data
- type DataMetadata
- type DataProperty
- type DataValue
- type DesiredData
- type DeviceData
- type DeviceInstance
- type DeviceModel
- type DeviceProfile
- type DeviceTwinDelta
- type DeviceTwinResult
- type DeviceTwinUpdate
- type DeviceUpdate
- type Metadata
- type MqttClient
- type MsgAttr
- type MsgTwin
- type Property
- type PropertyVisitor
- type Protocol
- type ReportedData
- type Timer
- type Twin
- type TwinValue
- type TwinVersion
- type TypeMetadata
- type ValueMetadata
Constants ¶
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.
const ( ProtocolBlueTooth = "bluetooth" ProtocolModbus = "modbus" ProtocolOnvif = "onvif" ProtocolOpcua = "opcua" ProtocolCustomized = "customized-protocol" )
const ( DevInitModeRegister = "register" DevInitModeConfigmap = "configmap" )
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)
const DefaultCollectCycle = time.Second
const DefaultReportCycle = time.Second
Variables ¶
This section is empty.
Functions ¶
func CreateMessageData ¶
CreateMessageData create data message.
func CreateMessageState ¶
CreateMessageState create device status message.
func CreateMessageTwinUpdate ¶
CreateMessageTwinUpdate create twin update message.
func GetDeviceID ¶
GetDeviceID extract the device ID from Mqtt topic.
Types ¶
type BaseMessage ¶
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 ¶
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 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 ¶
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 string `json:"timestamp,omitempty"`
}
ValueMetadata the meta of value.