skip to Main Content

Is there a way to get the device twin of a device from Azure IoT-Hub, using Azure SDK for C? As far as I know, I am able to get the device twin using the Azure SDK for NodeJS.

In nodejs we do it like.

const Client = require('azure-iot-device').Client;
cosnt Protocol = require('azure-iot-device-mqtt').Mqtt;
var client = Client.fromConnectionString(connectionString, Protocol);
function main() {
    client.open(function (err) {
    //If connection is success
    client.getTwin();
    }
});

Is there any way to get the twin data for a device and get twinchange notification in Azure SDK for C i.e A callback function when there is a change in twin data?

2

Answers


  1. Is there any way to get the twin data for a device and get twinchange notification in Azure SDK for C i.e A callback function when there is a change in twin data?

    Yes, you can refer to example of callback function as per Get updates on the device side:

    Try the following code snippet taken from the document:

    static void deviceTwinCallback(DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size, void* userContextCallback)
    {
        (void)userContextCallback;
    
        printf("Device Twin update received (state=%s, size=%zu): %srn", 
            MU_ENUM_TO_STRING(DEVICE_TWIN_UPDATE_STATE, update_state), size, payLoad);
    }
    

    You can also refer to iothub_devicetwin_sample.c and iothub_device_client.c

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search