devices

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

README

这个包负责提供和设备相关公用的操作函数

Documentation

Index

Constants

View Source
const (
	Sub = "Sub" //订阅
	Pub = "Pub" //发布
)
View Source
const (
	TopicHeadThing   = "$thing"
	TopicHeadOta     = "$ota"
	TopicHeadConfig  = "$config"
	TopicHeadLog     = "$log"
	TopicHeadShadow  = "$shadow"
	TopicHeadGateway = "$gateway"
)

Variables

This section is empty.

Functions

func CreateToken

func CreateToken(secretKey string, claims OssJwtToken) (string, error)

CreateToken 创建一个token

func GetJwtToken

func GetJwtToken(secretKey string, iat, seconds int64, bucket string, dir string) (string, error)

func GetPublish

func GetPublish(data []byte) (topic string, payload []byte)

收到发送给设备的数据,解包

func PublishToDev

func PublishToDev(topic string, payload []byte) []byte

发送给设备的数据组包

func RefreshToken

func RefreshToken(tokenString string, secretKey string) (string, error)

更新token

Types

type Core added in v0.3.0

type Core struct {
	ProductID  string `json:"productID"`  //产品id
	DeviceName string `json:"deviceName"` //设备名称
}

type DevConn

type DevConn struct {
	UserName  string `json:"username"`
	Timestamp int64  `json:"timestamp"` //毫秒时间戳
	Address   string `json:"addr"`
	ClientID  string `json:"clientID"`
	Reason    string `json:"reason"`
	Action    string `json:"action"` //登录 onLogin 登出 onLogout
}

DevConn ddsvr 发布设备连接和断连的结构体

type DevPublish

type DevPublish struct {
	Timestamp  int64  `json:"timestamp"`
	ProductID  string `json:"productID"`
	DeviceName string `json:"deviceName"`
	Topic      string `json:"topic"`
	Payload    []byte `json:"payload"`
}

DevPublish ddsvr 发布设备发布信息的结构体

type Direction

type Direction int
const (
	Unknown Direction = iota //未知
	Up                       //上行
	Down                     //下行
)

type InnerPublish

type InnerPublish struct {
	Topic   string `json:"topic"`
	Payload []byte `json:"payload"`
}

InnerPublish 用于其他服务发送给ddsvr转发给设备的

type OssJwtToken

type OssJwtToken struct {
	Bucket string //oss的token
	Dir    string //对象路径
	jwt.StandardClaims
}

OssJwtToken Custom claims structure

func ParseToken

func ParseToken(tokenString string, secretKey string) (*OssJwtToken, error)

解析 token

type TopicInfo

type TopicInfo struct {
	ProductID  string
	DeviceName string
	Direction  Direction
	TopicHead  string
}

func GetTopicInfo

func GetTopicInfo(topic string) (topicInfo *TopicInfo, err error)

Jump to

Keyboard shortcuts

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