mirror of
https://github.com/FreeRTOS/FreeRTOS.git
synced 2025-06-17 13:38:12 +08:00
Adds error messages for AWS demo mqtt helpers + misc fixes (#440)
Switch MQTT helpers to logging error message instead of error code. Adds time parameter to xProccessLoop so defender demo does not wait extra time. Fixes some incorrect returns in metrics_collector.c
This commit is contained in:
@ -802,16 +802,13 @@ void prvDefenderDemoTask( void * pvParameters )
|
||||
{
|
||||
for( i = 0; i < DEFENDER_RESPONSE_WAIT_SECONDS; i++ )
|
||||
{
|
||||
( void ) xProcessLoop( &xMqttContext );
|
||||
( void ) xProcessLoop( &xMqttContext, 1000 );
|
||||
|
||||
/* xReportStatus is updated in the prvPublishCallback. */
|
||||
if( xReportStatus != ReportStatusNotReceived )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* Wait for sometime between consecutive executions of ProcessLoop. */
|
||||
vTaskDelay( pdMS_TO_TICKS( 1000U ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ eMetricsCollectorStatus eGetOpenTcpPorts( uint16_t * pusOutTcpPortsArray,
|
||||
}
|
||||
}
|
||||
|
||||
return eMetricsCollectorSuccess;
|
||||
return eStatus;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
@ -199,7 +199,7 @@ eMetricsCollectorStatus eGetOpenUdpPorts( uint16_t * pusOutUdpPortsArray,
|
||||
}
|
||||
}
|
||||
|
||||
return eMetricsCollectorSuccess;
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
47
FreeRTOS-Plus/Demo/AWS/Mqtt_Demo_Helpers/mqtt_demo_helpers.c
Executable file → Normal file
47
FreeRTOS-Plus/Demo/AWS/Mqtt_Demo_Helpers/mqtt_demo_helpers.c
Executable file → Normal file
@ -558,9 +558,9 @@ static BaseType_t xHandlePublishResend( MQTTContext_t * pxMqttContext )
|
||||
if( xMQTTStatus != MQTTSuccess )
|
||||
{
|
||||
LogError( ( "Sending duplicate PUBLISH for packet id %u "
|
||||
" failed with status %u.",
|
||||
" failed with status %s.",
|
||||
outgoingPublishPackets[ ucIndex ].packetId,
|
||||
xMQTTStatus ) );
|
||||
MQTT_Status_strerror( xMQTTStatus ) ) );
|
||||
xReturnStatus = pdFAIL;
|
||||
break;
|
||||
}
|
||||
@ -620,7 +620,8 @@ BaseType_t xEstablishMqttSession( MQTTContext_t * pxMqttContext,
|
||||
if( xMQTTStatus != MQTTSuccess )
|
||||
{
|
||||
xReturnStatus = pdFAIL;
|
||||
LogError( ( "MQTT init failed with status %u.", xMQTTStatus ) );
|
||||
LogError( ( "MQTT init failed with status %s.",
|
||||
MQTT_Status_strerror( xMQTTStatus ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -673,7 +674,8 @@ BaseType_t xEstablishMqttSession( MQTTContext_t * pxMqttContext,
|
||||
if( xMQTTStatus != MQTTSuccess )
|
||||
{
|
||||
xReturnStatus = pdFAIL;
|
||||
LogError( ( "Connection with MQTT broker failed with status %u.", xMQTTStatus ) );
|
||||
LogError( ( "Connection with MQTT broker failed with status %s.",
|
||||
MQTT_Status_strerror( xMQTTStatus ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -735,8 +737,8 @@ BaseType_t xDisconnectMqttSession( MQTTContext_t * pxMqttContext,
|
||||
|
||||
if( xMQTTStatus != MQTTSuccess )
|
||||
{
|
||||
LogError( ( "Sending MQTT DISCONNECT failed with status=%u.",
|
||||
xMQTTStatus ) );
|
||||
LogError( ( "Sending MQTT DISCONNECT failed with status=%s.",
|
||||
MQTT_Status_strerror( xMQTTStatus ) ) );
|
||||
xReturnStatus = pdFAIL;
|
||||
}
|
||||
}
|
||||
@ -780,8 +782,8 @@ BaseType_t xSubscribeToTopic( MQTTContext_t * pxMqttContext,
|
||||
|
||||
if( xMQTTStatus != MQTTSuccess )
|
||||
{
|
||||
LogError( ( "Failed to send SUBSCRIBE packet to broker with error = %u.",
|
||||
xMQTTStatus ) );
|
||||
LogError( ( "Failed to send SUBSCRIBE packet to broker with error = %s.",
|
||||
MQTT_Status_strerror( xMQTTStatus ) ) );
|
||||
xReturnStatus = pdFAIL;
|
||||
}
|
||||
else
|
||||
@ -802,8 +804,8 @@ BaseType_t xSubscribeToTopic( MQTTContext_t * pxMqttContext,
|
||||
if( xMQTTStatus != MQTTSuccess )
|
||||
{
|
||||
xReturnStatus = pdFAIL;
|
||||
LogError( ( "MQTT_ProcessLoop returned with status = %u.",
|
||||
xMQTTStatus ) );
|
||||
LogError( ( "MQTT_ProcessLoop returned with status = %s.",
|
||||
MQTT_Status_strerror( xMQTTStatus ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -843,8 +845,8 @@ BaseType_t xUnsubscribeFromTopic( MQTTContext_t * pxMqttContext,
|
||||
|
||||
if( xMQTTStatus != MQTTSuccess )
|
||||
{
|
||||
LogError( ( "Failed to send UNSUBSCRIBE packet to broker with error = %u.",
|
||||
xMQTTStatus ) );
|
||||
LogError( ( "Failed to send UNSUBSCRIBE packet to broker with error = %s.",
|
||||
MQTT_Status_strerror( xMQTTStatus ) ) );
|
||||
xReturnStatus = pdFAIL;
|
||||
}
|
||||
else
|
||||
@ -859,8 +861,8 @@ BaseType_t xUnsubscribeFromTopic( MQTTContext_t * pxMqttContext,
|
||||
if( xMQTTStatus != MQTTSuccess )
|
||||
{
|
||||
xReturnStatus = pdFAIL;
|
||||
LogError( ( "MQTT_ProcessLoop returned with status = %u.",
|
||||
xMQTTStatus ) );
|
||||
LogError( ( "MQTT_ProcessLoop returned with status = %s.",
|
||||
MQTT_Status_strerror( xMQTTStatus ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -913,8 +915,8 @@ BaseType_t xPublishToTopic( MQTTContext_t * pxMqttContext,
|
||||
|
||||
if( xMQTTStatus != MQTTSuccess )
|
||||
{
|
||||
LogError( ( "Failed to send PUBLISH packet to broker with error = %u.",
|
||||
xMQTTStatus ) );
|
||||
LogError( ( "Failed to send PUBLISH packet to broker with error = %s.",
|
||||
MQTT_Status_strerror( xMQTTStatus ) ) );
|
||||
vCleanupOutgoingPublishAt( ucPublishIndex );
|
||||
xReturnStatus = pdFAIL;
|
||||
}
|
||||
@ -935,8 +937,8 @@ BaseType_t xPublishToTopic( MQTTContext_t * pxMqttContext,
|
||||
|
||||
if( xMQTTStatus != MQTTSuccess )
|
||||
{
|
||||
LogWarn( ( "MQTT_ProcessLoop returned with status = %u.",
|
||||
xMQTTStatus ) );
|
||||
LogError( ( "MQTT_ProcessLoop returned with status = %s.",
|
||||
MQTT_Status_strerror( xMQTTStatus ) ) );
|
||||
xReturnStatus = pdFAIL;
|
||||
}
|
||||
}
|
||||
@ -947,17 +949,18 @@ BaseType_t xPublishToTopic( MQTTContext_t * pxMqttContext,
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xProcessLoop( MQTTContext_t * pxMqttContext )
|
||||
BaseType_t xProcessLoop( MQTTContext_t * pxMqttContext,
|
||||
uint32_t ulTimeoutMs )
|
||||
{
|
||||
BaseType_t xReturnStatus = pdFAIL;
|
||||
MQTTStatus_t xMQTTStatus = MQTTSuccess;
|
||||
|
||||
xMQTTStatus = MQTT_ProcessLoop( pxMqttContext, mqttexamplePROCESS_LOOP_TIMEOUT_MS );
|
||||
xMQTTStatus = MQTT_ProcessLoop( pxMqttContext, ulTimeoutMs );
|
||||
|
||||
if( xMQTTStatus != MQTTSuccess )
|
||||
{
|
||||
LogWarn( ( "MQTT_ProcessLoop returned with status = %u.",
|
||||
xMQTTStatus ) );
|
||||
LogError( ( "MQTT_ProcessLoop returned with status = %s.",
|
||||
MQTT_Status_strerror( xMQTTStatus ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -126,10 +126,12 @@ BaseType_t xPublishToTopic( MQTTContext_t * pxMqttContext,
|
||||
* @brief Invoke the core MQTT library's process loop function.
|
||||
*
|
||||
* @param[in] pxMqttContext The MQTT context for the MQTT connection.
|
||||
* @param[in] ulTimeoutMs Minimum time for the loop to run, if no error occurs.
|
||||
*
|
||||
* @return pdPASS if process loop was successful;
|
||||
* pdFAIL otherwise.
|
||||
*/
|
||||
BaseType_t xProcessLoop( MQTTContext_t * pxMqttContext );
|
||||
BaseType_t xProcessLoop( MQTTContext_t * pxMqttContext,
|
||||
uint32_t ulTimeoutMs );
|
||||
|
||||
#endif /* ifndef MQTT_DEMO_HELPERS_H */
|
||||
|
Reference in New Issue
Block a user