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 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 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 LogCollectionConfig
- type Message
- type MessageHandler
- type ReportDeviceInfoEventParas
- type ReportDeviceInfoRequest
- type ReportDeviceInfoServiceEvent
- type ReportDeviceLogRequest
- type ReportDeviceLogServiceEvent
- type SubDeviceInfo
- type SubDevicesAddHandler
- type SubDevicesDeleteHandler
- type SubDevicesStatus
- type SwFwVersionReporter
- type UpgradeInfo
- type UpgradeProgress
Constants ¶
const ( // 平台下发消息topic MessageDownTopic string = "$oc/devices/{device_id}/sys/messages/down" // 设备上报消息topic MessageUpTopic string = "$oc/devices/{device_id}/sys/messages/up" // 平台下发命令topic CommandDownTopic string = "$oc/devices/{device_id}/sys/commands/#" // 设备响应平台命令 CommandResponseTopic string = "$oc/devices/{device_id}/sys/commands/response/request_id=" // 设备上报属性 PropertiesUpTopic string = "$oc/devices/{device_id}/sys/properties/report" //平台设置属性topic PropertiesSetRequestTopic string = "$oc/devices/{device_id}/sys/properties/set/#" // 设备响应平台属性设置topic PropertiesSetResponseTopic string = "$oc/devices/{device_id}/sys/properties/set/response/request_id=" // 平台查询设备属性 PropertiesQueryRequestTopic string = "$oc/devices/{device_id}/sys/properties/get/#" // 设备响应平台属性查询 PropertiesQueryResponseTopic string = "$oc/devices/{device_id}/sys/properties/get/response/request_id=" // 设备侧获取平台的设备影子数据 DeviceShadowQueryRequestTopic string = "$oc/devices/{device_id}/sys/shadow/get/request_id=" // 设备侧响应获取平台设备影子 DeviceShadowQueryResponseTopic string = "$oc/devices/{device_id}/sys/shadow/get/response/#" // 网关批量上报子设备属性 GatewayBatchReportSubDeviceTopic string = "$oc/devices/{device_id}/sys/gateway/sub_devices/properties/report" // 平台下发文件上传和下载URL FileActionUpload string = "upload" FileActionDownload string = "download" // 设备或网关向平台发送请求 DeviceToPlatformTopic string = "$oc/devices/{device_id}/sys/events/up" // 平台向设备下发事件topic PlatformEventToDeviceTopic string = "$oc/devices/{device_id}/sys/events/down" )
Variables ¶
This section is empty.
Functions ¶
func CreateAsyncIotDevice ¶
func CreateAsyncIotDevice(id, password, servers string) *asyncDevice
func CreateAsyncIotDeviceWitConfig ¶
func CreateAsyncIotDeviceWitConfig(config DeviceConfig) *asyncDevice
func GetEventTimeStamp ¶
func GetEventTimeStamp() string
设备采集数据UTC时间(格式:yyyyMMdd'T'HHmmss'Z'),如:20161219T114920Z。 设备上报数据不带该参数或参数格式错误时,则数据上报时间以平台时间为准。
func Interface2JsonString ¶
func Interface2JsonString(v interface{}) string
Types ¶
type AsyncDevice ¶
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 ¶
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 ¶
type BaseDevice ¶
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 ¶
type BooleanAsyncResult ¶
type BooleanAsyncResult struct {
// contains filtered or unexported fields
}
func NewBooleanAsyncResult ¶
func NewBooleanAsyncResult() *BooleanAsyncResult
func (*BooleanAsyncResult) Done ¶
func (b *BooleanAsyncResult) Done() <-chan struct{}
Done implements the Token Done method.
func (*BooleanAsyncResult) Result ¶
func (bar *BooleanAsyncResult) Result() bool
func (*BooleanAsyncResult) Wait ¶
func (b *BooleanAsyncResult) Wait() bool
Wait implements the Token Wait method.
func (*BooleanAsyncResult) WaitTimeout ¶
WaitTimeout implements the Token WaitTimeout method.
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 ¶
func CreateIotDeviceWitConfig(config DeviceConfig) Device
func CreateIotDeviceWithQos ¶
type DeviceCommandLogCollector ¶
type DeviceCommandLogCollector func(endTime string) []DeviceLogEntry
设备命令日志收集器
type DeviceConfig ¶
type DeviceError ¶
type DeviceError struct {
// contains filtered or unexported fields
}
func (*DeviceError) Error ¶
func (err *DeviceError) Error() string
type DeviceInfo ¶
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 ¶
type DeviceMessageLogCollector ¶
type DeviceMessageLogCollector func(endTime string) []DeviceLogEntry
设备消息日志收集器
type DeviceProperties ¶
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 ¶
type DevicePropertyEntry struct { ServiceId string `json:"service_id"` Properties interface{} `json:"properties"` EventTime string `json:"event_time"` }
设备的一个属性
type DevicePropertyLogCollector ¶
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 ¶
type DeviceStatusLogCollector ¶
type DeviceStatusLogCollector func(endTime string) []DeviceLogEntry
设备状态日志收集器
type DeviceUpgradeHandler ¶
type DeviceUpgradeHandler func(upgradeType byte, info UpgradeInfo) UpgradeProgress
设备执行软件/固件升级.upgradeType = 0 软件升级,upgradeType = 1 固件升级
type DevicesService ¶
type DevicesService struct {
Devices []DeviceService `json:"devices"`
}
type FileRequest ¶
type FileRequest struct { ObjectDeviceId string `json:"object_device_id"` Services []FileRequestServiceEvent `json:"services"` }
设备获取文件上传下载请求体
type FileRequestServiceEvent ¶
type FileRequestServiceEvent struct { BaseServiceEvent Paras FileRequestServiceEventParas `json:"paras"` }
type FileRequestServiceEventParas ¶
type FileRequestServiceEventParas struct { FileName string `json:"file_name"` FileAttributes interface{} `json:"file_attributes"` }
设备获取文件上传下载URL参数
type FileResponse ¶
type FileResponse struct { ObjectDeviceId string `json:"object_device_id"` Services []FileResponseServiceEvent `json:"services"` }
平台下发文件上传和下载URL响应
type FileResponseServiceEvent ¶
type FileResponseServiceEvent struct { BaseServiceEvent Paras FileResponseServiceEventParas `json:"paras"` }
type FileResponseServiceEventParas ¶
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 ¶
type FileResultResponse struct { ObjectDeviceId string `json:"object_device_id"` Services []FileResultResponseServiceEvent `json:"services"` }
func CreateFileUploadDownLoadResultResponse ¶
func CreateFileUploadDownLoadResultResponse(filename, action string, result bool) FileResultResponse
文件上传下载管理
type FileResultResponseServiceEvent ¶
type FileResultResponseServiceEvent struct { BaseServiceEvent Paras FileResultServiceEventParas `json:"paras"` }
type FileResultServiceEventParas ¶
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 ¶
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 ¶
type HttpClient interface { UploadFile(filename, uri string) bool DownloadFile(filename, uri string) bool }
仅用于设备上传文件
func CreateHttpClient ¶
func CreateHttpClient() HttpClient
type LogCollectionConfig ¶
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 ¶
type ReportDeviceInfoEventParas struct { DeviceSdkVersion string `json:"device_sdk_version,omitempty"` SwVersion string `json:"sw_version,omitempty"` FwVersion string `json:"fw_version,omitempty"` }
设备信息上报请求参数
type ReportDeviceInfoRequest ¶
type ReportDeviceInfoRequest struct { ObjectDeviceId string `json:"object_device_id,omitempty"` Services []ReportDeviceInfoServiceEvent `json:"services,omitempty"` }
上报设备信息请求
type ReportDeviceInfoServiceEvent ¶
type ReportDeviceInfoServiceEvent struct { BaseServiceEvent Paras ReportDeviceInfoEventParas `json:"paras,omitempty"` }
type ReportDeviceLogRequest ¶
type ReportDeviceLogRequest struct {
Services []ReportDeviceLogServiceEvent `json:"services,omitempty"`
}
上报设备日志请求
type ReportDeviceLogServiceEvent ¶
type ReportDeviceLogServiceEvent struct { BaseServiceEvent Paras DeviceLogEntry `json:"paras,omitempty"` }
type SubDeviceInfo ¶
type SubDeviceInfo struct { Devices []DeviceInfo `json:"devices"` Version int `json:"version"` }
添加子设备
type SubDevicesStatus ¶
type SubDevicesStatus struct {
DeviceStatuses []DeviceStatus `json:"device_statuses"`
}
网关更新子设备状态
type SwFwVersionReporter ¶
设备上报软固件版本,第一个返回值为软件版本,第二个返回值为固件版本
type UpgradeInfo ¶
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 ¶
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: 内部异常