mqttcli

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close 关闭MQTT连接

func Connect

func Connect(addr string, options ...Option)

Connect 连接MQTT服务器

func GetConnectionStatus added in v1.2.8

func GetConnectionStatus() string

GetConnectionStatus 获取客户端状态

func IsConnected added in v1.2.8

func IsConnected() bool

IsConnected 连接状态检查

func Publish

func Publish(topic string, qos byte, payload any) error

Publish 发布消息

func Subscribe

func Subscribe(topic string, qos byte, callback MsgHandler) error

Subscribe 订阅主题

Types

type MsgHandler added in v0.17.0

type MsgHandler func(ID uint16, topic string, payload []byte)

type Option

type Option func(*Options)

func AuthWithTLS added in v1.1.0

func AuthWithTLS(certFile, keyFile string) Option

AuthWithTLS TLS认证

func AuthWithUser added in v1.1.0

func AuthWithUser(username, pwd string) Option

AuthWithUser 用户名密码认证

func WithClientID

func WithClientID(clientID string, asPrefix bool) Option

WithClientID 设置客户端ID,仅仅作为前缀时会自动拼接随机串

type Options

type Options struct {
	ClientID string // 客户端ID,不设置时会自动随机生成
	Username string // 用户名
	Password string // 密码
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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