最近用到了华为的物联网平台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();
撤销设备命令