]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleMQTTExamples.c
The MQTT example now works with the local MQTT broker.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_IoT_Libraries / mqtt / DemoTasks / SimpleMQTTExamples.c
index d0c9e0b6e7fe3b8428b0825877065c112ae7fbb5..648999eb6654a5a9d7a714d33626c0bbd7d69713 100644 (file)
 \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
-/* MQTT include. */\r
+/* IoT SDK includes. */\r
 #include "iot_mqtt.h"\r
-\r
-/* Platform FreeRTOS network include. */\r
+#include "iot_taskpool.h"\r
 #include "platform/iot_network_freertos.h"\r
 \r
 /**\r
@@ -59,8 +59,9 @@
  * @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                "10.60.214.105"\r
+#define mqttexampleMQTT_BROKER_ENDPOINT                "test.mosquitto.org"\r
 #define mqttexampleMQTT_BROKER_PORT                    1883\r
 \r
 /**\r
  * @brief The MQTT connection handle used in this example.\r
  */\r
 static IotMqttConnection_t xMQTTConnection = IOT_MQTT_CONNECTION_INITIALIZER;\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
@@ -231,6 +258,10 @@ const TickType_t xNoDelay = ( TickType_t ) 0;
        /* 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
@@ -284,6 +315,13 @@ const TickType_t xNoDelay = ( TickType_t ) 0;
                                                 &( ulNotificationValue ), /* Obtain the notification value. */\r
                                                 pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );\r
                configASSERT( ( ulNotificationValue & mqttexampleDISCONNECTED_BIT ) == mqttexampleDISCONNECTED_BIT );\r
+\r
+               printf( "prvMQTTDemoTask() completed an iteration without hitting an assert.\r\n" );\r
+               fflush( stdout );\r
+\r
+               /* Wait for some time between two iterations to ensure that we do not\r
+                * bombard the public test mosquitto broker. */\r
+               vTaskDelay( pdMS_TO_TICKS( 5000 ) );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r