当前位置:首页 > Web开发 > 正文

开源.Net Standard版华为物联网北向接口SDK

11-05 Web开发

最近用到了华为的物联网平台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 = "" }; await _client.Subscribe(model);

查询单个订阅

var model = new SubscribeModel { NotifyType = NotifyType.DeviceDataChanged, CallbackUrl = "" }; 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

标签:

原文地址:https://www.cnblogs.com/oldli/p/11797743.html

温馨提示: 本文由杰米博客推荐,转载请保留链接: https://www.jmwww.net/file/web/10095.html