yemqtt

package module
v0.0.0-...-4f4606f Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: Apache-2.0 Imports: 4 Imported by: 1

README

mqttclient

mqtt客户端简单封装

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MqttClient

type MqttClient struct {
	Broker   string              // IP
	Port     int                 // 端口号
	ClientID string              // 客户端ID
	MClient  mqtt.Client         // 客户端实例
	MOpts    *mqtt.ClientOptions // 客户端配置
	Topic    string              // 主题名称
	// contains filtered or unexported fields
}

func MqttEngine

func MqttEngine(broker string, port int, clientID string) (mq *MqttClient)

MqttEngine 创建一个MQTT客户端

func (*MqttClient) Conn

func (m *MqttClient) Conn() (err error)

Conn 连接 broker

func (*MqttClient) Disconn

func (m *MqttClient) Disconn()

Disconn 断开MQTT 连接

func (*MqttClient) Ping

func (m *MqttClient) Ping()

Ping ping broker

func (*MqttClient) Publish

func (m *MqttClient) Publish(topicName string, msglevel string, msg string)

Publish 发布订阅

func (*MqttClient) Sub

func (m *MqttClient) Sub(topicName string, sf SubFunc) (err error)

Sub 订阅主题

func (*MqttClient) UnSub

func (m *MqttClient) UnSub(topicName string)

UnSub 取消订阅

type MsgJson

type MsgJson struct {
	Level string `json:"level"`
	Msg   string `json:"msg"`
	Time  string `json:"time"`
}

type SubFunc

type SubFunc = func(client mqtt.Client, msg mqtt.Message)

Jump to

Keyboard shortcuts

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