mqttcli

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 3 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 Publish

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

Publish 发布消息

func Subscribe

func Subscribe(topic string, qos byte, callback MQTT.MessageHandler)

Subscribe 订阅主题

Types

type Option

type Option func(*Options)

func WithClientID

func WithClientID(clientID string, asPrefix bool) Option

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

func WithUserAndPass

func WithUserAndPass(username, pwd string) Option

WithUserAndPass 设置用户名和密码

type Options

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

Jump to

Keyboard shortcuts

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