Updating a writable property in IOT Central via mqtt from device

446 views Asked by At

I was able to connect to IOT Cental via Mqtt, and update a read-only property from device to server, and writable property from server to device.

I am wondering if it is possible to update a writable property from device to server, and how the payload would look like?

enter image description here

1

There are 1 answers

0
Roman Kiss On

The IoT Plug and Play device developer guide described in details how to handle the telemetry, properties and commands in the device model. The simple case is when your model has only a default component.

The following example shows the major steps for updating a writeable property by device.

  1. Creating a device template abba with a default component: enter image description here

  2. Device abba with this template and its view Pattern:

    enter image description here

  3. Simulated device abba using my Azure IoT Hub Tester:

    enter image description here

    Note, that the versions are after few testing properties and then resetting to null.

  4. Updating both properties such as Reported (read-only property) and Desired (writable property) by device:

    enter image description here

  5. Showing the device twin on the device side:

    enter image description here

  6. IoT Central App view panel:

    enter image description here

    As you can see the above screen snippet, the read-only property shows immediately the value, but the writable property is showing a pending prompt text. In this point, the Desired property is waiting for accepting this value. Basically there are two ways how to make it, such as:

    a. typing the value getting from the raw data or

    b. using the REST PUT request call, see the following screen snippet:

    enter image description here

  7. IoT Central App view panel (updated):

    enter image description here

    Note, that the page must be refreshed manually, when the value has been accepted.

I do recommend to subscribe on the devicePropertyDesiredChange topic using the Data export features for receiving a notification on the changes, see an example of the message received in the Service Bus queue:

enter image description here

UPDATE:

In the case of using multiple components in your device model (at least one behind the default component), the following example shows how to update a writeable property in the component by device:

  1. Creating a new version with a component abc:

    enter image description here

  2. New version of the Pattern view:

    enter image description here

  3. Simulated device abba2 sent the update for writable property Desired at the component abc:

    enter image description here

  4. IoT Central App shows a pending status:

    enter image description here

  5. Cloud backend service received a notification message in the queue:

    enter image description here

  6. Cloud backend service will sent an accepted request for this writable property, note, that the url address shows a path to the specific component:

    enter image description here

  7. IoT Central App shows a new accepted Desired value in the view Pattern at the ComponentA such as abc:

    enter image description here

That's all. Using the above steps, any read-only and/or writable properties declared in the multiple components can be updated from the device side. Note, that the telemetry data outside of the default component are handling differently.