Cosmetic changes in the MQTT demo - mostly comment updates.

This commit is contained in:
Gaurav Aggarwal 2019-07-24 01:29:01 +00:00
parent fe4511b35e
commit 38b6553abd
5 changed files with 67 additions and 59 deletions

View file

@ -228,10 +228,10 @@ TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;
configASSERT( pxCallbackParams->u.message.info.qos == IOT_MQTT_QOS_1 ); configASSERT( pxCallbackParams->u.message.info.qos == IOT_MQTT_QOS_1 );
/* Although this print uses the constants rather than the data from the /* Although this print uses the constants rather than the data from the
message payload the asserts above have already checked the message payload * message payload the asserts above have already checked the message
equals the constants, and it is more efficient not to have to worry about * payload equals the constants, and it is more efficient not to have to
lengths in the print. */ * worry about lengths in the print. */
configPRINTF( ( "Received %s from topic %s\r\n", mqttexampleMESSAGE, mqttexampleTOPIC ) ); configPRINTF( ( "Received %s on the topic %s\r\n", mqttexampleMESSAGE, mqttexampleTOPIC ) );
/* Inform the demo task about the message received from the MQTT broker. */ /* Inform the demo task about the message received from the MQTT broker. */
xTaskNotify( xDemoTaskHandle, xTaskNotify( xDemoTaskHandle,
@ -258,8 +258,8 @@ void vStartSimpleMQTTDemo( void )
static void prvMQTTDemoTask( void *pvParameters ) static void prvMQTTDemoTask( void *pvParameters )
{ {
IotMqttError_t xResult; IotMqttError_t xResult;
uint32_t ulNotificationValue = 0, ulIterations; uint32_t ulNotificationValue = 0, ulPublishCount;
const uint32_t ulMaxIterations = 5UL; const uint32_t ulMaxPublishCount = 5UL;
const TickType_t xNoDelay = ( TickType_t ) 0; const TickType_t xNoDelay = ( TickType_t ) 0;
/* Remove compiler warnings about unused parameters. */ /* Remove compiler warnings about unused parameters. */
@ -280,7 +280,7 @@ const TickType_t xNoDelay = ( TickType_t ) 0;
configASSERT( ulTaskNotifyTake( pdTRUE, xNoDelay ) == 0 ); configASSERT( ulTaskNotifyTake( pdTRUE, xNoDelay ) == 0 );
/******************** CONNECT ****************************************/ /****************************** Connect. ******************************/
/* Establish a connection to the MQTT broker. This example connects to /* Establish a connection to the MQTT broker. This example connects to
* the MQTT broker as specified in mqttexampleMQTT_BROKER_ENDPOINT and * the MQTT broker as specified in mqttexampleMQTT_BROKER_ENDPOINT and
@ -291,33 +291,34 @@ const TickType_t xNoDelay = ( TickType_t ) 0;
configPRINTF( ( "Connected to %s\r\n", mqttexampleMQTT_BROKER_ENDPOINT ) ); configPRINTF( ( "Connected to %s\r\n", mqttexampleMQTT_BROKER_ENDPOINT ) );
/******************* SUBSCRIBE ***************************************/ /**************************** Subscribe. ******************************/
/* The client is now connected to the broker. Subscribe to the topic /* The client is now connected to the broker. Subscribe to the topic
as specified in mqttexampleTOPIC at the top of this file. This client * as specified in mqttexampleTOPIC at the top of this file. This
will then publish to the same topic it subscribed to, so will expect * client will then publish to the same topic it subscribed to, so will
all the messages it sends to the broker to be sent back to it from the * expect all the messages it sends to the broker to be sent back to it
broker. */ * from the broker. */
prvMQTTSubscribe(); prvMQTTSubscribe();
configPRINTF( ( "Subscribed to %s\r\n", mqttexampleTOPIC ) ); configPRINTF( ( "Subscribed to the topic %s\r\n", mqttexampleTOPIC ) );
/******************* PUBLISH 5 TIMES *********************************/ /*********************** Publish 5 messages. **************************/
/* Publish a few messages while connected. */ /* Publish a few messages while connected. */
for( ulIterations = 0; ulIterations < ulMaxIterations; ulIterations++ ) for( ulPublishCount = 0; ulPublishCount < ulMaxPublishCount; ulPublishCount++ )
{ {
/* Publish a message on the mqttexampleTOPIC topic as specified at the /* Publish a message on the mqttexampleTOPIC topic as specified at
* top of this file. */ * the top of this file. */
prvMQTTPublish(); prvMQTTPublish();
configPRINTF( ( "Published %s to %s\r\n", mqttexampleMESSAGE, mqttexampleTOPIC ) ); configPRINTF( ( "Published %s on the topic %s\r\n", mqttexampleMESSAGE, mqttexampleTOPIC ) );
/* Since we are subscribed on the same topic, we will get the same /* Since we are subscribed to the same topic as we published on, we
* message back from the MQTT broker. Wait for the message to be * will get the same message back from the MQTT broker. Wait for the
* received which is informed to us by the publish callback * message to be received which is informed to us by the publish
* (prvExample_OnMessageReceived) by setting the * callback (prvExample_OnMessageReceived) by setting the
* mqttexampleMESSAGE_RECEIVED_BIT in this task's notification * mqttexampleMESSAGE_RECEIVED_BIT in this task's notification
value. */ * value. Note that the bit is cleared in the task's notification
* value to ensure that it is ready for next message. */
xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */ xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */
mqttexampleMESSAGE_RECEIVED_BIT, /* Clear bit on exit. */ mqttexampleMESSAGE_RECEIVED_BIT, /* Clear bit on exit. */
&( ulNotificationValue ), /* Obtain the notification value. */ &( ulNotificationValue ), /* Obtain the notification value. */
@ -326,27 +327,25 @@ const TickType_t xNoDelay = ( TickType_t ) 0;
} }
/******************* UNSUBSCRIBE AND DISCONNECT **********************/ /******************* Unsubscribe and Disconnect. **********************/
/* Unsubscribe from the topic mqttexampleTOPIC the disconnect /* Unsubscribe from the topic mqttexampleTOPIC and disconnect
gracefully. */ * gracefully. */
prvMQTTUnsubscribe(); prvMQTTUnsubscribe();
prvMQTTDisconnect(); prvMQTTDisconnect();
configPRINTF( ( "Disconnected from from %s\r\n\r\n", mqttexampleMQTT_BROKER_ENDPOINT ) ); configPRINTF( ( "Disconnected from %s\r\n\r\n", mqttexampleMQTT_BROKER_ENDPOINT ) );
/* Wait for the disconnect operation to complete which is informed to us /* Wait for the disconnect operation to complete which is informed to us
* by the disconnect callback (prvExample_OnDisconnect)by setting * by the disconnect callback (prvExample_OnDisconnect)by setting
* the mqttexampleDISCONNECTED_BIT in this task's notification value. * the mqttexampleDISCONNECTED_BIT in this task's notification value.
* Note that all bits are cleared in the task's notification value to * Note that the bit is cleared in the task's notification value to
* ensure that it is ready for the next run. */ * ensure that it is ready for the next run. */
xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */ xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */
mqttexampleDISCONNECTED_BIT, /* Clear bit again on exit. */ mqttexampleDISCONNECTED_BIT, /* Clear bit on exit. */
&( ulNotificationValue ), /* Obtain the notification value. */ &( ulNotificationValue ), /* Obtain the notification value. */
pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) ); pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );
configASSERT( ( ulNotificationValue & mqttexampleDISCONNECTED_BIT ) == mqttexampleDISCONNECTED_BIT ); configASSERT( ( ulNotificationValue & mqttexampleDISCONNECTED_BIT ) == mqttexampleDISCONNECTED_BIT );
/* Wait for some time between two iterations to ensure that we do not /* Wait for some time between two iterations to ensure that we do not
* bombard the public test mosquitto broker. */ * bombard the public test mosquitto broker. */
configPRINTF( ( "prvMQTTDemoTask() completed an iteration without hitting an assert. Total free heap is %u\r\n\r\n", xPortGetFreeHeapSize() ) ); configPRINTF( ( "prvMQTTDemoTask() completed an iteration without hitting an assert. Total free heap is %u\r\n\r\n", xPortGetFreeHeapSize() ) );
@ -362,11 +361,15 @@ IotNetworkServerInfo_t xMQTTBrokerInfo;
IotMqttNetworkInfo_t xNetworkInfo = IOT_MQTT_NETWORK_INFO_INITIALIZER; IotMqttNetworkInfo_t xNetworkInfo = IOT_MQTT_NETWORK_INFO_INITIALIZER;
IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER; IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;
/******************* Broker information setup. **********************/ /******************* Broker information setup. **********************/
xMQTTBrokerInfo.pHostName = mqttexampleMQTT_BROKER_ENDPOINT; xMQTTBrokerInfo.pHostName = mqttexampleMQTT_BROKER_ENDPOINT;
xMQTTBrokerInfo.port = mqttexampleMQTT_BROKER_PORT; xMQTTBrokerInfo.port = mqttexampleMQTT_BROKER_PORT;
/******************* Network information setup. **********************/ /******************* Network information setup. **********************/
/* No connection to the MQTT broker has been established yet and we want to /* No connection to the MQTT broker has been established yet and we want to
* establish a new connection. */ * establish a new connection. */
xNetworkInfo.createNetworkConnection = true; xNetworkInfo.createNetworkConnection = true;
@ -379,13 +382,17 @@ IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;
/* Use FreeRTOS+TCP network. */ /* Use FreeRTOS+TCP network. */
xNetworkInfo.pNetworkInterface = IOT_NETWORK_INTERFACE_FREERTOS; xNetworkInfo.pNetworkInterface = IOT_NETWORK_INTERFACE_FREERTOS;
/* Setup the callback which is called when the MQTT connection is disconnected. */ /* Setup the callback which is called when the MQTT connection is
xNetworkInfo.disconnectCallback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();//_RB_ Why the task handle? * disconnected. The task handle is passed as the callback context which
* is used by the callback to send a task notification to this task.*/
xNetworkInfo.disconnectCallback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();
xNetworkInfo.disconnectCallback.function = prvExample_OnDisconnect; xNetworkInfo.disconnectCallback.function = prvExample_OnDisconnect;
/****************** MQTT Connection information setup. ********************/ /****************** MQTT Connection information setup. ********************/
/* Set this flag to true if connecting to the AWS IoT MQTT broker. This /* Set this flag to true if connecting to the AWS IoT MQTT broker. This
example does not use TLS and therefore won't work with AWS IoT. */ * example does not use TLS and therefore won't work with AWS IoT. */
xConnectInfo.awsIotMqttMode = false; xConnectInfo.awsIotMqttMode = false;
/* Start with a clean session i.e. direct the MQTT broker to discard any /* Start with a clean session i.e. direct the MQTT broker to discard any
@ -404,12 +411,12 @@ IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;
xConnectInfo.pWillInfo = NULL; xConnectInfo.pWillInfo = NULL;
/* Send an MQTT PING request every minute to keep the connection open if /* Send an MQTT PING request every minute to keep the connection open if
there is no other MQTT trafic. */ there is no other MQTT traffic. */
xConnectInfo.keepAliveSeconds = mqttexampleKEEP_ALIVE_SECONDS; xConnectInfo.keepAliveSeconds = mqttexampleKEEP_ALIVE_SECONDS;
/* The client identifier is used to uniquely identify this MQTT client to /* The client identifier is used to uniquely identify this MQTT client to
* the MQTT broker. In a production device the identifier can be something * the MQTT broker. In a production device the identifier can be something
unique, such as a device serial number. */ * unique, such as a device serial number. */
xConnectInfo.pClientIdentifier = mqttexampleCLIENT_IDENTIFIER; xConnectInfo.pClientIdentifier = mqttexampleCLIENT_IDENTIFIER;
xConnectInfo.clientIdentifierLength = ( uint16_t ) strlen( mqttexampleCLIENT_IDENTIFIER ); xConnectInfo.clientIdentifierLength = ( uint16_t ) strlen( mqttexampleCLIENT_IDENTIFIER );
@ -421,7 +428,7 @@ IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;
xConnectInfo.passwordLength = 0; xConnectInfo.passwordLength = 0;
/* Establish the connection to the MQTT broker - It is a blocking call and /* Establish the connection to the MQTT broker - It is a blocking call and
will return only when connection is complete or a timeout occurrs. */ will return only when connection is complete or a timeout occurs. */
xResult = IotMqtt_Connect( &( xNetworkInfo ), xResult = IotMqtt_Connect( &( xNetworkInfo ),
&( xConnectInfo ), &( xConnectInfo ),
mqttexampleMQTT_TIMEOUT_MS, mqttexampleMQTT_TIMEOUT_MS,
@ -435,7 +442,9 @@ static void prvMQTTSubscribe( void )
IotMqttError_t xResult; IotMqttError_t xResult;
IotMqttSubscription_t xMQTTSubscription; IotMqttSubscription_t xMQTTSubscription;
/* Subscribe to the mqttexampleTOPIC topic filter. */ /* Subscribe to the mqttexampleTOPIC topic filter. The task handle is passed
* as the callback context which is used by the callback to send a task
* notification to this task.*/
xMQTTSubscription.qos = IOT_MQTT_QOS_1; xMQTTSubscription.qos = IOT_MQTT_QOS_1;
xMQTTSubscription.pTopicFilter = mqttexampleTOPIC; xMQTTSubscription.pTopicFilter = mqttexampleTOPIC;
xMQTTSubscription.topicFilterLength = ( uint16_t ) strlen( mqttexampleTOPIC ); xMQTTSubscription.topicFilterLength = ( uint16_t ) strlen( mqttexampleTOPIC );
@ -443,7 +452,7 @@ IotMqttSubscription_t xMQTTSubscription;
xMQTTSubscription.callback.function = prvExample_OnMessageReceived; xMQTTSubscription.callback.function = prvExample_OnMessageReceived;
/* Use the synchronous API to subscribe - It is a blocking call and only /* Use the synchronous API to subscribe - It is a blocking call and only
* returns when the subscribe operation is complete. */ * returns when the subscribe operation is complete or a timeout occurs. */
xResult = IotMqtt_TimedSubscribe( xMQTTConnection, xResult = IotMqtt_TimedSubscribe( xMQTTConnection,
&( xMQTTSubscription ), &( xMQTTSubscription ),
1, /* We are subscribing to one topic filter. */ 1, /* We are subscribing to one topic filter. */
@ -471,7 +480,7 @@ IotMqttPublishInfo_t xMQTTPublishInfo;
xMQTTPublishInfo.retryLimit = mqttexamplePUBLISH_RETRY_LIMIT; xMQTTPublishInfo.retryLimit = mqttexamplePUBLISH_RETRY_LIMIT;
/* Use the synchronous API to publish - It is a blocking call and only /* Use the synchronous API to publish - It is a blocking call and only
* returns when the publish operation is complete. */ * returns when the publish operation is complete or a timeout occurs. */
xResult = IotMqtt_TimedPublish( xMQTTConnection, xResult = IotMqtt_TimedPublish( xMQTTConnection,
&( xMQTTPublishInfo ), &( xMQTTPublishInfo ),
0, /* flags - currently ignored. */ 0, /* flags - currently ignored. */
@ -496,7 +505,7 @@ IotMqttSubscription_t xMQTTSubscription;
xMQTTSubscription.callback.function = NULL; xMQTTSubscription.callback.function = NULL;
/* Use the synchronous API to unsubscribe - It is a blocking call and only /* Use the synchronous API to unsubscribe - It is a blocking call and only
* returns when the unsubscribe operation is complete. */ * returns when the unsubscribe operation is complete or a timeout occurs. */
xResult = IotMqtt_TimedUnsubscribe( xMQTTConnection, xResult = IotMqtt_TimedUnsubscribe( xMQTTConnection,
&( xMQTTSubscription ), &( xMQTTSubscription ),
1, /* We are unsubscribing from one topic filter. */ 1, /* We are unsubscribing from one topic filter. */

View file

@ -138,7 +138,7 @@ configNETWORK_INTERFACE_TO_USE to 2 results in the wireless network being
used. */ used. */
#define configNETWORK_INTERFACE_TO_USE 3L #define configNETWORK_INTERFACE_TO_USE 3L
/* The address of an echo server is only left in this project as it douples as /* The address of an echo server is only left in this project as it doubles as
the address to which logging is sent should UDP logging be enabled. */ the address to which logging is sent should UDP logging be enabled. */
#define configECHO_SERVER_ADDR0 192 #define configECHO_SERVER_ADDR0 192
#define configECHO_SERVER_ADDR1 168 #define configECHO_SERVER_ADDR1 168

View file

@ -44,7 +44,7 @@ extern void vLoggingPrintf( const char *pcFormatString, ... );
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to /* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
1 then FreeRTOS_debug_printf should be defined to the function used to print 1 then FreeRTOS_debug_printf should be defined to the function used to print
out the debugging messages. */ out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1 #define ipconfigHAS_DEBUG_PRINTF 0
#if( ipconfigHAS_DEBUG_PRINTF == 1 ) #if( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf(X) vLoggingPrintf X #define FreeRTOS_debug_printf(X) vLoggingPrintf X
#endif #endif

View file

@ -58,14 +58,15 @@
*/ */
#define IOT_TASKPOOL_ENABLE_ASSERTS 1 #define IOT_TASKPOOL_ENABLE_ASSERTS 1
/* /**
* @brief The numer of worker tasks in the task pool.
*
* The full IoT Task Pool Library has many use cases, including Linux * The full IoT Task Pool Library has many use cases, including Linux
* development.  Typical FreeRTOS use cases do not require the full * development. Typical FreeRTOS use cases do not require the full
* functionality so an optimised implementation is provided specifically for use * functionality so an optimized implementation is provided specifically for use
* with FreeRTOS. The optimised version has a fixed number of tasks in the * with FreeRTOS. The optimized version has a fixed number of tasks in the
* pool, each of which uses statically allocated memory to ensure creation of * task pool, each of which uses statically allocated memory to ensure creation
* the pool is guaranteed (it does not run out of heap space). * of the task pool is guaranteed (it does not run out of heap space).
* IOT_TASKPOOL_NUMBER_OF_WORKERS sets the number of tasks in the pool.
*/ */
#define IOT_TASKPOOL_NUMBER_OF_WORKERS 3 #define IOT_TASKPOOL_NUMBER_OF_WORKERS 3
@ -104,11 +105,10 @@
*/ */
#define AWS_IOT_MQTT_ENABLE_METRICS 0 #define AWS_IOT_MQTT_ENABLE_METRICS 0
/* /**
* @brief Set the log level of the task pool library. * @brief Set the log level of the MQTT library.
* *
* Log messages from the task pool library at or below this setting will be * Log messages from the MQTT library at or below this setting will be printed.
* printed.
* *
* Possible values: One of the Log levels. * Possible values: One of the Log levels.
* Default value (if undefined): IOT_LOG_LEVEL_GLOBAL; if that is undefined, * Default value (if undefined): IOT_LOG_LEVEL_GLOBAL; if that is undefined,

View file

@ -353,5 +353,4 @@ void vApplicationGetTimerTaskMemory( StaticTask_t** ppxTimerTaskTCBBuffer, Stack
configMINIMAL_STACK_SIZE is specified in words, not bytes. */ configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
} }
/*-----------------------------------------------------------*/