最近用到了華爲的物聯網平臺API,可是官方沒有.Net版的SDK,因此就本身封裝了一個,開源出來給有須要的朋友,同時也算是爲.Net Core的發展作點小貢獻~git
源碼地址:https://github.com/iamoldli/HuaWei.IoT.NorthApi.Sdkgithub
同時包也已經發布到NuGet https://www.nuget.org/packages/HuaWei.IoT.NorthApi.Sdk/api
華爲物聯網平臺北向接口.Net Standard(.Net Core)SDK異步
內部採用一個線程來自動刷新令牌,目前只提供異步方法,而且提供了依賴注入擴展,具體使用方法可參考源碼中的Demo測試
獲取令牌線程
當建立INorthApiClient實例的時候,會自動註冊獲取令牌code
刷新令牌接口
內部包含一個定時器,用於自動刷新令牌,同時能夠經過設置配置項中的RefreshTokenTimer
屬性爲false來關閉自動刷新ip
註冊設備(驗證碼方式)get
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();
撤銷設備命令