in source/azure_iot_hub_client.c [1369:1428]
AzureIoTResult_t AzureIoTHubClient_RequestPropertiesAsync( AzureIoTHubClient_t * pxAzureIoTHubClient )
{
AzureIoTMQTTResult_t xMQTTResult;
AzureIoTResult_t xResult;
AzureIoTMQTTPublishInfo_t xMQTTPublishInfo = { 0 };
uint8_t ucRequestID[ 10 ];
az_span xRequestID = az_span_create( ( uint8_t * ) ucRequestID, sizeof( ucRequestID ) );
size_t xTopicLength;
az_result xCoreResult;
if( pxAzureIoTHubClient == NULL )
{
AZLogError( ( "AzureIoTHubClient_RequestPropertiesAsync failed: invalid argument" ) );
xResult = eAzureIoTErrorInvalidArgument;
}
else if( pxAzureIoTHubClient->_internal.xReceiveContext[ azureiothubRECEIVE_CONTEXT_INDEX_PROPERTIES ]._internal.usState !=
azureiothubTOPIC_SUBSCRIBE_STATE_SUBACK )
{
AZLogError( ( "AzureIoTHubClient_RequestPropertiesAsync failed: properties topic not subscribed" ) );
xResult = eAzureIoTErrorTopicNotSubscribed;
}
else
{
if( ( xResult = prvGetPropertiesRequestId( pxAzureIoTHubClient, xRequestID,
false, NULL, &xRequestID ) ) != eAzureIoTSuccess )
{
AZLogError( ( "Failed to get request id: error=0x%08x", xResult ) );
}
else if( az_result_failed(
xCoreResult =
az_iot_hub_client_properties_document_get_publish_topic( &pxAzureIoTHubClient->_internal.xAzureIoTHubClientCore,
xRequestID,
( char * ) pxAzureIoTHubClient->_internal.pucWorkingBuffer,
pxAzureIoTHubClient->_internal.ulWorkingBufferLength,
&xTopicLength ) ) )
{
AZLogError( ( "Failed to get property document topic: core error=0x%08x", ( uint16_t ) xCoreResult ) );
xResult = AzureIoT_TranslateCoreError( xCoreResult );
}
else
{
xMQTTPublishInfo.pcTopicName = pxAzureIoTHubClient->_internal.pucWorkingBuffer;
xMQTTPublishInfo.xQOS = eAzureIoTMQTTQoS0;
xMQTTPublishInfo.usTopicNameLength = ( uint16_t ) xTopicLength;
if( ( xMQTTResult = AzureIoTMQTT_Publish( &( pxAzureIoTHubClient->_internal.xMQTTContext ),
&xMQTTPublishInfo, 0 ) ) != eAzureIoTMQTTSuccess )
{
AZLogError( ( "Failed to Publish get properties message: MQTT error=0x%08x", xMQTTResult ) );
xResult = eAzureIoTErrorPublishFailed;
}
else
{
xResult = eAzureIoTSuccess;
}
}
}
return xResult;
}