mqtt

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MQTTHub client
	MQTTHub *Client
	// ModuleContext variable
	ModuleContext *context.Context
	// NodeID stands for node id
	NodeID string
	// GroupID stands for group id
	GroupID string
	// ConnectedTopic to send connect event
	ConnectedTopic = "$hw/events/connected/%s"
	// DisconnectedTopic to send disconnect event
	DisconnectedTopic = "$hw/events/disconnected/%s"
	// MemberGet to get membership device
	MemberGet = "$hw/events/edgeGroup/%s/membership/get"
	// MemberGetRes to get membership device
	MemberGetRes = "$hw/events/edgeGroup/%s/membership/get/result"
	// MemberDetail which edge-client should be pub when service start
	MemberDetail = "$hw/events/edgeGroup/%s/membership/detail"
	// MemberDetailRes MemberDetail topic resp
	MemberDetailRes = "$hw/events/edgeGroup/%s/membership/detail/result"
	// MemberUpdate updating of the twin
	MemberUpdate = "$hw/events/edgeGroup/%s/membership/updated"
	// GroupUpdate updates a edgegroup
	GroupUpdate = "$hw/events/edgeGroup/%s/updated"
	// GroupAuthGet get temperary aksk from cloudhub
	GroupAuthGet = "$hw/events/edgeGroup/%s/authInfo/get"
	// GroupAuthGetRes temperary aksk from cloudhub
	GroupAuthGetRes = "$hw/events/edgeGroup/%s/authInfo/get/result"
	// SubTopics which edge-client should be sub
	SubTopics = []string{
		"$hw/events/upload/#",
		"$hw/events/device/+/state/update",
		"$hw/events/device/+/twin/+",
		"$hw/events/node/+/membership/get",
		"SYS/dis/upload_records",
	}
)

Functions

func OnSubMessageReceived

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

OnSubMessageReceived msg received callback

Types

type AccessInfo

type AccessInfo struct {
	Name    string `json:"name"`
	Type    string `json:"type"`
	Topic   string `json:"topic"`
	Content []byte `json:"content"`
}

AccessInfo that deliever between edge-hub and cloud-hub

type Client

type Client struct {
	MQTTUrl string
	PubCli  MQTT.Client
	SubCli  MQTT.Client
}

Client struct

func (*Client) InitPubClient

func (mq *Client) InitPubClient()

InitPubClient init pub client

func (*Client) InitSubClient

func (mq *Client) InitSubClient()

InitSubClient init sub client

func (*Client) PubMQTTMsg

func (mq *Client) PubMQTTMsg(topic string, qos byte, retained bool, payload interface{}) error

PubMQTTMsg pub msg to mqtt broker

type Server

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

Server serve as an internal mqtt broker.

func NewMqttServer

func NewMqttServer(sqz int, url string, retain bool, qos int) *Server

NewMqttServer create an internal mqtt server.

func (*Server) InitInternalTopics

func (m *Server) InitInternalTopics()

InitInternalTopics sets internal topics to server by default.

func (*Server) Publish

func (m *Server) Publish(topic string, payload []byte)

Publish will dispatch topic msg to its subscribers directly.

func (*Server) Run

func (m *Server) Run() error

Run launch a server and accept connections.

func (*Server) SetTopic

func (m *Server) SetTopic(topic string)

SetTopic set the topic to internal mqtt broker.

Jump to

Keyboard shortcuts

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