开源.Net Standard版华为物联网北向接口SDK
生活随笔
收集整理的這篇文章主要介紹了
开源.Net Standard版华为物联网北向接口SDK
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
說明
最近用到了華為的物聯網平臺API,但是官方沒有.Net版的SDK,所以就自己封裝了一個,開源出來給有需要的朋友,同時也算是為.Net Core的發展做點小貢獻~
源碼地址:https://github.com/iamoldli/HuaWei.IoT.NorthApi.Sdk
同時包也已經發布到NuGet?https://www.nuget.org/packages/HuaWei.IoT.NorthApi.Sdk/
說明
華為物聯網平臺北向接口.Net Standard(.Net Core)SDK
介紹
內部采用一個線程來自動刷新令牌,目前只提供異步方法,并且提供了依賴注入擴展,具體使用方法可參考源碼中的Demo
功能列表
獲取令牌
當創建INorthApiClient實例的時候,會自動注冊獲取令牌
刷新令牌
內部包含一個定時器,用于自動刷新令牌,同時可以通過設置配置項中的RefreshTokenTimer屬性為false來關閉自動刷新
注冊設備(驗證碼方式)
var model = new DeviceRegisterModel {EndUserId = "",Imsi = "",NodeId = "",Timeout = 0,DeviceInfo = new DeviceRegisterInfo{DeviceType = "",ManufacturerId = "",ManufacturerName = "",Model = "",Name = "測試",ProtocolType = ProtocolType.CoAP} };await _client.DeviceRegister(model);注冊設備(密碼方式)
刷新設備密鑰
var model = new DeviceRefreshModel {DeviceId = _deviceId,NodeId = "" };await _client.DeviceRefresh(model);修改設備信息
var model = new DeviceModifyModel {DeviceId = _deviceId,Name = "測試" };await _client.DeviceModify(model);刪除設備
await _client.DeviceDelete(_deviceId);查詢設備激活狀態
await _client.DeviceActivated(_deviceId);查詢單個設備信息
await _client.DeviceGet(_deviceId);批量查詢設備信息
var model = new DeviceInfoQueryModel {StartTime = DateTime.Now.AddDays(-7) };await _client.DeviceQuery(model);查詢設備歷史數據
var model = new DeviceDataHistoryQueryModel {DeviceId = _deviceId };await _client.DeviceDataHistory(model);訂閱平臺業務數據
var model = new SubscribeModel {NotifyType = NotifyType.DeviceDataChanged,CallbackUrl = "http://api.text.com" };await _client.Subscribe(model);查詢單個訂閱
var model = new SubscribeModel {NotifyType = NotifyType.DeviceDataChanged,CallbackUrl = "http://api.text.com" };var result = await _client.Subscribe(model);await _client.SubscriptionGet(result.Data.SubscriptionId);批量查詢訂閱
var model = new SubscriptionQueryModel {NotifyType = NotifyType.DeviceDataChanged };return (await _client.SubscriptionQuery(model)).Data;刪除單個訂閱
await _client.SubscriptionDelete("")批量刪除訂閱
訂閱平臺管理數據
創建設備命令
var model = new CommandCreateModel {DeviceId = _deviceId,Command = new CommandBody{ServiceId = "DTU",Method = "SETCommand",Paras = new{Value = "1111"}} };await _client.CommandCreate(model);查詢設備命令
await _client.CommandQuery();撤銷設備命令
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的开源.Net Standard版华为物联网北向接口SDK的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [Asp.net core 3.1] 通
- 下一篇: 你知道怎么使用DebugView查看调试