IoT Edge:在C#模块上使用SendEventAsync时出错

时间:2017-12-22 02:09:24

标签: c# azure azure-iot-edge

我从零开始实施了一个简单的IoT Edge模块作为模拟温度和湿度传感器。 当我尝试查看发送到云的消息时,我收到此错误:

命名输出的SendEventAsync仅适用于模块。

enter image description here 这是我的代码:

private static async Task SendMessages(DeviceClient deviceClient)
{
    Console.WriteLine("Device sending {0} messages to IoTHub...\n", MessageCount);

    var rnd = new Random();

    for (var count = 0; count < MessageCount; count++)
    {
        _temperature = rnd.Next(20, 35);
        _humidity = rnd.Next(60, 80);

        var alert = _temperature > TemperatureThreshold ? "true" : "false";

        var messageBody = new MessageBody
        {
            DeviceId = ModuleId,
            MessageId = count,
            Temperature = _temperature,
            Humidity = _humidity
        };

        var dataBuffer = JsonConvert.SerializeObject(messageBody);

        var eventMessage = new Message(Encoding.UTF8.GetBytes(dataBuffer));

        eventMessage.Properties.Add("temperatureAlert", alert);

        Console.WriteLine("\t{0}> Sending message: {1}, Data: [{2}]", DateTime.Now.ToLocalTime(), count, dataBuffer);

        await deviceClient.SendEventAsync("toFilterModule", eventMessage);
    }
}

这是我的cinnection字符串:

var connectionString = Environment.GetEnvironmentVariable("EdgeHubConnectionString");

有关如何修复的想法吗?

谢谢!

0 个答案:

没有答案