From 22ba9784be79f9ce910527f4d3d3d53cf0898d88 Mon Sep 17 00:00:00 2001 From: gaurav-aws Date: Sun, 21 Jul 2019 23:26:54 +0000 Subject: [PATCH] The MQTT example now works with the local MQTT broker. 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 --- .../mqtt/DemoTasks/SimpleMQTTExamples.c | 46 +++++++++++++++++-- .../FreeRTOS_IoT_Libraries/mqtt/WIN32.vcxproj | 2 +- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleMQTTExamples.c b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleMQTTExamples.c index d0c9e0b6e..648999eb6 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleMQTTExamples.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleMQTTExamples.c @@ -27,15 +27,15 @@ /* Standard inclues. */ #include +#include /* Kernel includes. */ #include "FreeRTOS.h" #include "task.h" -/* MQTT include. */ +/* IoT SDK includes. */ #include "iot_mqtt.h" - -/* Platform FreeRTOS network include. */ +#include "iot_taskpool.h" #include "platform/iot_network_freertos.h" /** @@ -59,8 +59,9 @@ * @brief Details of the MQTT broker to connect to. * * @note This example does not use TLS and therefore won't work with AWS IoT. + * */ -#define mqttexampleMQTT_BROKER_ENDPOINT "10.60.214.105" +#define mqttexampleMQTT_BROKER_ENDPOINT "test.mosquitto.org" #define mqttexampleMQTT_BROKER_PORT 1883 /** @@ -100,6 +101,32 @@ * @brief The MQTT connection handle used in this example. */ static IotMqttConnection_t xMQTTConnection = IOT_MQTT_CONNECTION_INITIALIZER; + +/** + * @brief Parameters used to create the system task pool. + */ +static const IotTaskPoolInfo_t xTaskPoolParameters = { + /* Minimum number of threads in a task pool. + * Note the slimmed down version of the task + * pool used by this library does not autoscale + * the number of tasks in the pool so in this + * case this sets the number of tasks in the + * pool. */ + 2, + /* Maximum number of threads in a task pool. + * Note the slimmed down version of the task + * pool used by this library does not autoscale + * the number of tasks in the pool so in this + * case this parameter is just ignored. */ + 2, + /* Stack size for every task pool thread - in + * bytes, hence multiplying by the number of bytes + * in a word as configMINIMAL_STACK_SIZE is + * specified in words. */ + configMINIMAL_STACK_SIZE * sizeof( portSTACK_TYPE ), + /* Priority for every task pool thread. */ + tskIDLE_PRIORITY, + }; /*-----------------------------------------------------------*/ /** @@ -231,6 +258,10 @@ const TickType_t xNoDelay = ( TickType_t ) 0; /* Remove compiler warnings about unused parameters. */ ( void ) pvParameters; + /* The MQTT library needs a task pool, so create the system task pool. */ + xResult = IotTaskPool_CreateSystemTaskPool( &( xTaskPoolParameters ) ); + configASSERT( xResult == IOT_TASKPOOL_SUCCESS ); + /* MQTT library must be initialized before it can be used. This is just one * time initialization. */ xResult = IotMqtt_Init(); @@ -284,6 +315,13 @@ const TickType_t xNoDelay = ( TickType_t ) 0; &( ulNotificationValue ), /* Obtain the notification value. */ pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) ); configASSERT( ( ulNotificationValue & mqttexampleDISCONNECTED_BIT ) == mqttexampleDISCONNECTED_BIT ); + + printf( "prvMQTTDemoTask() completed an iteration without hitting an assert.\r\n" ); + fflush( stdout ); + + /* Wait for some time between two iterations to ensure that we do not + * bombard the public test mosquitto broker. */ + vTaskDelay( pdMS_TO_TICKS( 5000 ) ); } } /*-----------------------------------------------------------*/ diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/WIN32.vcxproj b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/WIN32.vcxproj index 2c5202e2e..62df0590a 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/WIN32.vcxproj +++ b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/WIN32.vcxproj @@ -60,7 +60,7 @@ Disabled ..\..\..\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) WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - true + false EnableFastChecks MultiThreadedDLL .\Debug/WIN32.pch -- 2.39.2