Get device twin in IoT Edge module
See original GitHub issueHi 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:
- Created 5 years ago
- Reactions:2
- Comments:16 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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,
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.