]> git.sur5r.net Git - freertos/commitdiff
The MQTT example now works with the local MQTT broker.
authorgaurav-aws <gaurav-aws@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 21 Jul 2019 23:26:54 +0000 (23:26 +0000)
committergaurav-aws <gaurav-aws@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 21 Jul 2019 23:26:54 +0000 (23:26 +0000)
It still needs to be tested with the public mosquitto broker.

git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2691 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleMQTTExamples.c
FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/WIN32.vcxproj

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
index 2c5202e2e66fd77aecc219899edb6d6e1cbc4dd9..62df0590a27a1729757958da527364a58c3ef7dc 100644 (file)
@@ -60,7 +60,7 @@
       <Optimization>Disabled</Optimization>\r
       <AdditionalIncludeDirectories>..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\include;..\..\..\Source\FreeRTOS-Plus-TCP\include;..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;.\DemoTasks\include;.\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include\private;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\include;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\secure_sockets\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
-      <MinimalRebuild>true</MinimalRebuild>\r
+      <MinimalRebuild>false</MinimalRebuild>\r
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\r
       <PrecompiledHeaderOutputFile>.\Debug/WIN32.pch</PrecompiledHeaderOutputFile>\r