devices

package
v1.5.73 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthNone   = 0 //啥权限没有
	AuthNormal = 1 //普通功能权限
	AuthSystem = 2 //系统功能权限
	AuthShare  = 3 //只有分享的权限,需要进一步判断
	AuthAll    = 4 //拥有全部权限
)
View Source
const (
	DeviceRegisterUnable   = 1
	DeviceAutoCreateEnable = 3
	EncTypeCert            = 1 //证书加密
	EncTypeKey             = 2 //秘钥加密
)
View Source
const (
	ProductStatusEnable     = 1 //启用
	ProductStatusDisEnable  = 2 //禁用
	ProductStatusDeveloping = 3 //开发中
)
View Source
const (
	Sub = "Sub" //订阅
	Pub = "Pub" //发布
)
View Source
const (
	TopicHeadThing   = "$thing"
	TopicHeadOta     = "$ota"
	TopicHeadConfig  = "$config"
	TopicHeadLog     = "$log"
	TopicHeadShadow  = "$shadow"
	TopicHeadGateway = "$gateway"
	TopicHeadExt     = "$ext"
)

Variables

This section is empty.

Functions

func CreateToken

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

CreateToken 创建一个token

func GenMsgToken

func GenMsgToken(ctx context.Context, nodeID int64) string

func GetJwtToken

func GetJwtToken(secretKey string, t time.Time, seconds int64, bucket string, dir string) (string, error)

func IsLikelyText added in v1.4.1

func IsLikelyText(b []byte) bool

IsLikelyText 判断字节切片是否更可能是文本

func PublishToDev

func PublishToDev(handle string, Type string, payload []byte, protocolCode string, productID string, deviceName string) []byte

发送给设备的数据组包

func RefreshToken

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

更新token

Types

type Action

type Action = string
const (
	ActionConnected    Action = "connected"
	ActionDisconnected Action = "disconnected"
)

func IsOnlineToAction added in v1.5.25

func IsOnlineToAction(in bool) Action

type Affiliation

type Affiliation struct {
	TenantCode  string
	ProjectID   int64
	AreaID      int64
	AreaIDPath  string
	BelongGroup map[string]def.IDsInfo
}

归属

type Auth

type Auth = int64

type Core

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"`  //如果填写了下面的产品和设备ID,这个可以不填
	/*
		https://www.emqx.com/en/blog/emqx-mqtt-broker-connection-troubleshooting
			normal:客户端主动断开连接;
			kicked:被服务器踢出,通过 REST API;
			keepalive_timeout:保持活动超时;
			not_authorized:认证失败,或者acl_nomatch=disconnect时,没有权限的Pub/Sub会主动断开客户端连接;
			tcp_closed:对端关闭了网络连接;
			discard:因为相同ClientID的客户端上线了,并且设置了clean_start=true;
			takeovered:因为相同ClientID的客户端上线,并且设置了clean_start=false;
			internal_error:格式错误的消息或其他未知错误。
	*/
	Reason     string `json:"reason"`
	Action     Action `json:"action"` //登录 connected 登出 disconnected
	ProductID  string `json:"productID"`
	DeviceName string `json:"deviceName"`
}

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

type DevPublish

type DevPublish struct {
	Topic        string    `json:"topic"`  //只用于日志记录
	Handle       MsgHandle `json:"handle"` //对应 mqtt topic的第一个 thing ota config 等等
	Type         string    `json:"type"`   //操作类型 从topic中提取 物模型下就是   property属性 event事件 action行为
	Payload      []byte    `json:"payload"`
	Timestamp    int64     `json:"timestamp"` //毫秒时间戳
	ProductID    string    `json:"productID"`
	DeviceName   string    `json:"deviceName"`
	Explain      string    `json:"explain"`      //内部使用的拓展字段
	ProtocolCode string    `json:"protocolCode"` //如果有该字段则回复的时候也会带上该字段
}

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

func (*DevPublish) GetPayload added in v1.4.1

func (p *DevPublish) GetPayload() string

func (*DevPublish) String

func (p *DevPublish) String() string

type Direction

type Direction int

设备通信流向

const (
	Unknown Direction = iota //设备通信流向:未知
	Up                       //设备通信流向:上行
	Down                     //设备通信流向:下行
)

type Info

type Info struct {
	ProductID   string `json:"productID"`  //产品id
	DeviceName  string `json:"deviceName"` //设备名称
	TenantCode  string
	ProjectID   int64
	AreaID      int64
	AreaIDPath  string
	BelongGroup map[string]def.IDsInfo
}

type InnerPublish

type InnerPublish = DevPublish

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

func GetPublish

func GetPublish(data []byte) *InnerPublish

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

type MsgHandle

type MsgHandle = string
const (
	Thing   MsgHandle = "thing"
	Ota     MsgHandle = "ota"
	Config  MsgHandle = "config"
	Log     MsgHandle = "log"
	Shadow  MsgHandle = "shadow"
	Gateway MsgHandle = "gateway"
	Ext     MsgHandle = "ext"
)

type OssJwtToken

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

OssJwtToken Custom claims structure

func ParseToken

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

解析 token

type ProductStatus

type ProductStatus = int64

type ProtocolKey

type ProtocolKey = string
const (
	ProtocolKeyProductID ProtocolKey = "productID"
)

type Tag

type Tag struct {
	Key   string `json:"key"`   //设备标签key
	Value string `json:"value"` //设备标签value
}

设备标签

type TopicInfo

type TopicInfo struct {
	ProductID  string
	DeviceName string
	Direction  Direction
	Types      []string
	TopicHead  string
}

func GetTopicInfo

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

type WithGateway

type WithGateway struct {
	Dev     Core  `json:"dev"`
	Gateway *Core `json:"gateway,omitempty"` //如果是子设备类型,会带上网关
}

Jump to

Keyboard shortcuts

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