開源.Net Standard版華為物聯網北向介面SDK
- 2019 年 11 月 5 日
- 筆記
說明
最近用到了華為的物聯網平台API,但是官方沒有.Net版的SDK,所以就自己封裝了一個,開源出來給有需要的朋友,同時也算是為.Net Core的發展做點小貢獻~
源碼地址:https://github.com/iamoldli/HuaWei.IoT.NorthApi.Sdk
同時包也已經發布到NuGet https://www.nuget.org/packages/HuaWei.IoT.NorthApi.Sdk/
介紹
內部採用一個執行緒來自動刷新令牌,目前只提供非同步方法,並且提供了依賴注入擴展,具體使用方法可參考源碼中的Demo
功能列表
獲取令牌
刷新令牌
註冊設備(驗證碼方式)
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();
撤銷設備命令