El Bruno

Hi !

In my previous post I wrote about the libraries that we will use to access to Twin Properties in an Azure IoT Edge Module. Let’s go for it.

Configuration

We will use 3 main settings to read and write Twin information

# connect using IoTHub connection string and device id with the module identity name
IOTHUB_CONNECTION_STRING = "IoT Hub Connection String"
DEVICE_ID = 'Device Id'
MODULE_ID = 'Module Id'

Read Twin Properties

Let’s read twin properties with a couple of lines

# read twin
iothub_registry_manager = IoTHubRegistryManager(IOTHUB_CONNECTION_STRING)
module_twin = iothub_registry_manager.get_module_twin(DEVICE_ID, MODULE_ID)
twin_properties = "{0}".format(module_twin.properties) 
print ( twin_properties )

Update Twin Properties

And, if we need to update this, similar code.

iothub_registry_manager = IoTHubRegistryManager(IOTHUB_CONNECTION_STRING) module_twin = iothub_registry_manager.get_module_twin(DEVICE_ID, MODULE_ID) twin_original = "{0}".format(module_twin.properties) # Update twin twin_patch = Twin() twin_patch.properties = TwinProperties(desired={"doorState": 0, "doorStateSource": "python test app"}) updated_module_twin = iothub_registry_manager.update_module_twin(DEVICE_ID, MODULE_ID, twin_patch, module_twin.etag) # display changes twin_updated = "{0}".format(updated_module_twin .properties) print…

View original post 62 more words

Leave a Reply

Your email address will not be published. Required fields are marked *

I’m Ivana

I’m a Technology Advocate who is living proof that Technology changes lives. I started my career with Microsoft from my small city (Salta), in Argentina. Now I train people and teams globally in the powerful international language of Tech. I inspire people from all walks of life to become world citizens and “geeks” like me who dream big and achieve amazing things. As a proud woman in Tech, content creator and public speaker I love travelling, connect and create magic moments of transformation; and I learn from everyone I meet. When I am not on the road, I am home with my husband and two dogs. My adventurous spirit in my work life is echoed in my love for Disney movies like Moana and Lilo & Stitch. Who knows “how far I’ll go” on my journey, but I know the power of Technology can get me there!

Let’s connect