in source/azure_iot_hub_client.c [1301:1366]
AzureIoTResult_t AzureIoTHubClient_SendPropertiesReported( AzureIoTHubClient_t * pxAzureIoTHubClient,
const uint8_t * pucReportedPayload,
uint32_t ulReportedPayloadLength,
uint32_t * pulRequestId )
{
AzureIoTMQTTResult_t xMQTTResult;
AzureIoTResult_t xResult;
AzureIoTMQTTPublishInfo_t xMQTTPublishInfo = { 0 };
uint8_t ucRequestID[ azureiothubMAX_SIZE_FOR_UINT32 ];
size_t xTopicLength;
az_result xCoreResult;
az_span xRequestID = az_span_create( ucRequestID, sizeof( ucRequestID ) );
if( ( pxAzureIoTHubClient == NULL ) ||
( pucReportedPayload == NULL ) || ( ulReportedPayloadLength == 0 ) )
{
AZLogError( ( "AzureIoTHubClient_SendPropertiesReported failed: invalid argument" ) );
xResult = eAzureIoTErrorInvalidArgument;
}
else if( pxAzureIoTHubClient->_internal.xReceiveContext[ azureiothubRECEIVE_CONTEXT_INDEX_PROPERTIES ]._internal.usState !=
azureiothubTOPIC_SUBSCRIBE_STATE_SUBACK )
{
AZLogError( ( "AzureIoTHubClient_SendPropertiesReported failed: property topic not subscribed" ) );
xResult = eAzureIoTErrorTopicNotSubscribed;
}
else
{
if( ( xResult = prvGetPropertiesRequestId( pxAzureIoTHubClient, xRequestID,
true, pulRequestId, &xRequestID ) ) != eAzureIoTSuccess )
{
AZLogError( ( "Failed to get request id: error=0x%08x", xResult ) );
}
else if( az_result_failed(
xCoreResult =
az_iot_hub_client_properties_get_reported_publish_topic( &pxAzureIoTHubClient->_internal.xAzureIoTHubClientCore,
xRequestID,
( char * ) pxAzureIoTHubClient->_internal.pucWorkingBuffer,
pxAzureIoTHubClient->_internal.ulWorkingBufferLength,
&xTopicLength ) ) )
{
AZLogError( ( "Failed to get property patch topic: core error=0x%08x", ( uint16_t ) xCoreResult ) );
xResult = AzureIoT_TranslateCoreError( xCoreResult );
}
else
{
xMQTTPublishInfo.xQOS = eAzureIoTMQTTQoS0;
xMQTTPublishInfo.pcTopicName = pxAzureIoTHubClient->_internal.pucWorkingBuffer;
xMQTTPublishInfo.usTopicNameLength = ( uint16_t ) xTopicLength;
xMQTTPublishInfo.pvPayload = ( const void * ) pucReportedPayload;
xMQTTPublishInfo.xPayloadLength = ulReportedPayloadLength;
if( ( xMQTTResult = AzureIoTMQTT_Publish( &( pxAzureIoTHubClient->_internal.xMQTTContext ),
&xMQTTPublishInfo, 0 ) ) != eAzureIoTMQTTSuccess )
{
AZLogError( ( "Failed to Publish properties reported message: MQTT error=0x%08x", xMQTTResult ) );
xResult = eAzureIoTErrorPublishFailed;
}
else
{
xResult = eAzureIoTSuccess;
}
}
}
return xResult;
}