aiot

package module
v0.0.3-rc0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2021 License: MIT Imports: 15 Imported by: 0

README

aliyun 物联网设备接入的golang实现 (WIP)

GoDoc Go.Dev reference Build Status codecov Action Status Go Report Card Licence Tag

  • infra 公共包
  • sign: 实现MQTT签名,独立使用,不依赖第三方任何包
  • dynamic: 直连设备动态注册
  • ahttp: http 上云实现
  • dataflow: 服务器订阅数据流定义

Feature

  • device

    • raw up and raw up reply
    • raw down
    • event property post and reply
    • event post and reply
    • ntp
    • config get and push
    • label update and delete
    • RRPC
    • extend RRPC
  • gateway

    • event property pack post
    • event property history post

Donation

if package help you a lot,you can support us by:

Alipay

alipay

WeChat Pay

wxpay

Documentation

Overview

Package aiot imp aliyun dm

Index

Constants

View Source
const (
	DefaultCacheExpiration      = time.Second * 10
	DefaultCacheCleanupInterval = time.Second * 30
)

缓存默认值

View Source
const (
	OtaProgressStepUpgradeFailed  = -1
	OtaProgressStepDownloadFailed = -2
	OtaProgressStepVerifyFailed   = -3
	OtaProgressStepProgramFailed  = -4
)

OTA下载进度比

View Source
const (
	LogFatal = "FATAL"
	LogError = "ERROR"
	LogWarn  = "WARN"
	LogInfo  = "INFO"
	LogDebug = "DEBUG"
	LogOther = "OTHER"
)

Log level,从高到低

View Source
const DefaultVersion = "1.0"

DefaultVersion 平台通信版本

View Source
const DevInfoLabelCoordinateKey = "coordinate"

DevInfoLabelCoordinateKey 地理位置标签

Variables

View Source
var (
	ErrInvalidURI        = errors.New("invalid URI")
	ErrNotFound          = errors.New("not found")
	ErrInvalidParameter  = errors.New("invalid parameter")
	ErrNotSupportFeature = errors.New("not support feature")
	ErrWaitTimeout       = errors.New("wait timeout")
	ErrEntryClosed       = errors.New("entry has closed")
	ErrDeviceHasExist    = errors.New("device has exist")
	ErrNotPermit         = errors.New("not permit")
	ErrNotActive         = errors.New("device not active")
	ErrNotAvail          = errors.New("device not avail")
)

错误相关定义

Functions

func FormatKey

func FormatKey(pk, dn string) string

FormatKey format pk dn --> {pk}.{dn}

func ProcExtCombineBatchLoginReply

func ProcExtCombineBatchLoginReply(c *Client, rawURI string, payload []byte) error

ProcExtCombineBatchLoginReply 子设备批量上线应答处理 request: /ext/session/{productKey}/{deviceName}/combine/batch_login response: /ext/session/{productKey}/{deviceName}/combine/batch_login_reply subscribe: /ext/session/{productKey}/{deviceName}/combine/batch_login_reply

func ProcExtCombineBatchLogoutReply

func ProcExtCombineBatchLogoutReply(c *Client, rawURI string, payload []byte) error

ProcExtCombineBatchLogoutReply 子设备批量下线应答处理 上行 request: /ext/session/{productKey}/{deviceName}/combine/batch_logout response: /ext/session/{productKey}/{deviceName}/combine/batch_logout_reply subscribe: /ext/session/{productKey}/{deviceName}/combine/batch_logout_reply

func ProcExtCombineLoginReply

func ProcExtCombineLoginReply(c *Client, rawURI string, payload []byte) error

ProcExtCombineLoginReply 处理子设备上线应答 request: /ext/session/{productKey}/{deviceName}/combine/login response: /ext/session/{productKey}/{deviceName}/combine/login_reply subscribe: /ext/session/{productKey}/{deviceName}/combine/login_reply

func ProcExtCombineLogoutReply

func ProcExtCombineLogoutReply(c *Client, rawURI string, payload []byte) error

ProcExtCombineLogoutReply 子设备下线应答处理 上行 request: /ext/session/{productKey}/{deviceName}/combine/logout response: /ext/session/{productKey}/{deviceName}/combine/logout_reply subscribe: /ext/session/{productKey}/{deviceName}/combine/logout_reply

func ProcExtErrorResponse

func ProcExtErrorResponse(c *Client, rawURI string, payload []byte) error

ProcExtErrorResponse 处理错误的回复,仅与子设备 response: ext/error/{productKey}/{deviceName} subscribe: ext/error/{productKey}/{deviceName}

func ProcExtNetworkProbeRequest

func ProcExtNetworkProbeRequest(c *Client, rawURI string, _ []byte) error

ProcExtNetworkProbeRequest 处理平台测试延迟请求 request: /ext/network/probe/${messageId} subscribe: /ext/network/probe/+

func ProcExtNtpResponse

func ProcExtNtpResponse(c *Client, rawURI string, payload []byte) error

ProcExtNtpResponse 处理ntp请求的应答 上行 request: /ext/ntp/${YourProductKey}/${YourDeviceName}/request response: /ext/ntp/${YourProductKey}/${YourDeviceName}/response subscribe: /ext/ntp/${YourProductKey}/${YourDeviceName}/response

func ProcExtRRPCRequest

func ProcExtRRPCRequest(c *Client, rawURI string, payload []byte) error

ProcExtRRPCRequest 处理扩展RRPC请求 ${topic} 不为空,设备建立要求clientID传ext = 1 request: /ext/rrpc/${messageId}/${topic} response: /ext/rrpc/${messageId}/${topic} subscribe: /ext/rrpc/+/${topic}

/ext/rrpc/#

func ProcOtaUpgrade

func ProcOtaUpgrade(c *Client, rawURI string, payload []byte) error

ProcOtaUpgrade 处理物联网平台推送固件信息 request: /ota/device/upgrade/${YourProductKey}/${YourDeviceName} subscribe:/ota/device/upgrade/${YourProductKey}/${YourDeviceName}

func ProcRRPCRequest

func ProcRRPCRequest(c *Client, rawURI string, payload []byte) error

ProcRRPCRequest 处理RRPC请求 request: /sys/${YourProductKey}/${YourDeviceName}/rrpc/request/${messageId} response: /sys/${YourProductKey}/${YourDeviceName}/rrpc/response/${messageId} subscribe: /sys/${YourProductKey}/${YourDeviceName}/rrpc/request/+

func ProcThingConfigGetReply

func ProcThingConfigGetReply(c *Client, rawURI string, payload []byte) error

ProcThingConfigGetReply 处理获取配置的应答 上行 request: /sys/{productKey}/{deviceName}/thing/config/get response: /sys/{productKey}/{deviceName}/thing/config/get_reply subscribe: /sys/{productKey}/{deviceName}/thing/config/get_reply

func ProcThingConfigLogGetReply

func ProcThingConfigLogGetReply(c *Client, rawURI string, payload []byte) error

ProcThingConfigLogGetReply 处理获取日志配置应答 request: /sys/${productKey}/${deviceName}/thing/config/Log/get response: /sys/${productKey}/${deviceName}/thing/config/Log/get_reply subscribe: /sys/${productKey}/${deviceName}/thing/config/Log/get_reply

func ProcThingConfigLogPush

func ProcThingConfigLogPush(c *Client, rawURI string, payload []byte) error

ProcThingConfigLogPush 处理日志配置推送 subscribe: /sys/${productKey}/${deviceName}/thing/config/Log/push

func ProcThingConfigPush

func ProcThingConfigPush(c *Client, rawURI string, payload []byte) error

ProcThingConfigPush 处理配置推送,已做回复 下行 request: /sys/{productKey}/{deviceName}/thing/config/push response: /sys/{productKey}/{deviceName}/thing/config/push_reply subscribe: /sys/{productKey}/{deviceName}/thing/config/push

func ProcThingDelete

func ProcThingDelete(c *Client, rawURI string, payload []byte) error

ProcThingDelete 子设备删除,网关类型设备 下行 request: /sys/{productKey}/{deviceName}/thing/delete response: /sys/{productKey}/{deviceName}/thing/delete_reply subscribe: /sys/{productKey}/{deviceName}/thing/delete

func ProcThingDesiredPropertyDeleteReply

func ProcThingDesiredPropertyDeleteReply(c *Client, rawURI string, payload []byte) error

