Documentation ¶
Index ¶
- type Client
- type Handler
- type MQTTClient
- func (client *MQTTClient) Connect() error
- func (client *MQTTClient) Publish(topic string, payload string, qos uint8) error
- func (client *MQTTClient) SendStatus(deviceID string, status string) (err error)
- func (client *MQTTClient) Subscribe(topic string, callback mqtt.MessageHandler, qos uint8) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶ added in v1.0.3
type Handler struct { // 获取协议插件的json表单 OnGetForm func(w http.ResponseWriter, r *http.Request) // 断开设备连接回调(让设备重新连接) OnDisconnectDevice func(w http.ResponseWriter, r *http.Request) }
Handler 结构体用于存储用户提供的回调函数
func (*Handler) ListenAndServe ¶ added in v1.0.3
ListenAndServe 函数启动一个HTTP服务器来处理TP平台的通知
type MQTTClient ¶ added in v1.0.4
type MQTTClient struct {
// contains filtered or unexported fields
}
MQTT客户端结构体
func NewMQTTClient ¶ added in v1.0.4
func NewMQTTClient(broker string, username string, password string) *MQTTClient
创建新的MQTT客户端
func (*MQTTClient) Connect ¶ added in v1.0.4
func (client *MQTTClient) Connect() error
连接到MQTT代理,如果连接失败则重试100次
func (*MQTTClient) Publish ¶ added in v1.0.4
func (client *MQTTClient) Publish(topic string, payload string, qos uint8) error
发布消息到指定主题
func (*MQTTClient) SendStatus ¶ added in v1.0.4
func (client *MQTTClient) SendStatus(deviceID string, status string) (err error)
发送在线离线消息status 1-在线 0-离线
func (*MQTTClient) Subscribe ¶ added in v1.0.4
func (client *MQTTClient) Subscribe(topic string, callback mqtt.MessageHandler, qos uint8) error
订阅指定主题,并提供一个处理接收到消息的回调函数
Click to show internal directories.
Click to hide internal directories.