sparkplug

package
v0.0.0-...-a52557e Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Sparkplug 3.0.0 Note: Complies to v3.0.0 of the Sparkplug specification

to the extent needed for Winsonic DataIO and other industrial 4.0 products.

Copyright (c) 2023 Winsonic Electronics, Taiwan @author David Lee

* This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0.

Sparkplug 3.0.0 Note: Complies to v3.0.0 of the Sparkplug specification

to the extent needed for Winsonic DataIO and other industrial 4.0 products.

Copyright (c) 2023 Winsonic Electronics, Taiwan @author David Lee

* This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0.

Sparkplug 3.0.0 Note: Complies to v3.0.0 of the Sparkplug specification

to the extent needed for Winsonic DataIO and other industrial 4.0 products.

Copyright (c) 2023 Winsonic Electronics, Taiwan @author David Lee

* This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0.

Sparkplug 3.0.0 Note: Complies to v3.0.0 of the Sparkplug specification

to the extent needed for Winsonic DataIO and other industrial 4.0 products.

Copyright (c) 2023 Winsonic Electronics, Taiwan @author David Lee

* This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0.

Index

Constants

View Source
const (
	// Node message types
	MESSAGETYPE_NBIRTH = "NBIRTH"
	MESSAGETYPE_NDEATH = "NDEATH"
	MESSAGETYPE_NDATA  = "NDATA"
	MESSAGETYPE_NCMD   = "NCMD"
	// Device message types
	MESSAGETYPE_DBIRTH = "DBIRTH"
	MESSAGETYPE_DDEATH = "DDEATH"
	MESSAGETYPE_DDATA  = "DDATA"
	MESSAGETYPE_DCMD   = "DCMD"
)

Variables

This section is empty.

Functions

func GetWillPayload

func GetWillPayload(bdSeq int) ([]byte, error)

GetWillPayload will return the formatted payload with a single metric "bdSeq"

func RequestNodeRebirth

func RequestNodeRebirth(client mqtt.Client, groupID string, nodeID string) error

func SendNodeControlCMD

func SendNodeControlCMD(client mqtt.Client, groupID string, nodeID string, metrics []Metric) error

Send NCMD Node Control Command messages to Edge Node

Types

type Auth

type Auth struct {
	ServerUrl string
	Username  string
	Password  string
	GroupID   string
}

type ClientApp

type ClientApp struct {
	Auth                Auth
	MessagePubHandler   *mqtt.MessageHandler
	ConnectHandler      *mqtt.OnConnectHandler
	ConnectLostHandler  *mqtt.ConnectionLostHandler
	ReconnectingHandler *mqtt.ReconnectHandler
	// contains filtered or unexported fields
}

func (*ClientApp) Connect

func (c *ClientApp) Connect() error

func (*ClientApp) Disconnect

func (c *ClientApp) Disconnect()

Disconnect disconnects the client from the MQTT server

func (*ClientApp) SetOnline

func (c *ClientApp) SetOnline() error

SetOnline publishes and set state of application to "online"

type ClientNode

type ClientNode struct {
	Config              Config
	MessagePubHandler   *mqtt.MessageHandler
	ConnectHandler      *mqtt.OnConnectHandler
	ConnectLostHandler  *mqtt.ConnectionLostHandler
	ReconnectingHandler *mqtt.ReconnectHandler
	// contains filtered or unexported fields
}

func (*ClientNode) Connect

func (c *ClientNode) Connect(bdSeq int) error

Connect will connect to the MQTT broker Need to provide a bdSeq number which should increment with every connect The bdSeq number is from 0 to 255

func (*ClientNode) Disconnect

func (c *ClientNode) Disconnect()

Disconnect disconnects the client from the MQTT server

func (*ClientNode) PublishDeviceBirth

func (c *ClientNode) PublishDeviceBirth(deviceID string, metrics []Metric) error

func (*ClientNode) PublishDeviceData

func (c *ClientNode) PublishDeviceData(deviceID string, metrics []Metric) error

func (*ClientNode) PublishDeviceDeath

func (c *ClientNode) PublishDeviceDeath(deviceID string) error

func (*ClientNode) PublishNodeBirth

func (c *ClientNode) PublishNodeBirth(metrics []Metric) error

func (*ClientNode) PublishNodeData

func (c *ClientNode) PublishNodeData(metrics []Metric) error

func (*ClientNode) SubscribeDeviceCMD

func (c *ClientNode) SubscribeDeviceCMD(deviceID string)

type Config

type Config struct {
	ServerUrl string
	Username  string
	Password  string
	ClientID  string
	GroupID   string
	NodeID    string
}

type DataType

type DataType uint32
const (
	TypeInt    DataType = 3
	TypeFloat  DataType = 9
	TypeBool   DataType = 11
	TypeString DataType = 12
)

func (*DataType) String

func (d *DataType) String() string

type MessageType

type MessageType string

type Metric

type Metric struct {
	Name     string
	DataType DataType
	// IntValue    int
	// FloatValue  float32
	// BoolValue   bool
	// StringValue string
	Value string
}

type Payload

type Payload struct {
	Timestamp time.Time
	Seq       uint64
	Metrics   []Metric
}

func (*Payload) DecodePayload

func (p *Payload) DecodePayload(bytes []byte) error

func (*Payload) EncodePayload

func (p *Payload) EncodePayload(isDeathPayload bool) ([]byte, error)

Jump to

Keyboard shortcuts

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