0

I want to use the device provisioning in Azure for my devices.

I'm using the Azure IoT SDK (Java).

I would like to create a new device that have some specific properties inside the JSON of the device twin. I want to see my new device in Azure portal with a custom JSON for the device twin.

In the ProvisioningTpmSample class (Link GitHub). There is this piece of code:

try
{
    deviceClient = DeviceClient.createFromSecurityProvider(iotHubUri, deviceId, securityClientTPMEmulator, IotHubClientProtocol.MQTT);
    deviceClient.open();
    Message messageToSendFromDeviceToHub =  new Message("Whatever message you would like to send");

    System.out.println("Sending message from device to IoT Hub...");
    deviceClient.sendEventAsync(messageToSendFromDeviceToHub, new IotHubEventCallbackImpl(), null);
}

I find the method setProperty for the Message. It's like

messageToSendFromDeviceToHub.setProperty("test", "test");

Is it possible to defined the desired and required properties of the device twin by this setProperty method?

Thanks a lot

davide.ferrari
  • 221
  • 2
  • 10
  • the device twins and telemetry data message (D2C messages) are different entities. The setProperty method can be used only for populating a property of the telemetry data message (D2C message). – Roman Kiss Mar 15 '19 at 13:11
  • @RomanKiss you are right thanks a lot!. Anywhere, I find an 'Initial Twin Device' section in Device Service Provisioning area where you can set the device twin JSON. – davide.ferrari Mar 15 '19 at 15:42

0 Answers0