[Azure IoT SDK]How can I set/get/monitor the value of ModuleTwin?

罗宇恒 罗宇恒 571 Reputation points

I am implementing a IoT Edge App, and I want to set/get the value of ModuleTwin and monitor the value change of ModuleTwin.

I refer to the sample:

My understanding is following:

  1. set ModuleTwin: ModuleClient.sendReportedProperties()
  2. get ModuleTwin: ModuleClient.getTwin()
  3. monitor ModuleTwin: ModuleClient.subscribeToTwinDesiredProperties()
    Am I right?

I try to test with iotedgehubdev, but after excute client.getTwin(), there is no callback excuted.

Output logs:

MyFirstModule    | Client created
MyFirstModule    | Open connection to IoT Hub.
MyFirstModule    | Connection Status: Connected
MyFirstModule    | Start device Twin and get remaining properties...
MyFirstModule    | IoT Hub responded to device twin operation with status OK
MyFirstModule    | Subscribe to Desired properties on device Twin...
MyFirstModule    | Get device Twin...

What's the problem?

Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
202 questions
{count} votes

Accepted answer
  1. 罗宇恒 罗宇恒 571 Reputation points

    We can use the following APIs:

    1. Get Module Twin:
      ModuleClient.startTwin(IotHubEventCallback deviceTwinStatusCallback, Object deviceTwinStatusCallbackContext, DeviceTwin.TwinPropertyCallBack genericPropertyCallBack, Object genericPropertyCallBackContext)
    2. Set Module Twin:
      InternalClient.sendReportedProperties(Set<DeviceTwin.Property> reportedProperties)
    3. Monitor Module Twin:
      InternalClient.subscribeToTwinDesiredProperties(Map<DeviceTwin.Property,DeviceTwin.Pair<DeviceTwin.TwinPropertyCallBack,Object>> onDesiredPropertyChange)

    For details we can refer to sample:

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful