Documentation ¶
Index ¶
- Constants
- func CreateAsyncIotDevice(id, password, servers string) *asyncDevice
- func CreateAsyncIotDeviceWitConfig(config DeviceConfig) *asyncDevice
- func CreateAsyncIotDeviceWithQos(id, password, servers string, qos byte) *asyncDevice
- func CreateMqttClientId(deviceId string) string
- func GetEventTimeStamp() string
- func Interface2JsonString(v interface{}) string
- func OsName() string
- func SdkInfo() map[string]string
- type AsyncDevice
- type AsyncGateway
- type AsyncResult
- type BaseDevice
- type BaseServiceEvent
- type BooleanAsyncResult
- type BootstrapClient
- type Command
- type CommandHandler
- type CommandResponse
- type Data
- type DataEntry
- type Device
- type DeviceCommandLogCollector
- type DeviceConfig
- type DeviceError
- type DeviceInfo
- type DeviceLogEntry
- type DeviceMessageLogCollector
- type DeviceProperties
- type DevicePropertiesSetHandler
- type DevicePropertyDownRequest
- type DevicePropertyDownRequestEntry
- type DevicePropertyEntry
- type DevicePropertyLogCollector
- type DevicePropertyQueryHandler
- type DevicePropertyQueryRequest
- type DevicePropertyQueryResponse
- type DevicePropertyQueryResponseHandler
- type DeviceService
- type DeviceShadowData
- type DeviceShadowPropertiesData
- type DeviceStatus
- type DeviceStatusLogCollector
- type DeviceUpgradeHandler
- type DevicesService
- type FileRequest
- type FileRequestServiceEvent
- type FileRequestServiceEventParas
- type FileResponse
- type FileResponseServiceEvent
- type FileResponseServiceEventParas
- type FileResultResponse
- type FileResultResponseServiceEvent
- type FileResultServiceEventParas
- type Gateway
- type HttpClient
- type HttpDevice
- type HttpDeviceConfig
- type LogCollectionConfig
- type Message
- type MessageHandler
- type ReportDeviceInfoEventParas
- type ReportDeviceInfoRequest
- type ReportDeviceInfoServiceEvent
- type ReportDeviceLogRequest
- type ReportDeviceLogServiceEvent
- type Result
- type SubDeviceInfo
- type SubDevicesAddHandler
- type SubDevicesDeleteHandler
- type SubDevicesStatus
- type SwFwVersionReporter
- type UpgradeInfo
- type UpgradeProgress
Constants ¶
const ( // MessageDownTopic 平台下发消息topic MessageDownTopic string = "$oc/devices/{device_id}/sys/messages/down" // MessageUpTopic 设备上报消息topic MessageUpTopic string = "$oc/devices/{device_id}/sys/messages/up" // CommandDownTopic 平台下发命令topic CommandDownTopic string = "$oc/devices/{device_id}/sys/commands/#" // CommandResponseTopic 设备响应平台命令 CommandResponseTopic string = "$oc/devices/{device_id}/sys/commands/response/request_id=" // PropertiesUpTopic 设备上报属性 PropertiesUpTopic string = "$oc/devices/{device_id}/sys/properties/report" // PropertiesSetRequestTopic 平台设置属性topic PropertiesSetRequestTopic string = "$oc/devices/{device_id}/sys/properties/set/#" // PropertiesSetResponseTopic 设备响应平台属性设置topic PropertiesSetResponseTopic string = "$oc/devices/{device_id}/sys/properties/set/response/request_id=" // PropertiesQueryRequestTopic 平台查询设备属性 PropertiesQueryRequestTopic string = "$oc/devices/{device_id}/sys/properties/get/#" // PropertiesQueryResponseTopic 设备响应平台属性查询 PropertiesQueryResponseTopic string = "$oc/devices/{device_id}/sys/properties/get/response/request_id=" // DeviceShadowQueryRequestTopic 设备侧获取平台的设备影子数据 DeviceShadowQueryRequestTopic string = "$oc/devices/{device_id}/sys/shadow/get/request_id=" // DeviceShadowQueryResponseTopic 设备侧响应获取平台设备影子 DeviceShadowQueryResponseTopic string = "$oc/devices/{device_id}/sys/shadow/get/response/#" // GatewayBatchReportSubDeviceTopic 网关批量上报子设备属性 GatewayBatchReportSubDeviceTopic string = "$oc/devices/{device_id}/sys/gateway/sub_devices/properties/report" // FileActionUpload 平台下发文件上传和下载URL FileActionUpload string = "upload" FileActionDownload string = "download" // DeviceToPlatformTopic 设备或网关向平台发送请求 DeviceToPlatformTopic string = "$oc/devices/{device_id}/sys/events/up" // PlatformEventToDeviceTopic 平台向设备下发事件topic PlatformEventToDeviceTopic string = "$oc/devices/{device_id}/sys/events/down" )
const ( AuthTypePassword uint8 = 0 AuthTypeX509 uint8 = 1 )
Variables ¶
This section is empty.
Functions ¶
func CreateAsyncIotDevice ¶ added in v1.0.0
func CreateAsyncIotDevice(id, password, servers string) *asyncDevice
func CreateAsyncIotDeviceWitConfig ¶ added in v1.0.0
func CreateAsyncIotDeviceWitConfig(config DeviceConfig) *asyncDevice
func CreateAsyncIotDeviceWithQos ¶ added in v1.0.0
func CreateMqttClientId ¶ added in v1.0.2
func GetEventTimeStamp ¶ added in v0.0.2
func GetEventTimeStamp() string
设备采集数据UTC时间(格式:yyyyMMdd'T'HHmmss'Z'),如:20161219T114920Z。 设备上报数据不带该参数或参数格式错误时,则数据上报时间以平台时间为准。
func Interface2JsonString ¶
func Interface2JsonString(v interface{}) string
Types ¶
type AsyncDevice ¶ added in v1.0.0
type AsyncDevice interface { BaseDevice AsyncGateway SendMessage(message Message) AsyncResult ReportProperties(properties DeviceProperties) AsyncResult BatchReportSubDevicesProperties(service DevicesService) AsyncResult QueryDeviceShadow(query DevicePropertyQueryRequest, handler DevicePropertyQueryResponseHandler) AsyncResult UploadFile(filename string) AsyncResult DownloadFile(filename string) AsyncResult ReportDeviceInfo(swVersion, fwVersion string) AsyncResult ReportLogs(logs []DeviceLogEntry) AsyncResult }
type AsyncGateway ¶ added in v1.0.0
type AsyncGateway interface { // 网关更新子设备状态 UpdateSubDeviceState(subDevicesStatus SubDevicesStatus) AsyncResult // 网关删除子设备 DeleteSubDevices(deviceIds []string) AsyncResult // 网关添加子设备 AddSubDevices(deviceInfos []DeviceInfo) AsyncResult // 网关同步子设备列表,默认实现不指定版本 SyncAllVersionSubDevices() AsyncResult // 网关同步特定版本子设备列表 SyncSubDevices(version int) AsyncResult // contains filtered or unexported methods }
type AsyncResult ¶ added in v1.0.0
type BaseDevice ¶ added in v1.0.0
type BaseDevice interface { Init() bool DisConnect() IsConnected() bool AddMessageHandler(handler MessageHandler) AddCommandHandler(handler CommandHandler) AddPropertiesSetHandler(handler DevicePropertiesSetHandler) SetPropertyQueryHandler(handler DevicePropertyQueryHandler) SetSwFwVersionReporter(handler SwFwVersionReporter) SetDeviceUpgradeHandler(handler DeviceUpgradeHandler) SetDeviceStatusLogCollector(collector DeviceStatusLogCollector) SetDevicePropertyLogCollector(collector DevicePropertyLogCollector) SetDeviceMessageLogCollector(collector DeviceMessageLogCollector) SetDeviceCommandLogCollector(collector DeviceCommandLogCollector) }
type BaseServiceEvent ¶ added in v0.0.2
type BooleanAsyncResult ¶ added in v1.0.0
type BooleanAsyncResult struct {
// contains filtered or unexported fields
}
func NewBooleanAsyncResult ¶ added in v1.0.0
func NewBooleanAsyncResult() *BooleanAsyncResult
func (*BooleanAsyncResult) Done ¶ added in v1.0.0
func (b *BooleanAsyncResult) Done() <-chan struct{}
Done implements the Token Done method.
func (*BooleanAsyncResult) Result ¶ added in v1.0.0
func (bar *BooleanAsyncResult) Result() bool
func (*BooleanAsyncResult) Wait ¶ added in v1.0.0
func (b *BooleanAsyncResult) Wait() bool
Wait implements the Token Wait method.
func (*BooleanAsyncResult) WaitTimeout ¶ added in v1.0.0
WaitTimeout implements the Token WaitTimeout method.
type BootstrapClient ¶ added in v1.0.2
type BootstrapClient interface { Boot() string Close() }
func NewBootstrapClient ¶ added in v1.0.2
func NewBootstrapClient(id, password string) (BootstrapClient, error)
type Command ¶
type Command struct { ObjectDeviceId string `json:"object_device_id"` ServiceId string `json:"service_id""` CommandName string `json:"command_name"` Paras interface{} `json:"paras"` }
设备命令
type CommandResponse ¶
type Device ¶
type Device interface { BaseDevice Gateway SendMessage(message Message) bool ReportProperties(properties DeviceProperties) bool BatchReportSubDevicesProperties(service DevicesService) bool QueryDeviceShadow(query DevicePropertyQueryRequest, handler DevicePropertyQueryResponseHandler) UploadFile(filename string) bool DownloadFile(filename string) bool ReportDeviceInfo(swVersion, fwVersion string) ReportLogs(logs []DeviceLogEntry) bool }
func CreateIotDevice ¶
func CreateIotDeviceWitConfig ¶ added in v0.0.4
func CreateIotDeviceWitConfig(config DeviceConfig) Device
func CreateIotDeviceWithQos ¶ added in v0.0.2
type DeviceCommandLogCollector ¶ added in v1.0.0
type DeviceCommandLogCollector func(endTime string) []DeviceLogEntry
设备命令日志收集器
type DeviceConfig ¶ added in v0.0.4
type DeviceError ¶ added in v1.0.0
type DeviceError struct {
// contains filtered or unexported fields
}
func (*DeviceError) Error ¶ added in v1.0.0
func (err *DeviceError) Error() string
type DeviceInfo ¶ added in v0.0.2
type DeviceInfo struct { ParentDeviceId string `json:"parent_device_id,omitempty"` NodeId string `json:"node_id,omitempty"` DeviceId string `json:"device_id,omitempty"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` ManufacturerId string `json:"manufacturer_id,omitempty"` Model string `json:"model,omitempty"` ProductId string `json:"product_id"` FwVersion string `json:"fw_version,omitempty"` SwVersion string `json:"sw_version,omitempty"` Status string `json:"status,omitempty"` ExtensionInfo interface{} `json:"extension_info,omitempty"` }
type DeviceLogEntry ¶ added in v1.0.0
type DeviceMessageLogCollector ¶ added in v1.0.0
type DeviceMessageLogCollector func(endTime string) []DeviceLogEntry
设备消息日志收集器
type DeviceProperties ¶ added in v0.0.2
type DeviceProperties struct {
Services []DevicePropertyEntry `json:"services"`
}
设备属性
type DevicePropertiesSetHandler ¶
type DevicePropertiesSetHandler func(message DevicePropertyDownRequest) bool
平台设置设备属性
type DevicePropertyDownRequest ¶
type DevicePropertyDownRequest struct { ObjectDeviceId string `json:"object_device_id"` Services []DevicePropertyDownRequestEntry `json:"services"` }
平台设置设备属性==================================================
type DevicePropertyDownRequestEntry ¶
type DevicePropertyDownRequestEntry struct { ServiceId string `json:"service_id"` Properties interface{} `json:"properties"` }
type DevicePropertyEntry ¶ added in v0.0.2
type DevicePropertyEntry struct { ServiceId string `json:"service_id"` Properties interface{} `json:"properties"` EventTime string `json:"event_time"` }
设备的一个属性
type DevicePropertyLogCollector ¶ added in v1.0.0
type DevicePropertyLogCollector func(endTime string) []DeviceLogEntry
设备属性日志收集器
type DevicePropertyQueryHandler ¶
type DevicePropertyQueryHandler func(query DevicePropertyQueryRequest) DevicePropertyEntry
平台查询设备属性
type DevicePropertyQueryRequest ¶
type DevicePropertyQueryRequest struct { ObjectDeviceId string `json:"object_device_id"` ServiceId string `json:"service_id"` }
平台设置设备属性==================================================
type DevicePropertyQueryResponse ¶
type DevicePropertyQueryResponse struct { ObjectDeviceId string `json:"object_device_id"` Shadow []DeviceShadowData `json:"shadow"` }
type DevicePropertyQueryResponseHandler ¶
type DevicePropertyQueryResponseHandler func(response DevicePropertyQueryResponse)
设备获取设备影子数据
type DeviceService ¶
type DeviceService struct { DeviceId string `json:"device_id"` Services []DevicePropertyEntry `json:"services"` }
type DeviceShadowData ¶
type DeviceShadowData struct { ServiceId string `json:"service_id"` Desired DeviceShadowPropertiesData `json:"desired"` Reported DeviceShadowPropertiesData `json:"reported"` Version int `json:"version"` }
type DeviceShadowPropertiesData ¶
type DeviceShadowPropertiesData struct { Properties interface{} `json:"properties"` EventTime string `json:"event_time"` }
type DeviceStatus ¶ added in v0.0.2
type DeviceStatusLogCollector ¶ added in v1.0.0
type DeviceStatusLogCollector func(endTime string) []DeviceLogEntry
设备状态日志收集器
type DeviceUpgradeHandler ¶ added in v0.0.2
type DeviceUpgradeHandler func(upgradeType byte, info UpgradeInfo) UpgradeProgress
设备执行软件/固件升级.upgradeType = 0 软件升级,upgradeType = 1 固件升级
type DevicesService ¶
type DevicesService struct {
Devices []DeviceService `json:"devices"`
}
type FileRequest ¶ added in v0.0.2
type FileRequest struct { ObjectDeviceId string `json:"object_device_id"` Services []FileRequestServiceEvent `json:"services"` }
设备获取文件上传下载请求体
type FileRequestServiceEvent ¶ added in v0.0.2
type FileRequestServiceEvent struct { BaseServiceEvent Paras FileRequestServiceEventParas `json:"paras"` }
type FileRequestServiceEventParas ¶ added in v0.0.2
type FileRequestServiceEventParas struct { FileName string `json:"file_name"` FileAttributes interface{} `json:"file_attributes"` }
设备获取文件上传下载URL参数
type FileResponse ¶ added in v0.0.2
type FileResponse struct { ObjectDeviceId string `json:"object_device_id"` Services []FileResponseServiceEvent `json:"services"` }
平台下发文件上传和下载URL响应
type FileResponseServiceEvent ¶ added in v0.0.2
type FileResponseServiceEvent struct { BaseServiceEvent Paras FileResponseServiceEventParas `json:"paras"` }
type FileResponseServiceEventParas ¶ added in v0.0.2
type FileResponseServiceEventParas struct { Url string `json:"url"` BucketName string `json:"bucket_name"` ObjectName string `json:"object_name"` Expire int `json:"expire"` FileAttributes interface{} `json:"file_attributes"` }
平台下发响应参数
type FileResultResponse ¶ added in v0.0.2
type FileResultResponse struct { ObjectDeviceId string `json:"object_device_id"` Services []FileResultResponseServiceEvent `json:"services"` }
func CreateFileUploadDownLoadResultResponse ¶ added in v0.0.2
func CreateFileUploadDownLoadResultResponse(filename, action string, result bool) FileResultResponse
文件上传下载管理
type FileResultResponseServiceEvent ¶ added in v0.0.2
type FileResultResponseServiceEvent struct { BaseServiceEvent Paras FileResultServiceEventParas `json:"paras"` }
type FileResultServiceEventParas ¶ added in v0.0.2
type FileResultServiceEventParas struct { ObjectName string `json:"object_name"` ResultCode int `json:"result_code"` StatusCode int `json:"status_code"` StatusDescription string `json:"status_description"` }
上报文件上传下载结果参数
type Gateway ¶ added in v0.0.2
type Gateway interface { // 网关更新子设备状态 UpdateSubDeviceState(subDevicesStatus SubDevicesStatus) bool // 网关删除子设备 DeleteSubDevices(deviceIds []string) bool // 网关添加子设备 AddSubDevices(deviceInfos []DeviceInfo) bool // 网关同步子设备列表,默认实现不指定版本 SyncAllVersionSubDevices() // 网关同步特定版本子设备列表 SyncSubDevices(version int) // contains filtered or unexported methods }
type HttpClient ¶ added in v0.0.2
type HttpClient interface { UploadFile(filename, uri string) bool DownloadFile(filename, uri string) bool }
仅用于设备上传文件
func CreateHttpClient ¶ added in v0.0.2
func CreateHttpClient() HttpClient
type HttpDevice ¶ added in v1.0.1
type HttpDevice interface { // 上报消息 SendMessage(message Message) bool // 上报属性 ReportProperties(properties DeviceProperties) bool }
使用HTTP协议的设备,当前使用HTTP协议的设备只支持上报消息和上报属性
func CreateHttpDevice ¶ added in v1.0.1
func CreateHttpDevice(config HttpDeviceConfig) HttpDevice
type HttpDeviceConfig ¶ added in v1.0.1
type LogCollectionConfig ¶ added in v1.0.0
type LogCollectionConfig struct {
// contains filtered or unexported fields
}
type Message ¶
type Message struct { ObjectDeviceId string `json:"object_device_id"` Name string `json:"name"` Id string `json:"id"` Content string `json:"content"` }
消息
type ReportDeviceInfoEventParas ¶ added in v0.0.4
type ReportDeviceInfoEventParas struct { DeviceSdkVersion string `json:"device_sdk_version,omitempty"` SwVersion string `json:"sw_version,omitempty"` FwVersion string `json:"fw_version,omitempty"` }
设备信息上报请求参数
type ReportDeviceInfoRequest ¶ added in v0.0.4
type ReportDeviceInfoRequest struct { ObjectDeviceId string `json:"object_device_id,omitempty"` Services []ReportDeviceInfoServiceEvent `json:"services,omitempty"` }
上报设备信息请求
type ReportDeviceInfoServiceEvent ¶ added in v0.0.4
type ReportDeviceInfoServiceEvent struct { BaseServiceEvent Paras ReportDeviceInfoEventParas `json:"paras,omitempty"` }
type ReportDeviceLogRequest ¶ added in v1.0.0
type ReportDeviceLogRequest struct {
Services []ReportDeviceLogServiceEvent `json:"services,omitempty"`
}
上报设备日志请求
type ReportDeviceLogServiceEvent ¶ added in v1.0.0
type ReportDeviceLogServiceEvent struct { BaseServiceEvent Paras DeviceLogEntry `json:"paras,omitempty"` }
type Result ¶ added in v1.0.2
type Result struct { Flag chan int // contains filtered or unexported fields }
func (*Result) CompleteError ¶ added in v1.0.2
type SubDeviceInfo ¶ added in v0.0.2
type SubDeviceInfo struct { Devices []DeviceInfo `json:"devices"` Version int `json:"version"` }
添加子设备
type SubDevicesAddHandler ¶ added in v0.0.2
type SubDevicesAddHandler func(devices SubDeviceInfo)
子设备添加回调函数
type SubDevicesDeleteHandler ¶ added in v0.0.2
type SubDevicesDeleteHandler func(devices SubDeviceInfo)
子设备删除糊掉函数
type SubDevicesStatus ¶ added in v0.0.2
type SubDevicesStatus struct {
DeviceStatuses []DeviceStatus `json:"device_statuses"`
}
网关更新子设备状态
type SwFwVersionReporter ¶ added in v0.0.2
设备上报软固件版本,第一个返回值为软件版本,第二个返回值为固件版本
type UpgradeInfo ¶ added in v0.0.2
type UpgradeInfo struct { Version string `json:"version"` //软固件包版本号 Url string `json:"url"` //软固件包下载地址 FileSize int `json:"file_size"` //软固件包文件大小 AccessToken string `json:"access_token"` //软固件包url下载地址的临时token Expires string `json:"expires"` //access_token的超期时间 Sign string `json:"sign"` //软固件包MD5值 }
平台下发的升级信息
type UpgradeProgress ¶ added in v0.0.2
type UpgradeProgress struct { ResultCode int `json:"result_code"` Progress int `json:"progress"` // 设备的升级进度,范围:0到100 Version string `json:"version"` // 设备当前版本号 Description string `json:"description"` // 升级状态描述信息,可以返回具体升级失败原因。 }
设备升级状态响应,用于设备向平台反馈进度,错误信息等 ResultCode: 设备的升级状态,结果码定义如下: 0:处理成功 1:设备使用中 2:信号质量差 3:已经是最新版本 4:电量不足 5:剩余空间不足 6:下载超时 7:升级包校验失败 8:升级包类型不支持 9:内存不足 10:安装升级包失败 255: 内部异常