AzureSphere/AzureSphereSampleDevice/main.c
static bool SetUpAzureIoTHubClientWithDaa(void)
{
    bool retVal = true;

    // Set up auth type
    int retError = iothub_security_init(IOTHUB_SECURITY_TYPE_X509);
    if (retError != 0) {
        Log_Debug("ERROR: iothub_security_init failed with error %d.\n", retError);
        return false;
    }

    // Create Azure Iot Hub client handle
    iothubClientHandle =
        IoTHubDeviceClient_LL_CreateWithAzureSphereFromDeviceAuth(hostName, MQTT_Protocol);

    if (iothubClientHandle == NULL) {
        Log_Debug("IoTHubDeviceClient_LL_CreateFromDeviceAuth returned NULL.\n");
        retVal = false;
        goto cleanup;
    }

    // Enable DAA cert usage when x509 is invoked
    if (IoTHubDeviceClient_LL_SetOption(iothubClientHandle, "SetDeviceId",
                                        &deviceIdForDaaCertUsage) != IOTHUB_CLIENT_OK) {
        Log_Debug("ERROR: Failure setting Azure IoT Hub client option \"SetDeviceId\".\n");
        retVal = false;
        goto cleanup;
    }

    if (connectionType == ConnectionType_IoTEdge) {
        // Provide the Azure IoT device client with the IoT Edge root
        // X509 CA certificate that was used to setup the Edge runtime.
        if (IoTHubDeviceClient_LL_SetOption(iothubClientHandle, OPTION_TRUSTED_CERT,
                                            iotEdgeRootCACertContent) != IOTHUB_CLIENT_OK) {
            Log_Debug("ERROR: Failure setting Azure IoT Hub client option \"TrustedCerts\".\n");
            retVal = false;
            goto cleanup;
        }

        // Set the auto URL Encoder (recommended for MQTT).
        bool urlEncodeOn = true;
        if (IoTHubDeviceClient_LL_SetOption(iothubClientHandle, OPTION_AUTO_URL_ENCODE_DECODE,
                                            &urlEncodeOn) != IOTHUB_CLIENT_OK) {
            Log_Debug(
                "ERROR: Failure setting Azure IoT Hub client option "
                "\"OPTION_AUTO_URL_ENCODE_DECODE\".\n");
            retVal = false;
            goto cleanup;
        }
    }

cleanup:
    iothub_security_deinit();

    return retVal;
}
/// <summary>
///     Sets up the Azure IoT Hub connection (creates the iothubClientHandle)
///     with DAA
/// </summary>

Sets up the Azure IoT Hub connection (creates the iothubClientHandle)
with DAA

Sets up the Azure IoT Hub connection ( creates the iothubClientHandle ) with DAA
static bool SetUpAzureIoTHubClientWithDaa(void)
{
    bool retVal = true;
    int retError = iothub_security_init(IOTHUB_SECURITY_TYPE_X509);
    if (retError != 0) {
        Log_Debug("ERROR: iothub_security_init failed with error %d.\n", retError);
        return false;
    }
    iothubClientHandle =
        IoTHubDeviceClient_LL_CreateWithAzureSphereFromDeviceAuth(hostName, MQTT_Protocol);
    if (iothubClientHandle == NULL) {
        Log_Debug("IoTHubDeviceClient_LL_CreateFromDeviceAuth returned NULL.\n");
        retVal = false;
        goto cleanup;
    }
    if (IoTHubDeviceClient_LL_SetOption(iothubClientHandle, "SetDeviceId",
                                        &deviceIdForDaaCertUsage) != IOTHUB_CLIENT_OK) {
        Log_Debug("ERROR: Failure setting Azure IoT Hub client option \"SetDeviceId\".\n");
        retVal = false;
        goto cleanup;
    }
    if (connectionType == ConnectionType_IoTEdge) {
        if (IoTHubDeviceClient_LL_SetOption(iothubClientHandle, OPTION_TRUSTED_CERT,
                                            iotEdgeRootCACertContent) != IOTHUB_CLIENT_OK) {
            Log_Debug("ERROR: Failure setting Azure IoT Hub client option \"TrustedCerts\".\n");
            retVal = false;
            goto cleanup;
        }
        bool urlEncodeOn = true;
        if (IoTHubDeviceClient_LL_SetOption(iothubClientHandle, OPTION_AUTO_URL_ENCODE_DECODE,
                                            &urlEncodeOn) != IOTHUB_CLIENT_OK) {
            Log_Debug(
                "ERROR: Failure setting Azure IoT Hub client option "
                "\"OPTION_AUTO_URL_ENCODE_DECODE\".\n");
            retVal = false;
            goto cleanup;
        }
    }
cleanup:
    iothub_security_deinit();
    return retVal;
}
static bool SetUpAzureIoTHubClientWithDaa ( void ) { bool retVal = true ; int retError = iothub_security_init ( IOTHUB_SECURITY_TYPE_X509 ) ; if ( retError != 0 ) { Log_Debug ( " \n " , retError ) ; return false ; } iothubClientHandle = IoTHubDeviceClient_LL_CreateWithAzureSphereFromDeviceAuth ( hostName , MQTT_Protocol ) ; if ( iothubClientHandle == NULL ) { Log_Debug ( " \n " ) ; retVal = false ; goto cleanup ; } if ( IoTHubDeviceClient_LL_SetOption ( iothubClientHandle , " " , & deviceIdForDaaCertUsage ) != IOTHUB_CLIENT_OK ) { Log_Debug ( " \" \" \n " ) ; retVal = false ; goto cleanup ; } if ( connectionType == ConnectionType_IoTEdge ) { if ( IoTHubDeviceClient_LL_SetOption ( iothubClientHandle , OPTION_TRUSTED_CERT , iotEdgeRootCACertContent ) != IOTHUB_CLIENT_OK ) { Log_Debug ( " \" \" \n " ) ; retVal = false ; goto cleanup ; } bool urlEncodeOn = true ; if ( IoTHubDeviceClient_LL_SetOption ( iothubClientHandle , OPTION_AUTO_URL_ENCODE_DECODE , & urlEncodeOn ) != IOTHUB_CLIENT_OK ) { Log_Debug ( " " " \" \" \n " ) ; retVal = false ; goto cleanup ; } } cleanup : iothub_security_deinit ( ) ; return retVal ; }
<summary>
Sets up the Azure IoT Hub connection (creates the iothubClientHandle)
with DAA
</summary>
<summary > Sets up the Azure IoT Hub connection ( creates the iothubClientHandle ) with DAA < / summary >
// Set up auth type // Create Azure Iot Hub client handle // Enable DAA cert usage when x509 is invoked // Provide the Azure IoT device client with the IoT Edge root // X509 CA certificate that was used to setup the Edge runtime. // Set the auto URL Encoder (recommended for MQTT).