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