Search code examples
iosswiftazureazure-iot-hub

Getting device twin in Swift Sdk - Azure IoT Hub


Is there a way to get the device twin of a device from Azure IoT-Hub, using Azure SDK for Swift?

As far as I know, I am able to get the device twin using the Azure SDK for NodeJS and also its possible for C and others.

In the documentation it says that the swift sdk is a part of the C sdk. But i didnt know how to get the device twin into swift. I tested with the given code example in the docs but its only how to send messages to the device.


Solution

  • Is there a way to get the device twin of a device from Azure IoT-Hub, using Azure SDK for Swift?

    As per this open issue, as of now, there is no sample available for IoTHubDeviceTwin_GetTwin using Azure SDK for Swift.

    Alternatively, as suggested by Roman, you can get the device twin using REST API.

    GET https://fully-qualified-iothubname.azure-devices.net/twins/{id}?api-version=2020-05-31-preview
    

    For Swift, you can use AsyncHttpClient 1.6.4, SAS token for authorization header and create it using Device Explorer.