]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleMQTTExamples.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_IoT_Libraries / mqtt / DemoTasks / SimpleMQTTExamples.c
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleMQTTExamples.c b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleMQTTExamples.c
deleted file mode 100644 (file)
index 80a0416..0000000
+++ /dev/null
@@ -1,548 +0,0 @@
-/*\r
- * FreeRTOS Kernel V10.2.1\r
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
- * this software and associated documentation files (the "Software"), to deal in\r
- * the Software without restriction, including without limitation the rights to\r
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
- * the Software, and to permit persons to whom the Software is furnished to do so,\r
- * subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included in all\r
- * copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- *\r
- * http://www.FreeRTOS.org\r
- * http://aws.amazon.com/freertos\r
- *\r
- * 1 tab == 4 spaces!\r
- */\r
-\r
-/* Standard inclues. */\r
-#include <string.h>\r
-#include <stdio.h>\r
-\r
-/* Kernel includes. */\r
-#include "FreeRTOS.h"\r
-#include "task.h"\r
-\r
-/* IoT SDK includes. */\r
-#include "iot_mqtt.h"\r
-#include "iot_taskpool.h"\r
-#include "platform/iot_network_freertos.h"\r
-\r
-/**\r
- * @brief The keep-alive interval used for this example.\r
- *\r
- * An MQTT ping request will be sent periodically at this interval.\r
- */\r
-#define mqttexampleKEEP_ALIVE_SECONDS          ( 60 )\r
-\r
-/**\r
- * @brief The timeout for MQTT operations in this example.\r
- */\r
-#define mqttexampleMQTT_TIMEOUT_MS                     ( 50000 )\r
-\r
-/**\r
- * @brief The MQTT client identifier used in this example.\r
- */\r
-#define mqttexampleCLIENT_IDENTIFIER           "mqttexampleclient"\r
-\r
-const char *pcClientIdentifiers[] = { "AAA" };//, "BBB", "CCC", "DDD", "EEE", "FFF", "GGG", "HHH", "III", "JJJ" };\r
-\r
-/**\r
- * @brief Details of the MQTT broker to connect to.\r
- *\r
- * @note This example does not use TLS and therefore won't work with AWS IoT.\r
- *\r
- */\r
-#define mqttexampleMQTT_BROKER_ENDPOINT                "test.mosquitto.org"\r
-#define mqttexampleMQTT_BROKER_PORT                    1883\r
-\r
-/**\r
- * @brief The topic to subscribe and publish to in the example.\r
- */\r
-#define mqttexampleTOPIC                                       "example/topic"\r
-\r
-/**\r
- * @brief The MQTT message published in this example.\r
- */\r
-#define mqttexampleMESSAGE                                     "Hello World!"\r
-\r
-/**\r
- * @brief Paramters to control the retry behaviour in case a QoS1 publish\r
- * message gets lost.\r
- *\r
- * Retry every minutes up to a maximum of 5 retries.\r
- */\r
-#define mqttexamplePUBLISH_RETRY_MS                    ( 1000 )\r
-#define mqttexamplePUBLISH_RETRY_LIMIT         ( 5 )\r
-\r
-/**\r
- * @brief The bit which is set in the demo task's notification value from the\r
- * disconnect callback to inform the demo task about the MQTT disconnect.\r
- */\r
-#define mqttexampleDISCONNECTED_BIT                    ( 1UL << 0UL )\r
-\r
-/**\r
- * @brief The bit which is set in the demo task's notification value from the\r
- * publish callback to inform the demo task about the message received from the\r
- * MQTT broker.\r
- */\r
-#define mqttexampleMESSAGE_RECEIVED_BIT                ( 1UL << 1UL )\r
-/*-----------------------------------------------------------*/\r
-\r
-/**\r
- * @brief Parameters used to create the system task pool.\r
- */\r
-static const IotTaskPoolInfo_t xTaskPoolParameters = {\r
-                                                                                                               /* Minimum number of threads in a task pool.\r
-                                                                                                                * Note the slimmed down version of the task\r
-                                                                                                                * pool used by this library does not autoscale\r
-                                                                                                                * the number of tasks in the pool so in this\r
-                                                                                                                * case this sets the number of tasks in the\r
-                                                                                                                * pool. */\r
-                                                                                                               2,\r
-                                                                                                               /* Maximum number of threads in a task pool.\r
-                                                                                                                * Note the slimmed down version of the task\r
-                                                                                                                * pool used by this library does not autoscale\r
-                                                                                                                * the number of tasks in the pool so in this\r
-                                                                                                                * case this parameter is just ignored. */\r
-                                                                                                               2,\r
-                                                                                                               /* Stack size for every task pool thread - in\r
-                                                                                                                * bytes, hence multiplying by the number of bytes\r
-                                                                                                                * in a word as configMINIMAL_STACK_SIZE is\r
-                                                                                                                * specified in words. */\r
-                                                                                                               configMINIMAL_STACK_SIZE * sizeof( portSTACK_TYPE ),\r
-                                                                                                               /* Priority for every task pool thread. */\r
-                                                                                                               tskIDLE_PRIORITY,\r
-                                                                                                        };\r
-/*-----------------------------------------------------------*/\r
-\r
-/**\r
- * @brief The task used to demonstrate the MQTT API.\r
- *\r
- * @param[in] pvParameters Parmaters as passed at the time of task creation. Not\r
- * used in this example.\r
- */\r
-static void prvMQTTDemoTask( void *pvParameters );\r
-\r
-/**\r
- * @brief The callback invoked by the MQTT library when the MQTT connection gets\r
- * disconnected.\r
- *\r
- * @param[in] pvCallbackContext Callback context as provided at the time of\r
- * connect.\r
- * @param[in] pxCallbackParams Contains the reason why the MQTT connection was\r
- * disconnected.\r
- */\r
-static void prvExample_OnDisconnect( void * pvCallbackContext,\r
-                                                                        IotMqttCallbackParam_t * pxCallbackParams );\r
-\r
-/**\r
- * @brief The callback invoked by the MQTT library when a message is received on\r
- * a subscribed topic from the MQTT broker.\r
- *\r
- * @param[in] pvCallbackContext Callback context as provided at the time of\r
- * subscribe.\r
- * @param[in] pxCallbackParams Contain the details about the received message -\r
- * topic on which the message was received, the received message.\r
- */\r
-static void prvExample_OnMessageReceived( void * pvCallbackContext,\r
-                                                                                 IotMqttCallbackParam_t * pxCallbackParams );\r
-\r
-/**\r
- * @brief Connects to the MQTT broker as specified in mqttexampleMQTT_BROKER_ENDPOINT\r
- * and mqttexampleMQTT_BROKER_PORT.\r
- *\r
- * @note This example does not use TLS and therefore will not work with MQTT.\r
- */\r
-static void prvMQTTConnect( IotMqttConnection_t *xMQTTConnection, const char *pcClientID );\r
-\r
-/**\r
- * @brief Subscribes to pcTopicString.\r
- */\r
-static void prvMQTTSubscribe( IotMqttConnection_t xMQTTConnection, const char * const pcTopicString );\r
-\r
-/**\r
- * @brief Publishes a messages mqttexampleMESSAGE on mqttexampleTOPIC topic.\r
- */\r
-static void prvMQTTPublish( IotMqttConnection_t xMQTTConnection, const char * const pcTopicString );\r
-\r
-/**\r
- * @brief Unsubscribes from the mqttexampleTOPIC topic.\r
- */\r
-static void prvMQTTUnsubscribe( IotMqttConnection_t xMQTTConnection, const char * const pcTopicString );\r
-\r
-/**\r
- * @brief Disconnects from the MQTT broker gracefully by sending an MQTT\r
- * DISCONNECT message.\r
- */\r
-static void prvMQTTDisconnect( IotMqttConnection_t xMQTTConnection );\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvExample_OnDisconnect( void * pvCallbackContext,\r
-                                                                                  IotMqttCallbackParam_t * pxCallbackParams )\r
-{\r
-TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;\r
-\r
-       /* Ensure that we initiated the disconnect. */\r
-       configASSERT( pxCallbackParams->u.disconnectReason == IOT_MQTT_DISCONNECT_CALLED );\r
-\r
-       /* Inform the demo task about the disconnect. */\r
-       xTaskNotify( xDemoTaskHandle,\r
-                               mqttexampleDISCONNECTED_BIT,\r
-                               eSetBits /* Set the mqttexampleDISCONNECTED_BIT in the demo task's notification value. */\r
-                               );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvExample_OnMessageReceived( void * pvCallbackContext,\r
-                                                                               IotMqttCallbackParam_t * pxCallbackParams )\r
-{\r
-TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;\r
-\r
-       /* Ensure that the message is received on the expected topic. */\r
-//     configASSERT( pxCallbackParams->u.message.info.topicNameLength == strlen( mqttexampleTOPIC ) );\r
-//     configASSERT( strncmp( pxCallbackParams->u.message.info.pTopicName,\r
-//                                                mqttexampleTOPIC,\r
-//                                                strlen( mqttexampleTOPIC ) ) == 0 );\r
-\r
-       /* Ensure that the expected message is received. */\r
-       configASSERT( pxCallbackParams->u.message.info.payloadLength == strlen( mqttexampleMESSAGE ) );\r
-       configASSERT( strncmp( pxCallbackParams->u.message.info.pPayload,\r
-                                                  mqttexampleMESSAGE,\r
-                                                  strlen( mqttexampleMESSAGE ) ) == 0 );\r
-\r
-       /* Ensure that the message QoS is as expected. */\r
-       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\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
-                                mqttexampleMESSAGE_RECEIVED_BIT,\r
-                                eSetBits /* Set the mqttexampleMESSAGE_RECEIVED_BIT in the demo task's notification value. */\r
-                               );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vStartSimpleMQTTDemo( void )\r
-{\r
-uint32_t x;\r
-const uint32_t ulMax_x = sizeof( pcClientIdentifiers ) / sizeof( char * );\r
-\r
-       /* This example uses a single application task, which in turn is used to\r
-        * connect, subscribe, publish, unsubscribe and disconnect from the MQTT\r
-        * broker. */\r
-for( x = 0; x < ulMax_x; x++ )\r
-{\r
-       xTaskCreate( prvMQTTDemoTask,                   /* Function that implements the task. */\r
-                                "MQTTDemo",                            /* Text name for the task - only used for debugging. */\r
-                                configMINIMAL_STACK_SIZE,      /* Size of stack (in words, not bytes) to allocate for the task. */\r
-                                ( void * ) x,                                          /* Task parameter - not used in this case. */\r
-                                tskIDLE_PRIORITY,                      /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */\r
-                                NULL );                                        /* Used to pass out a handle to the created task - not used in this case. */\r
-}\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvMQTTDemoTask( void *pvParameters )\r
-{\r
-IotMqttError_t xResult;\r
-uint32_t ulNotificationValue = 0, ulPublishCount;\r
-uint32_t ulMaxPublishCount = 0UL;\r
-const TickType_t xNoDelay = ( TickType_t ) 1;\r
-IotMqttConnection_t xMQTTConnection = IOT_MQTT_CONNECTION_INITIALIZER;\r
-uint32_t ulTaskNumber = ( uint32_t ) pvParameters, x;\r
-char cTopicString[ sizeof( mqttexampleTOPIC ) + 5 ];//_RB_ Access by other tasks so must be persistant and will cause memory faults on memory protected systems.\r
-#pragma message ("Access by other tasks so must be persistant and will cause memory faults on memory protected systems.")\r
-\r
-       /* Remove compiler warnings about unused parameters. */\r
-       ( void ) pvParameters;\r
-\r
-       /* The MQTT library needs a task pool, so create the system task pool. */\r
-       xResult = IotTaskPool_CreateSystemTaskPool( &( xTaskPoolParameters ) );\r
-       configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
-       /* MQTT library must be initialized before it can be used. This is just one\r
-        * time initialization. */\r
-       xResult = IotMqtt_Init();\r
-       configASSERT( xResult == IOT_MQTT_SUCCESS );\r
-\r
-       /* Create a topic string that is unique to the MQTT connection created by\r
-       this task. */\r
-       snprintf( cTopicString, sizeof( cTopicString ), "%s/%s", mqttexampleTOPIC, pcClientIdentifiers[ ulTaskNumber ] );\r
-\r
-       for( ; ; )\r
-       {\r
-               /* Don't expect any notifications to be pending yet. */\r
-               ulNotificationValue = ulTaskNotifyTake( pdTRUE, xNoDelay );\r
-               configASSERT( ulNotificationValue == 0 );\r
-\r
-\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
-                * mqttexampleMQTT_BROKER_PORT at the top of this file. Please change\r
-                * it to the MQTT broker you want to connect to. Note that this example\r
-                * does not use TLS and therefore will not work with AWS IoT. */\r
-               prvMQTTConnect( &xMQTTConnection, pcClientIdentifiers[ ulTaskNumber ] );\r
-               configPRINTF( ( "Connected to %s\r\n", mqttexampleMQTT_BROKER_ENDPOINT ) );\r
-\r
-\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\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( xMQTTConnection, cTopicString );\r
-               configPRINTF( ( "Subscribed to the topic %s\r\n", cTopicString ) );\r
-\r
-\r
-               /*********************** Publish 5 messages. **************************/\r
-\r
-               /* Publish a few messages while connected. */\r
-               for( x = 0; x < ( ulTaskNumber + 1UL ); x++ )\r
-               {\r
-                       ulMaxPublishCount = uxRand();\r
-               }\r
-\r
-               /* Cap ulMaxPublishCount but ensure it is not zero. */\r
-               ulMaxPublishCount %= 10UL;\r
-               ulMaxPublishCount++;\r
-\r
-               for( ulPublishCount = 0; ulPublishCount < ulMaxPublishCount; ulPublishCount++ )\r
-               {\r
-                       /* Publish a message on the mqttexampleTOPIC topic as specified at\r
-                        * the top of this file. */\r
-                       prvMQTTPublish( xMQTTConnection, cTopicString );\r
-                       configPRINTF( ( "Published %s on the topic %s\r\n", mqttexampleMESSAGE, cTopicString ) );\r
-\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. 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
-                                                        pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );\r
-                       configASSERT( ( ulNotificationValue & mqttexampleMESSAGE_RECEIVED_BIT ) == mqttexampleMESSAGE_RECEIVED_BIT );\r
-               }\r
-\r
-\r
-               /******************* Unsubscribe and Disconnect. **********************/\r
-\r
-               /* Unsubscribe from the topic mqttexampleTOPIC and disconnect\r
-                * gracefully. */\r
-               prvMQTTUnsubscribe( xMQTTConnection, cTopicString );\r
-               prvMQTTDisconnect( xMQTTConnection );\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 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 on exit. */\r
-                                                &( ulNotificationValue ), /* Obtain the notification value. */\r
-                                                pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );\r
-               configASSERT( ( ulNotificationValue & mqttexampleDISCONNECTED_BIT ) == mqttexampleDISCONNECTED_BIT );\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
-//             vTaskDelay( pdMS_TO_TICKS( 5000 ) );\r
-       }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvMQTTConnect( IotMqttConnection_t *xMQTTConnection, const char *pcClientID )\r
-{\r
-IotMqttError_t xResult;\r
-IotNetworkServerInfo_t xMQTTBrokerInfo;\r
-IotMqttNetworkInfo_t xNetworkInfo = IOT_MQTT_NETWORK_INFO_INITIALIZER;\r
-IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;\r
-static char c[ 10 ];\r
-static int id = 0;\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
-       xNetworkInfo.u.setup.pNetworkServerInfo = &( xMQTTBrokerInfo );\r
-\r
-       /* This example does not use TLS and therefore pNetworkCredentialInfo must\r
-        * be set to NULL. */\r
-       xNetworkInfo.u.setup.pNetworkCredentialInfo = NULL;\r
-\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\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
-\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
-        * previous session data. Also, establishing a connection with clean session\r
-        * will ensure that the broker does not store any data when this client\r
-        * gets disconnected. */\r
-       xConnectInfo.cleanSession = true;\r
-\r
-       /* Since we are starting with a clean session, there are no previous\r
-        * subscriptions to be restored. */\r
-       xConnectInfo.pPreviousSubscriptions = NULL;\r
-       xConnectInfo.previousSubscriptionCount = 0;\r
-\r
-       /* We do not want to publish Last Will and Testament (LWT) message if the\r
-        * client gets disconnected. */\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 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
-       xConnectInfo.pClientIdentifier = pcClientID;\r
-       xConnectInfo.clientIdentifierLength = ( uint16_t ) strlen( pcClientID );\r
-\r
-       /* This example does not use any authentication and therefore username and\r
-        * password fields are not used. */\r
-       xConnectInfo.pUserName = NULL;\r
-       xConnectInfo.userNameLength = 0;\r
-       xConnectInfo.pPassword = NULL;\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 occurs. */\r
-       xResult = IotMqtt_Connect( &( xNetworkInfo ),\r
-                                                          &( xConnectInfo ),\r
-                                                          mqttexampleMQTT_TIMEOUT_MS,\r
-                                                          xMQTTConnection );\r
-       configASSERT( xResult == IOT_MQTT_SUCCESS );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvMQTTSubscribe( IotMqttConnection_t xMQTTConnection, const char * const pcTopicString )\r
-{\r
-IotMqttError_t xResult;\r
-IotMqttSubscription_t xMQTTSubscription;\r
-\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 = pcTopicString;\r
-       xMQTTSubscription.topicFilterLength = ( uint16_t ) strlen( pcTopicString );\r
-       xMQTTSubscription.callback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();\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 or a timeout occurs. */\r
-       xResult = IotMqtt_TimedSubscribe( xMQTTConnection,\r
-                                                                         &( xMQTTSubscription ),\r
-                                                                         1, /* We are subscribing to one topic filter. */\r
-                                                                         0, /* flags - currently ignored. */\r
-                                                                         mqttexampleMQTT_TIMEOUT_MS );\r
-       configASSERT( xResult == IOT_MQTT_SUCCESS );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvMQTTPublish( IotMqttConnection_t xMQTTConnection, const char * const pcTopicString )\r
-{\r
-IotMqttError_t xResult;\r
-IotMqttPublishInfo_t xMQTTPublishInfo;\r
-\r
-       /* Publish a message with QoS1 on the mqttexampleTOPIC topic. Since we are\r
-        * subscribed to the same topic, the MQTT broker will send the same message\r
-        * back to us. It is verified in the publish callback. */\r
-       xMQTTPublishInfo.qos = IOT_MQTT_QOS_1;\r
-       xMQTTPublishInfo.retain = false;\r
-       xMQTTPublishInfo.pTopicName = pcTopicString;\r
-       xMQTTPublishInfo.topicNameLength = ( uint16_t ) strlen( pcTopicString );\r
-       xMQTTPublishInfo.pPayload = mqttexampleMESSAGE;\r
-       xMQTTPublishInfo.payloadLength = strlen( mqttexampleMESSAGE );\r
-       xMQTTPublishInfo.retryMs = mqttexamplePUBLISH_RETRY_MS;\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 or a timeout occurs. */\r
-       xResult = IotMqtt_TimedPublish( xMQTTConnection,\r
-                                                                       &( xMQTTPublishInfo ),\r
-                                                                       0, /* flags - currently ignored. */\r
-                                                                       mqttexampleMQTT_TIMEOUT_MS );\r
-       configASSERT( xResult == IOT_MQTT_SUCCESS );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvMQTTUnsubscribe( IotMqttConnection_t xMQTTConnection, const char * const pcTopicString )\r
-{\r
-IotMqttError_t xResult;\r
-IotMqttSubscription_t xMQTTSubscription;\r
-\r
-       /* Unsubscribe from the mqttexampleTOPIC topic filter. */\r
-       xMQTTSubscription.pTopicFilter = pcTopicString;\r
-       xMQTTSubscription.topicFilterLength = ( uint16_t ) strlen( pcTopicString );\r
-       /* The following members of the IotMqttSubscription_t are ignored by the\r
-        * unsubscribe operation. Just initialize them to avoid "use of uninitialized\r
-        * variable" warnings. */\r
-       xMQTTSubscription.qos = IOT_MQTT_QOS_1;\r
-       xMQTTSubscription.callback.pCallbackContext = NULL;\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 or a timeout occurs. */\r
-       xResult = IotMqtt_TimedUnsubscribe( xMQTTConnection,\r
-                                                                               &( xMQTTSubscription ),\r
-                                                                               1, /* We are unsubscribing from one topic filter. */\r
-                                                                               0, /* flags - currently ignored. */\r
-                                                                               mqttexampleMQTT_TIMEOUT_MS );\r
-       configASSERT( xResult == IOT_MQTT_SUCCESS );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvMQTTDisconnect( IotMqttConnection_t xMQTTConnection )\r
-{\r
-       /* Send a MQTT DISCONNECT packet to the MQTT broker to do a graceful\r
-        * disconnect. */\r
-       IotMqtt_Disconnect( xMQTTConnection,\r
-                                               0 /* flags - 0 means a graceful disconnect by sending MQTT DISCONNECT. */\r
-                                               );\r
-}\r
-/*-----------------------------------------------------------*/\r