• 开源.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();
    

    撤销设备命令

  • 相关阅读:
    MySQL主库异常,从库手动切换为主库方案
    快速搭建应用服务日志收集系统(Filebeat + ElasticSearch + kibana)
    CentOS7设置DNS服务器
    nginx/iptables动态IP黑白名单实现方案
    Python批量复制和重命名文件
    centos 7 配置php运行环境 (新)
    配置Nginx和php-fpm用Sock套接字连接时,找不到php-fpm.sock的原因
    php-fpm nginx 9000端口
    nginx与php-fpm通信的两种方式
    centos 7.2 常用命令useradd的使用
  • 原文地址:https://www.cnblogs.com/oldli/p/11797743.html
Copyright © 2020-2023  润新知