1

I implemented a simple IoT Edge module from scratch as simulated temperature and humidity sensor. When I try to see the messages being sent to the cloud, I receive this error:

SendEventAsync for a named output is available for Modules only.

enter image description here This is my code:

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);
    }
}

This is my cinnection string:

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

Any idea of how to fix it?

Thank you!

  • 1
    Could you verify that the value in the `EdgeHubConnectionString` envrionment variable is a connection string which has a component for the `ModuleId` property? Please feel free to copy/paste the connection string here eliding hub names and keys. – Raj Dec 22 '17 at 02:40
  • How do you execute the code? You will get this error if you debug the code from within VSCode (F5). A "hack" would be to not use named output, e.g. just .SetEventAsync(eventMessage). You may have to adjust the connection string too. – Karsten Strøbæk Dec 23 '17 at 16:41

0 Answers0