繁体   English   中英

通过C#注册树莓派以使用Azure

[英]Register raspberry pi to azure via c#

我正在开发一个简单的应用程序,该应用程序需要从azure发送和接收一些数据。 首先,我使用了模拟设备(和控制台应用程序)。 我已经配置了Azure门户以使用此数据,并且一切正常。

同时,我通过单元测试检查了传感器,它也可以正常工作。 现在,我想将传感器中的一些数据发送到天蓝色(使用Universal App)。 我尝试使用此链接: https : //blogs.windows.com/buildingapps/2016/03/03/connect-your-windows-app-to-azure-iot-hub-with-visual-studio/#BgxLrRq1bXolCitM .97

我在模拟设备中选择了要使用的设备,并且客户端连接出现“未知主机”错误。 我需要将树莓派注册为设备吗? 如何从已知的通用应用程序(即https://developer.microsoft.com/en-us/windows/iot/samples/helloblinky )发送简单的字符串到天蓝色?

我正在使用Windows 10物联网,c#

谢谢!

更新:我尝试完成您建议的所有操作,但均未成功。 相关代码:

    public static async Task SendDeviceToCloudMessageAsync()
    {
        CreateClient();

        var currentTemperature = 20 /*getCurrentTemperature()*/;
        var currentHumidity = 20/*getCurrentHumidity()*/;

        var telemetryDataPoint = new
        {
            deviceId = DeviceId,
            plantID = 7,
            temperature = currentTemperature,
            humidity = currentHumidity,
            userId = 1
        };
        var messageString = JsonConvert.SerializeObject(telemetryDataPoint);
        var message = new Message(Encoding.ASCII.GetBytes(messageString));
        message.Properties.Add("temperatureAlert", (currentTemperature > 30) ? "true" : "false");

        Debug.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageString);

        await deviceClient.SendEventAsync(message);
    }

我不知道如何验证connectionString var上的“ sharedAccessKey”

错误( 在await deviceClient.SendEventAsync(message)行上 ):引发异常:System.Private.CoreLib.ni.dll中的“ System.Exception”。 (来自HRESULT的异常:0x80072AF9)

您将需要在这里做两件事。

首先,连接您的设备。 此处的详细信息-https: //developer.microsoft.com/zh-cn/windows/iot/docs/ConnectDeviceToCloud

其次,连接您的应用程序。 -https://developer.microsoft.com/zh-CN/windows/iot/docs/ConnectAppToCloud

如果您在执行上述两项操作时遇到问题,则可以提出更具体的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM