mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-20 05:21:59 -04:00
The MQTT example now works with the local MQTT broker.
It still needs to be tested with the public mosquitto broker.
This commit is contained in:
parent
a7ef9c3b61
commit
06f9278de3
|
@ -27,15 +27,15 @@
|
||||||
|
|
||||||
/* Standard inclues. */
|
/* Standard inclues. */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
/* Kernel includes. */
|
/* Kernel includes. */
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
/* MQTT include. */
|
/* IoT SDK includes. */
|
||||||
#include "iot_mqtt.h"
|
#include "iot_mqtt.h"
|
||||||
|
#include "iot_taskpool.h"
|
||||||
/* Platform FreeRTOS network include. */
|
|
||||||
#include "platform/iot_network_freertos.h"
|
#include "platform/iot_network_freertos.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,8 +59,9 @@
|
||||||
* @brief Details of the MQTT broker to connect to.
|
* @brief Details of the MQTT broker to connect to.
|
||||||
*
|
*
|
||||||
* @note This example does not use TLS and therefore won't work with AWS IoT.
|
* @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
|
#define mqttexampleMQTT_BROKER_PORT 1883
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,6 +101,32 @@
|
||||||
* @brief The MQTT connection handle used in this example.
|
* @brief The MQTT connection handle used in this example.
|
||||||
*/
|
*/
|
||||||
static IotMqttConnection_t xMQTTConnection = IOT_MQTT_CONNECTION_INITIALIZER;
|
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. */
|
/* Remove compiler warnings about unused parameters. */
|
||||||
( void ) pvParameters;
|
( 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
|
/* MQTT library must be initialized before it can be used. This is just one
|
||||||
* time initialization. */
|
* time initialization. */
|
||||||
xResult = IotMqtt_Init();
|
xResult = IotMqtt_Init();
|
||||||
|
@ -284,6 +315,13 @@ const TickType_t xNoDelay = ( TickType_t ) 0;
|
||||||
&( ulNotificationValue ), /* Obtain the notification value. */
|
&( ulNotificationValue ), /* Obtain the notification value. */
|
||||||
pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );
|
pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );
|
||||||
configASSERT( ( ulNotificationValue & mqttexampleDISCONNECTED_BIT ) == mqttexampleDISCONNECTED_BIT );
|
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 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<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>
|
<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>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<MinimalRebuild>true</MinimalRebuild>
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
<PrecompiledHeaderOutputFile>.\Debug/WIN32.pch</PrecompiledHeaderOutputFile>
|
<PrecompiledHeaderOutputFile>.\Debug/WIN32.pch</PrecompiledHeaderOutputFile>
|
||||||
|
|
Loading…
Reference in a new issue