tpprotocolsdkgo

package module
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

README

tp-protocol-sdk-go

Development of ThingsPanel protocol plug-in GO language SDK package

目录结构说明

├─api               # API层,处理HTTP请求和响应
└─example           # 示例代码目录

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v1.0.3

type Client struct {
	API *api.API
}

用于访问ThingsPanel API的客户端

func NewClient added in v1.0.3

func NewClient(baseURL string) *Client

创建一个新的客户端实例

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

func (h *Handler) ListenAndServe(addr string) error

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

订阅指定主题,并提供一个处理接收到消息的回调函数

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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