ProcThingDesiredPropertyDeleteReply 处理清空期望属性值的应答 request: /sys/{productKey}/{deviceName}/thing/property/desired/delete response: /sys/{productKey}/{deviceName}/thing/property/desired/delete_reply subscribe: /sys/{productKey}/{deviceName}/thing/property/desired/delete_reply

func ProcThingDesiredPropertyGetReply

func ProcThingDesiredPropertyGetReply(c *Client, rawURI string, payload []byte) error

ProcThingDesiredPropertyGetReply 处理获取期望属性值的应答 上行 request: /sys/{productKey}/{deviceName}/thing/property/desired/get response: /sys/{productKey}/{deviceName}/thing/property/desired/get_reply subscribe: /sys/{productKey}/{deviceName}/thing/property/desired/get_reply

func ProcThingDeviceInfoDeleteReply

func ProcThingDeviceInfoDeleteReply(c *Client, rawURI string, payload []byte) error

ProcThingDeviceInfoDeleteReply 处理设备信息删除的应答 request: /sys/{productKey}/{deviceName}/thing/deviceinfo/delete response: /sys/{productKey}/{deviceName}/thing/deviceinfo/delete_reply subscribe: /sys/{productKey}/{deviceName}/thing/deviceinfo/delete_reply

func ProcThingDeviceInfoUpdateReply

func ProcThingDeviceInfoUpdateReply(c *Client, rawURI string, payload []byte) error

ProcThingDeviceInfoUpdateReply 处理设备信息更新应答 request: /sys/{productKey}/{deviceName}/thing/deviceinfo/update response: /sys/{productKey}/{deviceName}/thing/deviceinfo/update_reply subscribe: /sys/{productKey}/{deviceName}/thing/deviceinfo/update_reply

func ProcThingDialPostReply

func ProcThingDialPostReply(c *Client, rawURI string, payload []byte) error

ProcThingDialPostReply 处理设备主动上报网络状态回复 request: /sys/{productKey}/{deviceName}/_thing/diag/post response: /sys/{productKey}/{deviceName}/_thing/diag/post_reply subscribe: /sys/{productKey}/{deviceName}/_thing/diag/post_reply

func ProcThingDisable

func ProcThingDisable(c *Client, rawURI string, payload []byte) error

ProcThingDisable 禁用子设备 request: /sys/{productKey}/{deviceName}/thing/disable response: /sys/{productKey}/{deviceName}/thing/disable_reply subscribe: /sys/{productKey}/{deviceName}/thing/disable

func ProcThingDsltemplateGetReply

func ProcThingDsltemplateGetReply(c *Client, rawURI string, payload []byte) error

ProcThingDsltemplateGetReply 处理dsltemplate获取的应答 request: /sys/{productKey}/{deviceName}/thing/dsltemplate/get response: /sys/{productKey}/{deviceName}/thing/dsltemplate/get_reply subscribe: /sys/{productKey}/{deviceName}/thing/dsltemplate/get_reply

func ProcThingDynamictslGetReply

func ProcThingDynamictslGetReply(c *Client, rawURI string, payload []byte) error

ProcThingDynamictslGetReply 处理获取动态tsl应答 request: /sys/${YourProductKey}/${YourDeviceName}/thing/dynamicTsl/get response: /sys/${YourProductKey}/${YourDeviceName}/thing/dynamicTsl/get_reply subscribe: /sys/${YourProductKey}/${YourDeviceName}/thing/dynamicTsl/get_reply

func ProcThingEnable

func ProcThingEnable(c *Client, rawURI string, payload []byte) error

ProcThingEnable 启用子设备 下行 request: /sys/{productKey}/{deviceName}/thing/enable response: /sys/{productKey}/{deviceName}/thing/enable_reply subscribe: /sys/{productKey}/{deviceName}/thing/enable

func ProcThingEventPostReply

func ProcThingEventPostReply(c *Client, rawURI string, payload []byte) error

ProcThingEventPostReply 处理ThingEvent XXX上行的应答 上行 request: /sys/{productKey}/{deviceName}/thing/event/[{tsl.event.identifier},property]/post response: /sys/{productKey}/{deviceName}/thing/event/[{tsl.event.identifier},property]/post_reply subscribe: /sys/{productKey}/{deviceName}/thing/event/+/post_reply

func ProcThingEventPropertyHistoryPostReply

func ProcThingEventPropertyHistoryPostReply(c *Client, rawURI string, payload []byte) error

ProcThingEventPropertyHistoryPostReply 物模型历史数据上报应答 request: /sys/{productKey}/{deviceName}/thing/event/property/history/post response: /sys/{productKey}/{deviceName}/thing/event/property/history/post_reply subscribe: /sys/{productKey}/{deviceName}/thing/event/property/history/post_reply

func ProcThingEventPropertyPackPostReply

func ProcThingEventPropertyPackPostReply(c *Client, rawURI string, payload []byte) error

ProcThingEventPropertyPackPostReply 网关批量上报数据 上行,仅网关支持 request: /sys/{productKey}/{deviceName}/thing/event/property/pack/post response: /sys/{productKey}/{deviceName}/thing/event/property/pack/post_reply subscribe: /sys/{productKey}/{deviceName}/thing/event/property/pack/post_reply

func ProcThingListFoundReply

func ProcThingListFoundReply(c *Client, rawURI string, payload []byte) error

ProcThingListFoundReply 处理发现设备列表上报应答 request: /sys/{productKey}/{deviceName}/thing/list/found response: /sys/{productKey}/{deviceName}/thing/list/found_reply subscribe: /sys/{productKey}/{deviceName}/thing/list/found_reply

func ProcThingLogPostReply

func ProcThingLogPostReply(c *Client, rawURI string, payload []byte) error

ProcThingLogPostReply 处理日志上报应答 request: /sys/${productKey}/${deviceName}/thing/Log/post response:/sys/${productKey}/${deviceName}/thing/Log/post_reply

func ProcThingModelDownRaw

func ProcThingModelDownRaw(c *Client, rawURI string, payload []byte) error

ProcThingModelDownRaw 处理透传下行数据 下行 request: /sys/{productKey}/{deviceName}/thing/model/down_raw response: /sys/{productKey}/{deviceName}/thing/model/down_raw_reply subscribe: /sys/{productKey}/{deviceName}/thing/model/down_raw

func ProcThingModelUpRawReply

func ProcThingModelUpRawReply(c *Client, rawURI string, payload []byte) error

ProcThingModelUpRawReply 处理透传上行的应答 request: /sys/{productKey}/{deviceName}/thing/model/up_raw response: /sys/{productKey}/{deviceName}/thing/model/up_raw_reply subscribe: /sys/{productKey}/{deviceName}/thing/model/up_raw_reply

func ProcThingOtaFirmwareGetReply

func ProcThingOtaFirmwareGetReply(c *Client, rawURI string, payload []byte) error

ProcThingOtaFirmwareGetReply 处理请求固件信息应答 request: /sys/{productKey}/{deviceName}/thing/ota/firmware/get response: /sys/{productKey}/{deviceName}/thing/ota/firmware/get_reply subscribe:/sys/{productKey}/{deviceName}/thing/ota/firmware/get_reply

func ProcThingServiceRequest

func ProcThingServiceRequest(c *Client, rawURI string, payload []byte) error

