zoukankan      html  css  js  c++  java
  • 开源.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();
    

    撤销设备命令

  • 相关阅读:
    开发笔记--git代码回退,撤回到上一个版本
    开发笔记--Navicat导出postgresql表结构数据成excel文件
    使用Aspose.Words组件给word加水印
    JSON JavaScriptSerializer 字符串的长度超过了为 maxJsonLength 属性设置的值。
    http content-type详解
    Linux CPU使用率超过100%的原因
    Qt查找依赖库的简单方法及如何简便地在pro中添加依赖库
    OSI七层网络模型分别是哪七层?各运行那些协议?
    配置文件管理
    Java中日期转json时日期格式转换
  • 原文地址:https://www.cnblogs.com/oldli/p/11797743.html
Copyright © 2011-2022 走看看