question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get device twin in IoT Edge module

See original GitHub issue

Hi all,

Currently, I would like to monitor the event about updating device’s desired property(not module twin). It seems doable, but how can I get device connection string in IoT Edge module? or is there any better way?

Below is my code in edge module

static string _deviceConnectionString = "***";
static DeviceClient _deviceClient = null;

//Monitor Device Twin
_deviceClient = DeviceClient.CreateFromConnectionString(_deviceConnectionString, TransportType.Mqtt);
Twin twin = await _deviceClient.GetTwinAsync();

private static async Task OnDeviceTwinDesiredPropertyChanged(TwinCollection desiredProperties, object userContext)
        {
            Console.WriteLine("\tDesired property changed:");
            Console.WriteLine($"\t{desiredProperties.ToJson()}");

            Console.WriteLine("\tSending current time as reported property");
            TwinCollection reportedProperties = new TwinCollection();
            reportedProperties["DateTimeLastDesiredPropertyChangeReceived"] = DateTime.Now;

            await _deviceClient.UpdateReportedPropertiesAsync(reportedProperties).ConfigureAwait(false);
        }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
FabGrecommented, May 31, 2021

Hi there, we also have scenarios where some device models, running modes(, …), should be shared between modules and it’s not really convenient to duplicate in each module twin… We have different edge device projects and we have always met this need. Thanks,

2reactions
danigiancommented, Jan 31, 2019

Same issue here. What if an edge device has metadata in its device twin, that a customer wants to use in device registry queries, that any given module wants to access? @varunpuranik what’s the suggested pattern here? Connection string in module twin is definitely not a way for production scenarios where a TPM is involved, neither it is the duplication of these metadata in every module twin.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understand and use module twins in IoT Hub - Azure
Similar to device twins, module twins are JSON documents that store module state information including metadata, configurations, and conditions.
Read more >
Access Device twin properties from IoT Edge module #18767
You can access the IOTEDGE_IOTHUBHOSTNAME, IOTEDGE_MODULEID,IOTEDGE_DEVICEID by reading the corresponding environment variable. You can start an ...
Read more >
Use Iot hub edge module client to get device twin properties
1 Answer 1 ... That is correct Mehdi, when you use the IoTHubModuleClient's get_twin method you are getting the module twin properties, you...
Read more >
Adding local persisted state to IoT Edge modules using ...
Each Azure IoT Edge module, deployed to a device, has its own Module twin. A Module twin is the same concept as a...
Read more >
Azure IoT Edge Module Twin
The Azure IoT Hub Connector supports the following activities with Azure IoT Edge Devices: • Read and write edge module twin properties.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found