ProcThingServiceRequest 处理设备服务调用(异步) 下行 request: /sys/{productKey}/{deviceName}/thing/service/[{tsl.service.identifier},property/set] response: /sys/{productKey}/{deviceName}/thing/service/[{tsl.service.identifier}_reply,property/set_reply subscribe: /sys/{productKey}/{deviceName}/thing/service/[+,#]

func ProcThingSubRegisterReply

func ProcThingSubRegisterReply(c *Client, rawURI string, payload []byte) error

ProcThingSubRegisterReply 处理子设备动态注册回复 request: /sys/{productKey}/{deviceName}/thing/sub/register response: /sys/{productKey}/{deviceName}/thing/sub/register_reply subscribe: /sys/{productKey}/{deviceName}/thing/sub/register_reply

func ProcThingTopoAddNotify

func ProcThingTopoAddNotify(c *Client, rawURI string, payload []byte) error

ProcThingTopoAddNotify 通知网关添加设备拓扑关系 request: /sys/{productKey}/{deviceName}/thing/topo/add/notify response: /sys/{productKey}/{deviceName}/thing/topo/add/notify_reply subscribe: /sys/{productKey}/{deviceName}/thing/topo/add/notify

func ProcThingTopoAddReply

func ProcThingTopoAddReply(c *Client, rawURI string, payload []byte) error

ProcThingTopoAddReply 处理网络拓扑添加 request: /sys/{productKey}/{deviceName}/thing/topo/add response: /sys/{productKey}/{deviceName}/thing/topo/add_reply subscribe: /sys/{productKey}/{deviceName}/thing/topo/add_reply

func ProcThingTopoChange

func ProcThingTopoChange(c *Client, rawURI string, payload []byte) error

ProcThingTopoChange 通知网关拓扑关系变化 request: /sys/{productKey}/{deviceName}/thing/topo/change response: /sys/{productKey}/{deviceName}/thing/topo/change_reply subscribe: /sys/{productKey}/{deviceName}/thing/topo/change

func ProcThingTopoDeleteReply

func ProcThingTopoDeleteReply(c *Client, rawURI string, payload []byte) error

ProcThingTopoDeleteReply 处理删除网络拓扑 request: /sys/{productKey}/{deviceName}/thing/topo/delete response: /sys/{productKey}/{deviceName}/thing/topo/delete_reply subscribe: /sys/{productKey}/{deviceName}/thing/topo/delete_reply

func ProcThingTopoGetReply

func ProcThingTopoGetReply(c *Client, rawURI string, payload []byte) error

ProcThingTopoGetReply 处理获取该网关和子设备的拓扑关系 request: /sys/{productKey}/{deviceName}/thing/topo/get response: /sys/{productKey}/{deviceName}/thing/topo/get_reply subscribe: /sys/{productKey}/{deviceName}/thing/topo/get_reply

Types

type Callback

type Callback interface {
	// 透传应答
	ThingModelUpRawReply(c *Client, productKey, deviceName string, payload []byte) error
	// 透传请求,需要用户自己处理及应答
	ThingModelDownRaw(c *Client, productKey, deviceName string, payload []byte) error
	// event
	ThingEventPropertyPostReply(c *Client, err error, productKey, deviceName string) error
	ThingEventPostReply(c *Client, err error, eventID, productKey, deviceName string) error
	ThingEventPropertyPackPostReply(c *Client, err error, productKey, deviceName string) error
	ThingEventPropertyHistoryPostReply(c *Client, err error, productKey, deviceName string) error
	// device info
	ThingDeviceInfoUpdateReply(c *Client, err error, productKey, deviceName string) error
	ThingDeviceInfoDeleteReply(c *Client, err error, productKey, deviceName string) error
	// desired property
	ThingDesiredPropertyGetReply(c *Client, err error, productKey, deviceName string, data json.RawMessage) error
	ThingDesiredPropertyDeleteReply(c *Client, err error, productKey, deviceName string) error
	// template
	ThingDsltemplateGetReply(c *Client, err error, productKey, deviceName string, data json.RawMessage) error
	ThingDynamictslGetReply(c *Client, err error, productKey, deviceName string, data json.RawMessage) error
	// config
	ThingConfigGetReply(c *Client, err error, productKey, deviceName string, data ConfigParamsData) error
	// 配置推送,已做默认回复
	ThingConfigPush(c *Client, productKey, deviceName string, params ConfigParamsData) error

	// Log
	ThingConfigLogGetReply(c *Client, err error, productKey, deviceName string, data ConfigLogParamData) error
	ThingConfigLogPush(c *Client, productKey, deviceName string, param ConfigLogParamData) error
	ThingLogPostReply(c *Client, err error, productKey, deviceName string) error

	// diag
	ThingDialPostReply(c *Client, err error, productKey, deviceName string) error

	// service
	// 设置设备属性, 需用户自行做回复
	ThingServicePropertySet(c *Client, productKey, deviceName string, payload []byte) error
	// 设备服务调用,需用户自行做回复
	ThingServiceRequest(c *Client, srvID, productKey, deviceName string, payload []byte) error

	// ntp
	ExtNtpResponse(c *Client, productKey, deviceName string, exact time.Time) error

	// 系统RRPC调用, 仅支持设备端Qos = 0的回复,需用户自行做回复
	RRPCRequest(c *Client, messageID, productKey, deviceName string, payload []byte) error
	// 自定义RRPC调用,仅支持设备端Qos = 0的回复, 需用户自行做回复
	ExtRRPCRequest(c *Client, messageID, topic string, payload []byte) error
	// ota
	OtaUpgrade(c *Client, productKey, deviceName string, rsp *OtaFirmwareResponse) error
	ThingOtaFirmwareGetReply(c *Client, productKey, deviceName string, data OtaFirmwareData) error
}

Callback 事件回调接口

type Client

type Client struct {
	*DevMgr

	Conn

	Log logger.Logger
	// contains filtered or unexported fields
}

Client 客户端

func New

func New(triad infra.MetaTriad, conn Conn, opts ...Option) *Client

New 创建一个物管理客户端

func (*Client) AddSubDevice

func (sf *Client) AddSubDevice(meta infra.MetaTriad) error

AddSubDevice 增加一个一个子设备

func (*Client) Connect

func (sf *Client) Connect() error

Connect 将订阅所有相关主题,主题有config配置

func (*Client) ExtNtpRequest

func (sf *Client) ExtNtpRequest() error

ExtNtpRequest ntp请求 发送一条Qos = 0的消息,并带上设备当前的时间戳,平台将回复 设备的发送时间,平台的接收时间, 平台的发送时间. 设备计算当前精确时间 = (平台接收时间 + 平台发送时间 + 设备接收时间 - 设备发送时间) / 2 请求Topic:/ext/ntp/${YourProductKey}/${YourDeviceName}/request 响应Topic:/ext/ntp/${YourProductKey}/${YourDeviceName}/response

func (*Client) ExtRRPCResponse

func (sf *Client) ExtRRPCResponse(messageID, topic string, payload interface{}) error

ExtRRPCResponse ext rrpc回复 NOTE: 只支持Qos=0回复 response: /ext/rrpc/${messageId}/${topic} see https://help.aliyun.com/document_detail/90570.html?spm=a2c4g.11186623.6.656.64076175n5VFHO#title-0r5-s8c-t1c

func (*Client) LinkExtCombineBatchLogin

func (sf *Client) LinkExtCombineBatchLogin(pairs []CombinePair, timeout time.Duration) error

LinkExtCombineBatchLogin 子设备批量上线,同步

func (*Client) LinkExtCombineBatchLogout

func (sf *Client) LinkExtCombineBatchLogout(pairs []infra.MetaPair, timeout time.Duration) error

LinkExtCombineBatchLogout 子设备批量下线,同步

func (*Client) LinkExtCombineLogin

func (sf *Client) LinkExtCombineLogin(cp CombinePair, timeout time.Duration) error

LinkExtCombineLogin 子设备上线,同步

func (*Client) LinkExtCombineLogout

func (sf *Client) LinkExtCombineLogout(pk, dn string, timeout time.Duration) error

LinkExtCombineLogout 子设备下线,同步

func (*Client) LinkThingConfigGet

func (sf *Client) LinkThingConfigGet(pk, dn string, timeout time.Duration) (ConfigParamsData, error)

LinkThingConfigGet 获取配置参数,同步

func (*Client) LinkThingConfigLogGet

func (sf *Client) LinkThingConfigLogGet(pk, dn string,
	clp ConfigLogParam, timeout time.Duration) (ConfigLogParamData, error)

LinkThingConfigLogGet 获取日志配置,同步

func (*Client) LinkThingDesiredPropertyDelete

func (sf *Client) LinkThingDesiredPropertyDelete(pk, dn string, params interface{}, timeout time.Duration) error

LinkThingDesiredPropertyDelete 清空期望属性值,同步

func (*Client) LinkThingDesiredPropertyGet

func (sf *Client) LinkThingDesiredPropertyGet(pk, dn string,
	params []string, timeout time.Duration) (json.RawMessage, error)

LinkThingDesiredPropertyGet 获取期望属性值,同步

func (*Client) LinkThingDeviceInfoDelete

func (sf *Client) LinkThingDeviceInfoDelete(pk, dn string, params []DeviceLabelKey, timeout time.Duration) error

LinkThingDeviceInfoDelete 删除标签信息.同步

func (*Client) LinkThingDeviceInfoUpdate

func (sf *Client) LinkThingDeviceInfoUpdate(pk, dn string, params []DeviceInfoLabel, timeout time.Duration) error

LinkThingDeviceInfoUpdate 设备信息上传(如厂商,设备型号等,可以保存为设备标签),同步

func (*Client) LinkThingDiagHistoryPost

func (sf *Client) LinkThingDiagHistoryPost(pk, dn string, p []P, timeout time.Duration) error

LinkThingDiagHistoryPost 设备主动上报历史网络状态,同步

func (*Client) LinkThingDiagPost

func (sf *Client) LinkThingDiagPost(pk, dn string, p P, timeout time.Duration) error

LinkThingDiagPost 设备主动上报当前网络状态,同步

func (*Client) LinkThingDsltemplateGet

func (sf *Client) LinkThingDsltemplateGet(pk, dn string, timeout time.Duration) (json.RawMessage, error)

LinkThingDsltemplateGet 设备可以通过上行请求获取设备的TSL模板(包含属性、服务和事件的定义),同步

func (*Client) LinkThingDynamictslGet

func (sf *Client) LinkThingDynamictslGet(pk, dn string, timeout time.Duration) (json.RawMessage, error)

LinkThingDynamictslGet 获取动态tsl,同步

func (*Client) LinkThingEventPost

func (sf *Client) LinkThingEventPost(pk, dn, eventID string, params interface{}, timeout time.Duration) error

LinkThingEventPost 设备事件上报,同步

func (*Client) LinkThingEventPropertyHistoryPost

func (sf *Client) LinkThingEventPropertyHistoryPost(params interface{}, timeout time.Duration) error

LinkThingEventPropertyHistoryPost 物模型历史数据上报,同步

func (*Client) LinkThingEventPropertyPackPost

func (sf *Client) LinkThingEventPropertyPackPost(params interface{}, timeout time.Duration) error

LinkThingEventPropertyPackPost 网关批量上报数据,同步

func (*Client) LinkThingEventPropertyPost

func (sf *Client) LinkThingEventPropertyPost(pk, dn string, params interface{}, timeout time.Duration) error

LinkThingEventPropertyPost 设备上报属性数据,同步

func (*Client) LinkThingListFound

func (sf *Client) LinkThingListFound(pairs []infra.MetaPair, timeout time.Duration) error

LinkThingListFound 发现设备列表上报,同步

func (*Client) LinkThingLogPost

func (sf *Client) LinkThingLogPost(pk, dn string, lp []LogParam, timeout time.Duration) error

LinkThingLogPost 设备上报日志内容,同步

func (*Client) LinkThingOtaFirmwareGet

func (sf *Client) LinkThingOtaFirmwareGet(pk, dn string,
	param OtaFirmwareParam, timeout time.Duration) (OtaFirmwareData, error)

LinkThingOtaFirmwareGet 请求固件信息,同步

func (*Client) LinkThingSubRegister

func (sf *Client) LinkThingSubRegister(pk, dn string, timeout time.Duration) ([]SubRegisterData, error)

LinkThingSubRegister 同步子设备注册,

func (*Client) LinkThingTopoAdd

func (sf *Client) LinkThingTopoAdd(pk, dn string, timeout time.Duration) error

LinkThingTopoAdd 添加设备拓扑关系,同步

func (*Client) LinkThingTopoDelete

func (sf *Client) LinkThingTopoDelete(pk, dn string, timeout time.Duration) error

LinkThingTopoDelete 删除网关与子设备的拓扑关系

func (*Client) LinkThingTopoGet

func (sf *Client) LinkThingTopoGet(timeout time.Duration) ([]infra.MetaPair, error)

LinkThingTopoGet 获取该网关和子设备的拓扑关系,同步

func (*Client) OtaInform

func (sf *Client) OtaInform(pk, dn string, params OtaInformParams) error

OtaInform 上报固件版本 request:/ota/device/inform/${YourProductKey}/${YourDeviceName}。

func (*Client) OtaProgress

func (sf *Client) OtaProgress(pk, dn string, params OtaProgressParams) error

OtaProgress 固件升级过程中,设备可以通过这个Topic上报固件升级的进度百分比 request:/ota/device/progress/${YourProductKey}/${YourDeviceName

func (*Client) RRPCResponse

func (sf *Client) RRPCResponse(pk, dn, messageID string, rsp Response) error

RRPCResponse rrcpc 回复 response: /sys/${YourProductKey}/${YourDeviceName}/rrpc/response/${messageId}

func (*Client) Request

func (sf *Client) Request(_uri string, requestID uint, method string, params interface{}) error

Request 发送请求,API内部已实现json序列化 _uri 唯一定位服务器或(topic) requestID: 请求ID method: 方法 params: 消息体Request的params

func (*Client) Response

func (sf *Client) Response(_uri string, rsp Response) error

Response 发送回复 _uri 唯一定位服务器或(topic) Response: 回复 API内部已实现json序列化

func (*Client) SendRequest

func (sf *Client) SendRequest(_uri, method string, params interface{}) (*Token, error)

SendRequest 发送请求,API内部已实现json序列化,requestID内部生成 _uri 唯一定位服务器或(topic) method: 方法 params: 消息体Request的params

func (*Client) SubDeviceConnect

func (sf *Client) SubDeviceConnect(pk, dn string, cleanSession bool, timeout time.Duration) error

SubDeviceConnect 子设备连接注册并添加到网关拓扑关系 子设备上线流程: (确保网关已接入物联网平台)

  1. 子设备发起动态注册,返回成功注册的子设备的设备证书(当平台使能动态注册子设备时)
  2. 子设备身份注册后,通过网关向平台上报网关与子设备的拓扑关系
  3. 子设备进行上线(此时平台会校验子设备的身份和与网关的拓扑关系。所有校验通过,才会建立并绑定子设备逻辑通道至网关物理通道上)
  4. 子设备与物联网平台的数据上下行通信与直连设备的通信协议一致,协议上不需要露出网关信息
  5. 删除拓扑关系后,子设备不能再通过网关上线

func (*Client) SubscribeAllTopic

func (sf *Client) SubscribeAllTopic(productKey, deviceName string, isSub bool) error

SubscribeAllTopic 对某个设备类型订阅相关所有主题

func (*Client) ThingConfigGet

func (sf *Client) ThingConfigGet(pk, dn string) (*Token, error)

ThingConfigGet 获取配置参数 request: /sys/{productKey}/{deviceName}/thing/config/get response: /sys/{productKey}/{deviceName}/thing/config/get_reply

func (*Client) ThingConfigLogGet

func (sf *Client) ThingConfigLogGet(pk, dn string, _ ConfigLogParam) (*Token, error)

ThingConfigLogGet 获取日志配置 request: /sys/${productKey}/${deviceName}/thing/config/Log/get response:/sys/${productKey}/${deviceName}/thing/config/Log/get_reply

func (*Client) ThingDesiredPropertyDelete

func (sf *Client) ThingDesiredPropertyDelete(pk, dn string, params interface{}) (*Token, error)

ThingDesiredPropertyDelete 清空期望属性值 request: /sys/{productKey}/{deviceName}/thing/property/desired/delete response: /sys/{productKey}/{deviceName}/thing/property/desired/delete_reply

func (*Client) ThingDesiredPropertyGet

func (sf *Client) ThingDesiredPropertyGet(pk, dn string, params []string) (*Token, error)

ThingDesiredPropertyGet 获取期望属性值 request: /sys/{productKey}/{deviceName}/thing/property/desired/get response: /sys/{productKey}/{deviceName}/thing/property/desired/get_reply

func (*Client) ThingDeviceInfoDelete

func (sf *Client) ThingDeviceInfoDelete(pk, dn string, params []DeviceLabelKey) (*Token, error)

ThingDeviceInfoDelete 删除标签信息 request: /sys/{productKey}/{deviceName}/thing/deviceinfo/delete response: /sys/{productKey}/{deviceName}/thing/deviceinfo/delete_reply

func (*Client) ThingDeviceInfoUpdate

func (sf *Client) ThingDeviceInfoUpdate(pk, dn string, params []DeviceInfoLabel) (*Token, error)

ThingDeviceInfoUpdate 设备信息上传(如厂商、设备型号等,可以保存为设备标签) request: /sys/{productKey}/{deviceName}/thing/deviceinfo/update response: /sys/{productKey}/{deviceName}/thing/deviceinfo/update_reply

func (*Client) ThingDiagHistoryPost

func (sf *Client) ThingDiagHistoryPost(pk, dn string, ps []P) (*Token, error)

ThingDiagHistoryPost 设备主动上报历史网络状态

func (*Client) ThingDiagPost

func (sf *Client) ThingDiagPost(pk, dn string, p P) (*Token, error)

ThingDiagPost 设备主动上报当前网络状态 request: /sys/{productKey}/{deviceName}/_thing/diag/post response: /sys/{productKey}/{deviceName}/_thing/diag/post_reply

func (*Client) ThingDsltemplateGet

func (sf *Client) ThingDsltemplateGet(pk, dn string) (*Token, error)

ThingDsltemplateGet 设备可以通过上行请求获取设备的TSL模板(包含属性、服务和事件的定义) see https://help.aliyun.com/document_detail/89305.html?spm=a2c4g.11186623.6.672.5d3d70374hpPcx request: /sys/{productKey}/{deviceName}/thing/dsltemplate/get response: /sys/{productKey}/{deviceName}/thing/dsltemplate/get_reply

func (*Client) ThingDynamictslGet

func (sf *Client) ThingDynamictslGet(pk, dn string) (*Token, error)

ThingDynamictslGet 获取动态tsl

func (*Client) ThingEventPost

func (sf *Client) ThingEventPost(pk, dn, eventID string, params interface{}) (*Token, error)

ThingEventPost 设备事件上报 request: /sys/{productKey}/{deviceName}/thing/event/{tsl.event.identifier}/post response: /sys/{productKey}/{deviceName}/thing/event/{tsl.event.identifier}/post_reply

func (*Client) ThingEventPropertyHistoryPost

func (sf *Client) ThingEventPropertyHistoryPost(params interface{}) (*Token, error)

ThingEventPropertyHistoryPost 物模型历史数据上报 直连设备仅能上报自己的物模型历史数据,网关设备可以上报其子设备的物模型历史数据 request: /sys/{productKey}/{deviceName}/thing/event/property/history/post response:/sys/{productKey}/{deviceName}/thing/event/property/history/post_reply

func (*Client) ThingEventPropertyPackPost

func (sf *Client) ThingEventPropertyPackPost(params interface{}) (*Token, error)

ThingEventPropertyPackPost 网关批量上报数据 NOTE: 仅网关支持,一次最多200个属性,20个事件,一次最多为20个子设备上报数据 request: /sys/{productKey}/{deviceName}/thing/event/property/pack/post response: /sys/{productKey}/{deviceName}/thing/event/property/pack/post_reply

func (*Client) ThingEventPropertyPost

func (sf *Client) ThingEventPropertyPost(pk, dn string, params interface{}) (*Token, error)

ThingEventPropertyPost 设备上报属性数据 request: /sys/{productKey}/{deviceName}/thing/event/property/post response: /sys/{productKey}/{deviceName}/thing/event/property/post_reply

func (*Client) ThingListFound

func (sf *Client) ThingListFound(pairs []infra.MetaPair) (*Token, error)

ThingListFound 发现设备列表上报 场景,网关可以发现新接入的子设备,发现后,需将新接入的子设备的信息上报云端, 然后转到第三方应用,选择哪些子设备可以接入该网关 request: /sys/{productKey}/{deviceName}/thing/list/found response:/sys/{productKey}/{deviceName}/thing/list/found_reply

func (*Client) ThingLogPost

func (sf *Client) ThingLogPost(pk, dn string, lp []LogParam) (*Token, error)

ThingLogPost 设备上报日志内容 request: /sys/${productKey}/${deviceName}/thing/config/Log/post response:/sys/${productKey}/${deviceName}/thing/config/Log/post_reply

func (*Client) ThingModelUpRaw

func (sf *Client) ThingModelUpRaw(pk, dn string, payload interface{}) error

ThingModelUpRaw 上传透传数据 request: /sys/{productKey}/{deviceName}/thing/model/up_raw response: /sys/{productKey}/{deviceName}/thing/model/up_raw_reply

func (*Client) ThingOtaFirmwareGet

func (sf *Client) ThingOtaFirmwareGet(pk, dn string, param OtaFirmwareParam) (*Token, error)

ThingOtaFirmwareGet 请求固件信息 module: 不指定则表示请求默认(default)模块的固件信息 request: /sys/{productKey}/{deviceName}/thing/ota/firmware/get response:/sys/{productKey}/{deviceName}/thing/ota/firmware/get_reply

func (*Client) ThingTopoGet

func (sf *Client) ThingTopoGet() (*Token, error)

ThingTopoGet 获取该网关和子设备的拓扑关系 request: /sys/{productKey}/{deviceName}/thing/topo/get response: /sys/{productKey}/{deviceName}/thing/topo/get_reply

func (*Client) URIGateway

func (sf *Client) URIGateway(prefix, name string) string

URIGateway 获得本设备网关URI

func (*Client) UnSubscribeAllTopic

func (sf *Client) UnSubscribeAllTopic(productKey, deviceName string, isSub bool) error

UnSubscribeAllTopic 取消订阅设备相关所有主题

type CombineBatchLoginParams

type CombineBatchLoginParams struct {
	DeviceList []CombineLoginParams `json:"deviceList"`
}

CombineBatchLoginParams 子设备上线请求参数域

type CombineBatchLoginResponse

type CombineBatchLoginResponse struct {
	ID      uint             `json:"id,string"`
	Code    int              `json:"code"`
	Data    []infra.MetaPair `json:"data"`
	Message string           `json:"message,omitempty"`
}

CombineBatchLoginResponse 子设备批量上线回复

type CombineBatchLogoutResponse

type CombineBatchLogoutResponse struct {
	ID      uint             `json:"id,string"`
	Code    int              `json:"code"`
	Data    []infra.MetaPair `json:"data"`
	Message string           `json:"message,omitempty"`
}

CombineBatchLogoutResponse 子设备批量下线回复

type CombineLoginParams

type CombineLoginParams struct {
	ProductKey string `json:"productKey"`       // 子设备的产品key
	DeviceName string `json:"deviceName"`       // 子设备的设备名称
	ClientID   string `json:"clientId"`         // 设备端标识
	Timestamp  int64  `json:"timestamp,string"` // 时间戳,单位ms
	SignMethod string `json:"signMethod"`       // 签名方法,支持hmacSha1、hmacSha256、hmacMd5和Sha256。
	Sign       string `json:"sign"`
	// 如果取值是true,则清理所有子设备离线时的消息,即所有未接收的QoS1消息将被清除。
	// 如果取值是false,则不清理子设备离线时的消息
	CleanSession bool `json:"cleanSession,string"`
}

CombineLoginParams 子设备上线参数域

type CombineLoginResponse

type CombineLoginResponse struct {
	ID      uint           `json:"id,string"`
	Code    int            `json:"code"`
	Data    infra.MetaPair `json:"data"`
	Message string         `json:"message,omitempty"`
}

CombineLoginResponse 子设备上线回复

type CombineLogoutResponse

type CombineLogoutResponse struct {
	ID      uint           `json:"id,string"`
	Code    int            `json:"code"`
	Data    infra.MetaPair `json:"data"`
	Message string         `json:"message,omitempty"`
}

CombineLogoutResponse 子设备上线回复

type CombinePair

type CombinePair struct {
	ProductKey   string
	DeviceName   string
	CleanSession bool
}

CombinePair combine pair

type ConfigGetParams

type ConfigGetParams struct {
	ConfigScope string `json:"configScope"` // 配置范围, 目前只支持产品维度配置. 取值: product
	GetType     string `json:"getType"`     // 获取配置类型. 目前支持文件类型,取值: file
}

ConfigGetParams 获取配置的参数域

type ConfigGetResponse

type ConfigGetResponse struct {
	ID      uint             `json:"id,string"`
	Code    int              `json:"code"`
	Data    ConfigParamsData `json:"data"`
	Message string           `json:"message,omitempty"`
}

ConfigGetResponse 配置获取的回复

type ConfigLogMode

type ConfigLogMode struct {
	Mode int `json:"mode"` // 0 表示不上报, 1 表示上报
}

ConfigLogMode 日志配置的日志上报模式

type ConfigLogParam

type ConfigLogParam struct {
	// 配置范围,目前日志只有设备维度配置,默认为device
	ConfigScope string `json:"configScope"`
	// 获取内容类型,默认为content.因日志配置内容较少,默认直接返回内容
	GetType string `json:"getType"`
}

ConfigLogParam 设备获取日志配置参数域

type ConfigLogParamData

type ConfigLogParamData struct {
	GetType string        `json:"getType"`
	Content ConfigLogMode `json:"content"`
}

ConfigLogParamData 日志配置的参数域或配置域

type ConfigLogPush

type ConfigLogPush struct {
	ID      uint               `json:"id,string"`
	Version string             `json:"version"`
	Params  ConfigLogParamData `json:"params"`
}

ConfigLogPush 日志配置推送

type ConfigLogResponse

type ConfigLogResponse struct {
	ID      uint               `json:"id,string"`
	Code    int                `json:"code"`
	Data    ConfigLogParamData `json:"data"`
	Message string             `json:"message,omitempty"`
}

ConfigLogResponse 日志配置回复

type ConfigParamsData

type ConfigParamsData struct {
	ConfigID   string `json:"configId"`   // 配置文件的ID
	ConfigSize int64  `json:"configSize"` // 配置文件大小,按字节计算
	Sign       string `json:"sign"`       // 签名
	SignMethod string `json:"signMethod"` // 签名方法,仅支持Sha256
	URL        string `json:"url"`        // 存储配置文件的对象存储(OSS)地址
	GetType    string `json:"getType"`    // 同ConfigGetParams.GetType
}

ConfigParamsData 配置获取回复数据域或配置推送参数域

type ConfigPushRequest

type ConfigPushRequest struct {
	ID      uint             `json:"id,string"`
	Version string           `json:"version"`
	Params  ConfigParamsData `json:"params"`
	Method  string           `json:"method"`
}

ConfigPushRequest 配置推送的请求

type Conn

type Conn interface {
	// Publish will publish a Message with the specified QoS and content
	Publish(topic string, qos byte, payload interface{}) error
	Subscribe(topic string, callback ProcDownStream) error
	UnSubscribe(topic ...string) error
	io.Closer
}

Conn conn接口

type DevMgr

type DevMgr struct {
	// contains filtered or unexported fields
}

DevMgr 设备管理

func NewDevMgr

func NewDevMgr(root infra.MetaTriad) *DevMgr

NewDevMgr 设备管理是一个线程安全 root: 网关设备

func (*DevMgr) Add

func (sf *DevMgr) Add(meta infra.MetaTriad) error

Add 增加一个子设备,子设备处于 DevStatusUnauthorized

func (*DevMgr) Delete

func (sf *DevMgr) Delete(pk, dn string)

Delete 删除一个子设备

func (*DevMgr) DeviceAvail

func (sf *DevMgr) DeviceAvail(pk, dn string) (bool, error)

DeviceAvail 获取avail

func (*DevMgr) DeviceSecret

func (sf *DevMgr) DeviceSecret(pk, dn string) (string, error)

DeviceSecret 设备DeviceSecret

func (*DevMgr) DeviceStatus

func (sf *DevMgr) DeviceStatus(pk, dn string, status DevStatus) error

DeviceStatus 获取设备的状态

func (*DevMgr) IsActive

func (sf *DevMgr) IsActive(pk, dn string) bool

IsActive productKey deviceName的设备已使能且是否在线

func (*DevMgr) Len

func (sf *DevMgr) Len() int

Len 设备个数,含root设备

func (*DevMgr) Search

func (sf *DevMgr) Search(pk, dn string) (*DevNode, error)

Search 使用productKey deviceName查找一个设备节点信息

func (*DevMgr) SearchAvail

func (sf *DevMgr) SearchAvail(pk, dn string) (*DevNode, error)

SearchAvail 使用productKey deviceName查找一个设备节点信息且avail = true 如果设备avail=false返回ErrNotAvail

func (*DevMgr) SetDeviceAvail

func (sf *DevMgr) SetDeviceAvail(pk, dn string, enable bool) error

SetDeviceAvail 设置avail

func (*DevMgr) SetDeviceSecret

func (sf *DevMgr) SetDeviceSecret(pk, dn, ds string) error

SetDeviceSecret 设置设备的密钥

func (*DevMgr) SetDeviceStatus

func (sf *DevMgr) SetDeviceStatus(pk, dn string, status DevStatus) error

SetDeviceStatus 设置设备的状态

type DevNode

type DevNode struct {
	// contains filtered or unexported fields
}

DevNode 设备节点

func (*DevNode) Avail

func (sf *DevNode) Avail() bool

Avail 返回设备avail

func (*DevNode) DeviceName

func (sf *DevNode) DeviceName() string

DeviceName 获得DeviceName

func (*DevNode) DeviceSecret

func (sf *DevNode) DeviceSecret() string

DeviceSecret 获得DeviceSecret

func (*DevNode) Extend

func (sf *DevNode) Extend() interface{}

Extend 获得扩展参数值

func (*DevNode) ProductKey

func (sf *DevNode) ProductKey() string

ProductKey 获得productKey

func (*DevNode) Status

func (sf *DevNode) Status() DevStatus

Status 返回设备状态

type DevStatus

type DevStatus byte

DevStatus 设备状态

const (
	DevStatusUnauthorized DevStatus = iota // Subdev Created
	DevStatusAuthorized                    // Receive Topo Add Notify
	DevStatusRegistered                    // Receive Subdev Registered
	DevStatusAttached                      // Receive Subdev Topo Add Reply
	DevStatusLogined                       // Receive Subdev Login Reply
	DevStatusOnline                        // After All Topic Subscribed
)

设备状态

type DeviceInfoLabel

type DeviceInfoLabel struct {
	AttrKey   string `json:"attrKey"`
	AttrValue string `json:"attrValue"`
}

DeviceInfoLabel 更新设备标签的键值对

type DeviceLabelKey

type DeviceLabelKey struct {
	AttrKey string `json:"attrKey"`
}

DeviceLabelKey 删除设备标答的键

type DiagParam

type DiagParam struct {
	P interface{} `json:"p"`
	// format:数据格式.仅支持simple,表示数据为精简格式。
	// quantity:数量。取值:
	//      single:表示上报单条数据。
	//      batch:表示上报多条数据,仅用于上报历史数据。
	// time:时间.取值:
	//      now: 表示上报当前数据。
	//      history: 表示上报历史数据
	Model string `json:"model"`
}

DiagParam diag参数域

type DiagRequest

type DiagRequest struct {
	ID      uint      `json:"id,string"`
	Version string    `json:"version"`
	Params  DiagParam `json:"params"`
}

DiagRequest 设备主动上报网络状态请求

type ExtErrorResponse

type ExtErrorResponse struct {
	ID      uint           `json:"id,string"`
	Code    int            `json:"code"`
	Data    infra.MetaPair `json:"data"`
	Message string         `json:"message,omitempty"`
}

ExtErrorResponse 子设备错误回复

type GwCallback

type GwCallback interface {
	// 520错误已做自动登陆回复
	ExtErrorResponse(c *Client, err error, productKey, deviceName string) error
	ThingTopoGetReply(c *Client, err error, params []infra.MetaPair) error
	ThingListFoundReply(c *Client, err error) error
	ThingTopoAddNotify(c *Client, params []infra.MetaPair) error
	ThingTopoChange(c *Client, params TopoChangeParams) error
	ThingDisable(c *Client, productKey, deviceName string) error
	ThingEnable(c *Client, productKey, deviceName string) error
	ThingDelete(c *Client, productKey, deviceName string) error
}

GwCallback 网关事件接口

type LogParam

type LogParam struct {
	// 日志的采集时间,为设备本地UTC时间,
	// 包含时区信息,以毫秒计,格式为 yyyy-MM-dd'T'HH:mm:ss.SSSZ
	UtcTime string `json:"utcTime"`
	// FATAL,ERROR,WARN,INFO,DEBUG
	LogLevel string `json:"logLevel"`
	// 当设备端使用Android SDK时,模块名称为ALK-LK.
	// 当设备端使用C SDK时,需自定义模块名称.
	// 当设备端使用自行开发的SDK时,需自定义模块名称
	Module string `json:"module"`
	// 当设备端使用Android SDK时,请参见Android SDK错误码.
	// 当设备端使用C SDK时,请参见C SDK状态码.
	// 当设备端使用自行开发的SDK时,可以自定义结果状态码,也可以为空.
	Code string `json:"code"`
	// 可选参数,上下文跟踪内容,设备端使用Alink协议消息的id,App端使用TraceId(追踪ID)
	TraceContext string `json:"traceContext,omitempty"`
	// 日志详细内容
	LogContent string `json:"logContent"`
}

LogParam 日志内容参数域

type MQTTClient

type MQTTClient struct {
	*Client
	// contains filtered or unexported fields
}

MQTTClient MQTT客户端

func NewWithMQTT

func NewWithMQTT(meta infra.MetaTriad, c mqtt.Client, opts ...Option) *MQTTClient

NewWithMQTT 新建MQTTClient

func (*MQTTClient) Close

func (sf *MQTTClient) Close() error

Close 实现dm.Conn接口

func (*MQTTClient) Publish

func (sf *MQTTClient) Publish(topic string, qos byte, payload interface{}) error

Publish 实现dm.Conn接口

func (*MQTTClient) Subscribe

func (sf *MQTTClient) Subscribe(topic string, streamFunc ProcDownStream) error

Subscribe 实现dm.Conn接口

func (*MQTTClient) UnSubscribe

func (sf *MQTTClient) UnSubscribe(topic ...string) error

UnSubscribe 实现dm.Conn接口

func (*MQTTClient) Underlying

func (sf *MQTTClient) Underlying() mqtt.Client

Underlying 获得底层的Client

type Message

type Message struct {
	ID   uint
	Data interface{}
	// contains filtered or unexported fields
}

Message 回复的消息

type Mode

type Mode byte

Mode 工作模式

const (
	ModeMQTT Mode = iota
	ModeCOAP
	ModeHTTP
)

当前的工作模式

type NopCb

type NopCb struct{}

NopCb 实现Callback接口的空实现

func (NopCb) ExtNtpResponse

func (NopCb) ExtNtpResponse(*Client, string, string, time.Time) error

ExtNtpResponse see interface Callback

func (NopCb) ExtRRPCRequest

func (NopCb) ExtRRPCRequest(*Client, string, string, []byte) error

ExtRRPCRequest see interface Callback

func (NopCb) OtaUpgrade

OtaUpgrade see interface Callback

func (NopCb) RRPCRequest

func (NopCb) RRPCRequest(*Client, string, string, string, []byte) error

RRPCRequest see interface Callback

func (NopCb) ThingConfigGetReply

func (NopCb) ThingConfigGetReply(*Client, error, string, string, ConfigParamsData) error

ThingConfigGetReply see interface Callback

func (NopCb) ThingConfigLogGetReply

func (NopCb) ThingConfigLogGetReply(*Client, error, string, string, ConfigLogParamData) error

ThingConfigLogGetReply see interface Callback

func (NopCb) ThingConfigLogPush

func (NopCb) ThingConfigLogPush(*Client, string, string, ConfigLogParamData) error

ThingConfigLogPush see interface Callback

func (NopCb) ThingConfigPush

func (NopCb) ThingConfigPush(*Client, string, string, ConfigParamsData) error

ThingConfigPush see interface Callback

func (NopCb) ThingDesiredPropertyDeleteReply

func (NopCb) ThingDesiredPropertyDeleteReply(*Client, error, string, string) error

ThingDesiredPropertyDeleteReply see interface Callback

func (NopCb) ThingDesiredPropertyGetReply

func (NopCb) ThingDesiredPropertyGetReply(*Client, error, string, string, json.RawMessage) error

ThingDesiredPropertyGetReply see interface Callback

func (NopCb) ThingDeviceInfoDeleteReply

func (NopCb) ThingDeviceInfoDeleteReply(*Client, error, string, string) error

ThingDeviceInfoDeleteReply see interface Callback

func (NopCb) ThingDeviceInfoUpdateReply

func (NopCb) ThingDeviceInfoUpdateReply(*Client, error, string, string) error

ThingDeviceInfoUpdateReply see interface Callback

func (NopCb) ThingDialPostReply

func (NopCb) ThingDialPostReply(*Client, error, string, string) error

ThingDialPostReply see interface Callback

func (NopCb) ThingDsltemplateGetReply

func (NopCb) ThingDsltemplateGetReply(*Client, error, string, string, json.RawMessage) error

ThingDsltemplateGetReply see interface Callback

func (NopCb) ThingDynamictslGetReply

func (NopCb) ThingDynamictslGetReply(*Client, error, string, string, json.RawMessage) error

ThingDynamictslGetReply see interface Callback

func (NopCb) ThingEventPostReply

func (NopCb) ThingEventPostReply(*Client, error, string, string, string) error

ThingEventPostReply see interface Callback

func (NopCb) ThingEventPropertyHistoryPostReply

func (NopCb) ThingEventPropertyHistoryPostReply(*Client, error, string, string) error

ThingEventPropertyHistoryPostReply see interface Callback

func (NopCb) ThingEventPropertyPackPostReply

func (NopCb) ThingEventPropertyPackPostReply(*Client, error, string, string) error

ThingEventPropertyPackPostReply see interface Callback

func (NopCb) ThingEventPropertyPostReply

func (NopCb) ThingEventPropertyPostReply(*Client, error, string, string) error

ThingEventPropertyPostReply see interface Callback

func (NopCb) ThingLogPostReply

func (NopCb) ThingLogPostReply(*Client, error, string, string) error

ThingLogPostReply see interface Callback

func (NopCb) ThingModelDownRaw

func (NopCb) ThingModelDownRaw(*Client, string, string, []byte) error

ThingModelDownRaw see interface Callback

func (NopCb) ThingModelUpRawReply

func (NopCb) ThingModelUpRawReply(*Client, string, string, []byte) error

ThingModelUpRawReply see interface Callback

func (NopCb) ThingOtaFirmwareGetReply

func (NopCb) ThingOtaFirmwareGetReply(*Client, string, string, OtaFirmwareData) error

ThingOtaFirmwareGetReply see interface Callback

func (NopCb) ThingServicePropertySet

func (NopCb) ThingServicePropertySet(*Client, string, string, []byte) error

ThingServicePropertySet see interface Callback

func (NopCb) ThingServiceRequest

func (NopCb) ThingServiceRequest(*Client, string, string, string, []byte) error

ThingServiceRequest see interface Callback

type NopGwCb

type NopGwCb struct{}

NopGwCb 实现EventGwProc接口的空实现

func (NopGwCb) ExtErrorResponse

func (NopGwCb) ExtErrorResponse(*Client, error, string, string) error

ExtErrorResponse see interface GwCallback

func (NopGwCb) ThingDelete

func (NopGwCb) ThingDelete(*Client, string, string) error

ThingDelete see interface GwCallback

func (NopGwCb) ThingDisable

func (NopGwCb) ThingDisable(*Client, string, string) error

ThingDisable see interface GwCallback

func (NopGwCb) ThingEnable

func (NopGwCb) ThingEnable(*Client, string, string) error

ThingEnable see interface GwCallback

func (NopGwCb) ThingListFoundReply

func (NopGwCb) ThingListFoundReply(*Client, error) error

ThingListFoundReply see interface GwCallback

func (NopGwCb) ThingTopoAddNotify

func (NopGwCb) ThingTopoAddNotify(*Client, []infra.MetaPair) error

ThingTopoAddNotify see interface GwCallback

func (NopGwCb) ThingTopoChange

func (NopGwCb) ThingTopoChange(*Client, TopoChangeParams) error

ThingTopoChange see interface GwCallback

func (NopGwCb) ThingTopoGetReply

func (NopGwCb) ThingTopoGetReply(*Client, error, []infra.MetaPair) error

ThingTopoGetReply see interface GwCallback

type NtpRequest

type NtpRequest struct {
	DeviceSendTime int64 `json:"deviceSendTime,string"`
}

NtpRequest ntp请求payload

type NtpResponse

type NtpResponse struct {
	DeviceSendTime int64 `json:"deviceSendTime,string"` // 设备发送时间,单位ms
	ServerRecvTime int64 `json:"serverRecvTime,string"` // 平台接收时间,单位ms
	ServerSendTime int64 `json:"serverSendTime,string"` // 平台发送时间,单位ms
}

NtpResponse ntp回复payload

type Option

type Option func(*Client)

Option 配置选项

func WithCache

func WithCache(expiration, cleanupInterval time.Duration) Option

WithCache 设备消息缓存超时时间

func WithCallback

func WithCallback(cb Callback) Option

WithCallback 设置事件处理接口

func WithEnableDesired

func WithEnableDesired() Option

WithEnableDesired 使能期望属性

func WithEnableDiag

func WithEnableDiag() Option

WithEnableDiag 使能diag功能

func WithEnableExtRRPC

func WithEnableExtRRPC() Option

WithEnableExtRRPC 使能扩展RRPC功能

func WithEnableGateway

func WithEnableGateway() Option

WithEnableGateway 使能网关功能

func WithEnableModelRaw

func WithEnableModelRaw() Option

WithEnableModelRaw 使能透传

func WithEnableNTP

func WithEnableNTP() Option

WithEnableNTP 使能NTP

func WithEnableOTA

func WithEnableOTA() Option

WithEnableOTA 使能ota功能

func WithGwCallback

func WithGwCallback(cb GwCallback) Option

WithGwCallback 设备网关事件接口

func WithLogger

func WithLogger(l logger.Logger) Option

WithLogger 设置日志

func WithMode

func WithMode(m Mode) Option

WithMode 设置工作模式 支持 ModeCOAP ,ModeHTTP, ModeMQTT(默认)

func WithVersion

func WithVersion(ver string) Option

WithVersion 设置平台版本,默认为 DefaultVersion

type OtaFirmwareData

type OtaFirmwareData struct {
	Size       int64  `json:"size"`
	Sign       string `json:"sign"`
	Version    string `json:"version"`
	IsDiff     int    `json:"isDiff"`
	URL        string `json:"url"`
	SignMethod string `json:"signMethod"`
	MD5        string `json:"md5"`
	Module     string `json:"module"`
}

OtaFirmwareData 请求固件信息回复数据域

type OtaFirmwareParam

type OtaFirmwareParam struct {
	Module string `json:"module"`
}

OtaFirmwareParam 请求固件信息参数域

type OtaFirmwareResponse

type OtaFirmwareResponse struct {
	ID      uint            `json:"id,string"`
	Code    int             `json:"code"`
	Data    OtaFirmwareData `json:"data"`
	Message string          `json:"message"`
}

OtaFirmwareResponse ota firmware response

type OtaInformParams

type OtaInformParams struct {
	Version string `json:"version"`
	// 上报默认(default)模块的固件版本号时,可以不上报module参数.
	// 设备的默认(default)模块的固件版本号等同于整个设备的固件版本号.
	Module string `json:"module"`
}

OtaInformParams OTA固件参数域

type OtaProgressParams

type OtaProgressParams struct {
	Step   int    `json:"step,string"` // 固件升级进度信息 [1,100] 之间的数字:表示升级进度百分比,其它见上
	Desc   string `json:"desc"`
	Module string `json:"module"`
}

OtaProgressParams 下载过程上报参数域

type OtaRequest

type OtaRequest struct {
	ID     uint        `json:"id,string"`
	Params interface{} `json:"params"`
}

OtaRequest OTA请求体

type P

type P struct {
	Wifi Wifi  `json:"wifi"`  // 设备的连网方式为Wi-Fi,该参数值由网络状态的四个指标组成
	Time int64 `json:"_time"` // 时间戳可以为空,当为空时,控制台上设备网络状态不展现采集时间,单位ms
}

P 包含wifi状态和时间戳

type ProcDownStream

type ProcDownStream func(c *Client, rawURI string, payload []byte) error

ProcDownStream 处理下行数据

type Request

type Request struct {
	ID      uint        `json:"id,string"`
	Version string      `json:"version"`
	Params  interface{} `json:"params"`
	Method  string      `json:"method"`
}

Request 请求

type Response

type Response struct {
	ID      uint        `json:"id,string"`
	Code    int         `json:"code"`
	Data    interface{} `json:"data"`
	Message string      `json:"message,omitempty"`
}

Response 应答

type ResponseRawData

type ResponseRawData struct {
	ID      uint            `json:"id,string"`
	Code    int             `json:"code"`
	Data    json.RawMessage `json:"data"`
	Message string          `json:"message,omitempty"`
}

ResponseRawData 应答, data域为 json.RawMessage

type SubRegisterData

type SubRegisterData struct {
	IotID        string `json:"iotId"`
	ProductKey   string `json:"productKey"`
	DeviceName   string `json:"deviceName"`
	DeviceSecret string `json:"deviceSecret"`
}

SubRegisterData 子设备注册应答数据域

type SubRegisterResponse

type SubRegisterResponse struct {
	ID      uint              `json:"id,string"`
	Code    int               `json:"code"`
	Data    []SubRegisterData `json:"data"`
	Message string            `json:"message,omitempty"`
}

SubRegisterResponse 子设备注册应答

type Token

type Token struct {
	// contains filtered or unexported fields
}

Token defines the interface for the tokens used to indicate when actions have completed.

func (*Token) Wait

func (sf *Token) Wait(timeout time.Duration) (m Message, err error)

Wait the entry response,return ID,Data and error

type TopoAddNotifyRequest

type TopoAddNotifyRequest struct {
	ID      uint             `json:"id,string"`
	Version string           `json:"version"`
	Params  []infra.MetaPair `json:"params"`
	Method  string           `json:"method"`
}

TopoAddNotifyRequest 添加设备拓扑关系通知请求

type TopoAddParams

type TopoAddParams struct {
	ProductKey string `json:"productKey"`
	DeviceName string `json:"deviceName"`
	ClientID   string `json:"clientId"`
	Timestamp  int64  `json:"timestamp,string"` // 时间戳
	SignMethod string `json:"signmethod"`       // 支持hmacsha1、hmacsha256、hmacmd5、sha256(not used)
	Sign       string `json:"sign"`
}

TopoAddParams 添加设备拓扑关系参数域

type TopoAddResponse

type TopoAddResponse struct {
	ID      uint             `json:"id,string"`
	Code    int              `json:"code"`
	Data    []infra.MetaPair `json:"Data"`
	Message string           `json:"message,omitempty"`
}

TopoAddResponse 添加网络拓扑应答

type TopoChangeParams

type TopoChangeParams struct {
	Status  int              `json:"status"` // 0: 创建 1:删除 2: 启用 8: 禁用
	SubList []infra.MetaPair `json:"subList"`
}

TopoChangeParams 网络拓扑关系变化请求参数域

type TopoChangeRequest

type TopoChangeRequest struct {
	ID      uint             `json:"id,string"`
	Version string           `json:"version"`
	Params  TopoChangeParams `json:"params"`
	Method  string           `json:"method"`
}

TopoChangeRequest 网络拓扑关系变化请求

type TopoDeleteResponse

type TopoDeleteResponse struct {
	ID      uint             `json:"id,string"`
	Code    int              `json:"code"`
	Data    []infra.MetaPair `json:"Data"`
	Message string           `json:"message,omitempty"`
}

TopoDeleteResponse 删除网络拓扑应答

type TopoGetResponse

type TopoGetResponse struct {
	ID      uint             `json:"id,string"`
	Code    int              `json:"code"`
	Data    []infra.MetaPair `json:"Data"`
	Message string           `json:"message,omitempty"`
}

TopoGetResponse 获取网关和子设备的拓扑关系应答

type Wifi

type Wifi struct {
	Rssi int `json:"rssi"` // 无线信号接收强度
	Snr  int `json:"snr"`  // 无线信号信噪比
	Per  int `json:"per"`  // 数据丢包率
	// 错误信息。仅当设备检测到网络异常后,上报数据包含该参数。
	// 格式:"type,code,count;type,code,count"
	// type:  错误类型
	// code:  错误原因
	// count: 错误数量
	// @see https://help.aliyun.com/document_detail/140585.html?spm=a2c4g.11186623.6.715.36f1791fcf3FJI#table-fvv-k8u-som
	ErrStats string `json:"err_stats"`
}

Wifi wifi status

Directories

Path Synopsis
_examples
Package ahttp 实现http client 上传数据.
Package ahttp 实现http client 上传数据.
Package dataflow 阿里云iot服务器订阅数据流 Package dataflow 定义数据流转的数据格式 实现iot转发的解析以及相关 客户端将获得一个messageBody,解析到message, payload承载着真实的dataflow数据流 根据不同的主题,解析不同的payload,see https://help.aliyun.com/document_detail/73736.html?spm=a2c4g.11186623.6.630.1ce25a10TgnylI
Package dataflow 阿里云iot服务器订阅数据流 Package dataflow 定义数据流转的数据格式 实现iot转发的解析以及相关 客户端将获得一个messageBody,解析到message, payload承载着真实的dataflow数据流 根据不同的主题,解析不同的payload,see https://help.aliyun.com/document_detail/73736.html?spm=a2c4g.11186623.6.630.1ce25a10TgnylI
Package dynamic 实现动态注册,只限直连设备动态注册,阿里云目前限制激活过的设备不可再注册
Package dynamic 实现动态注册,只限直连设备动态注册,阿里云目前限制激活过的设备不可再注册
Package sign 实现MQTT设备签名 see https://help.aliyun.com/document_detail/73742.html?spm=a2c4g.11186623.6.599.76216eebzbvrYq
Package sign 实现MQTT设备签名 see https://help.aliyun.com/document_detail/73742.html?spm=a2c4g.11186623.6.599.76216eebzbvrYq

Jump to

Keyboard shortcuts

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