Giter VIP home page Giter VIP logo

aliyun-iot-netcore-sdk's Introduction

aliyun-iot-netcore-sdk

阿里云 华东2 IOT 服务器端 SDK ,使用旧版本(V20160530)改写 ,.NETCore

阿里云IOT套件交流 QQ群:568153758

用法:

	/// <summary>
    /// 发送消息到设备
    /// </summary>
    /// <param name="device_productKey">产品Key</param>
    /// <param name="device_topic">设备topic</param>
    /// <param name="msgContent">消息内容</param>
    public static bool Pub(long device_productKey,string device_topic,string msgContent)
    {
        IClientProfile clientProfile = DefaultProfile.GetProfile("cn-shanghai", "accessKeyId", "secret");
        DefaultAcsClient client = new DefaultAcsClient(clientProfile);
        try
        {
            byte[] bytes = Encoding.UTF8.GetBytes(msgContent);
            string strContent = Convert.ToBase64String(bytes);

            PubRequest pub = new PubRequest();
            pub.ProductKey = device_productKey;
            pub.MessageContent = strContent;
            pub.TopicFullName = device_topic;
            pub.Qos = 1;
            PubResponse resp = client.GetAcsResponse(pub);
            return true;
        }
        catch (Exception err)
        {
            Console.Write(err.Message);
            return false;
        }
    }

    /// <summary>
    /// 创建设备
    /// </summary>
    /// <param name="productKey">设备所属的产品Key</param>
    /// <param name="deviceName">设备名称(支持英文字母、数字和特殊字符-_@.:,长度限制4~32)</param>
    public static RegistDeviceResponse Create(string productKey, string deviceName)
    {
        IClientProfile clientProfile = DefaultProfile.GetProfile("cn-shanghai", "accessKeyId", "secret");
        DefaultAcsClient client = new DefaultAcsClient(clientProfile);

        try
        {
            RegistDeviceRequest request = new RegistDeviceRequest();
            request.ProductKey = productKey;
            request.DeviceName = deviceName;//
            RegistDeviceResponse resp = client.GetAcsResponse(request);
            if (resp.Success == null || !resp.Success.Value)
            {
                return null;
            }
       
            return resp;
        }
        catch (Exception err)
        {
            Console.WriteLine(err.Message);
            return null;
        }
    }

aliyun-iot-netcore-sdk's People

Contributors

anlem12 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.