0

I have an IotHub trigger:

[FunctionName("MainFunc")]    
public static void Run([IoTHubTrigger("messages/events", Connection = "IotHubConnectionString", ConsumerGroup = "cons_group")]EventData message,       ILogger log)
    {
        //....
    }

The problem is that I cannot figure out the right signature for "injecting" device twin. The only solution for reading twin that I see is to use RegistryManager inside the trigger:

var registryManager = RegistryManager.CreateFromConnectionString(IotHubConnectionString);
var twinsQuery = registryManager.CreateQuery("SELECT * FROM devices");
var twins = await twinsQuery.GetNextAsTwinAsync().ConfigureAwait(false);

Any ideas?

amplifier
  • 1,793
  • 1
  • 21
  • 55
  • you can use the Azure IoT Hub REST API to get the device twin, see https://learn.microsoft.com/en-us/rest/api/iothub/service/gettwin The deviceId can be obtained from the message.SystemProperties["iothub-connection-device-id"] – Roman Kiss Apr 19 '19 at 04:42
  • @RomanKiss I think it is the same as using GetNextAsTwinAsync – amplifier Apr 19 '19 at 12:28
  • Basically, the RegistryManager is using the same protocol. If you are looking for a custom binding, see the following iothub extension https://github.com/Azure/azure-functions-iothub-extension – Roman Kiss Apr 19 '19 at 13:53

0 Answers0