Changes to prepare for Jobs Library Demo (#401)

* Add submodule pointer to the aws/jobs-for-aws-iot-embedded-sdk repository for the Jobs library
* Commonize the MQTT helper functions used by the Device Shadow demo by re-locating them to FreeRTOS-Plus/Demo/AWS/MQTT_Demo_Helpers and updating the Device Shadow demo to use the new files
This commit is contained in:
Archit Aggarwal
2020-11-11 09:34:59 -08:00
committed by GitHub
parent de26f7f2f4
commit e96fd8b872
7 changed files with 192 additions and 160 deletions

3
.gitmodules vendored
View File

@ -25,3 +25,6 @@
[submodule "FreeRTOS-Plus/Source/Application-Protocols/corePKCS11"] [submodule "FreeRTOS-Plus/Source/Application-Protocols/corePKCS11"]
path = FreeRTOS-Plus/Source/corePKCS11 path = FreeRTOS-Plus/Source/corePKCS11
url = https://github.com/FreeRTOS/corePKCS11.git url = https://github.com/FreeRTOS/corePKCS11.git
[submodule "FreeRTOS-Plus/Source/AWS/jobs"]
path = FreeRTOS-Plus/Source/AWS/jobs
url = https://github.com/aws/jobs-for-aws-iot-embedded-sdk.git

View File

@ -62,10 +62,10 @@
/* JSON library includes. */ /* JSON library includes. */
#include "core_json.h" #include "core_json.h"
/* Shadow demo helpers header. */ /* Include MQTT demo helpers header. */
#include "shadow_demo_helpers.h" #include "mqtt_demo_helpers.h"
/* Demo Specific configs. */ /* Demo Specific config file. */
#include "demo_config.h" #include "demo_config.h"
@ -148,25 +148,43 @@
*/ */
#define SHADOW_REPORTED_JSON_LENGTH ( sizeof( SHADOW_REPORTED_JSON ) - 3 ) #define SHADOW_REPORTED_JSON_LENGTH ( sizeof( SHADOW_REPORTED_JSON ) - 3 )
#ifndef THING_NAME /*------------- Demo configurations -------------------------*/
/** #ifndef democonfigTHING_NAME
* @brief Predefined thing name. #define democonfigTHING_NAME democonfigCLIENT_IDENTIFIER
*
* This is the example predefine thing name and could be compiled in ROM code.
*/
#define THING_NAME democonfigCLIENT_IDENTIFIER
#endif #endif
/** /**
* @brief The length of #THING_NAME. * @brief The length of #democonfigTHING_NAME.
*/ */
#define THING_NAME_LENGTH ( ( uint16_t ) ( sizeof( THING_NAME ) - 1 ) ) #define THING_NAME_LENGTH ( ( uint16_t ) ( sizeof( democonfigTHING_NAME ) - 1 ) )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/**
* @brief The MQTT context used for MQTT operation.
*/
static MQTTContext_t xMqttContext;
/**
* @brief The network context used for mbedTLS operation.
*/
static NetworkContext_t xNetworkContext;
/**
* @brief Static buffer used to hold MQTT messages being sent and received.
*/
static uint8_t ucSharedBuffer[ democonfigNETWORK_BUFFER_SIZE ];
/**
* @brief Static buffer used to hold MQTT messages being sent and received.
*/
static MQTTFixedBuffer_t xBuffer =
{
.pBuffer = ucSharedBuffer,
.size = democonfigNETWORK_BUFFER_SIZE
};
/** /**
* @brief The simulated device current power on state. * @brief The simulated device current power on state.
*/ */
@ -523,14 +541,15 @@ static void prvEventCallback( MQTTContext_t * pxMqttContext,
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* /*
* @brief Create the task that demonstrates the Shadow API Demo via a * @brief Create the task that demonstrates the Device Shadow library API via a
* MQTT mutually authenticated network connection with MQTT broker. * MQTT mutually authenticated network connection with the AWS IoT broker.
*/ */
void vStartShadowDemo( void ) void vStartShadowDemo( void )
{ {
/* This example uses a single application task, which shows that how to /* This example uses a single application task, which shows that how to
* use Device Shadow library to get shadow topics and validate shadow topics * use Device Shadow library to generate and validate AWS IoT Device Shadow
* via MQTT APIs communicating with the MQTT broker. */ * MQTT topics, and use the coreMQTT library to communicate with the AWS IoT
* Device Shadow service. */
xTaskCreate( prvShadowDemoTask, /* Function that implements the task. */ xTaskCreate( prvShadowDemoTask, /* Function that implements the task. */
"DemoTask", /* Text name for the task - only used for debugging. */ "DemoTask", /* Text name for the task - only used for debugging. */
democonfigDEMO_STACKSIZE, /* Size of stack (in words, not bytes) to allocate for the task. */ democonfigDEMO_STACKSIZE, /* Size of stack (in words, not bytes) to allocate for the task. */
@ -538,7 +557,6 @@ void vStartShadowDemo( void )
tskIDLE_PRIORITY, /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */ tskIDLE_PRIORITY, /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */
NULL ); /* Used to pass out a handle to the created task - not used in this case. */ NULL ); /* Used to pass out a handle to the created task - not used in this case. */
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/** /**
@ -564,14 +582,17 @@ void prvShadowDemoTask( void * pvParameters )
{ {
BaseType_t demoStatus = pdPASS; BaseType_t demoStatus = pdPASS;
/* Remove compiler warnings about unused parameters. */
( void ) pvParameters;
/* A buffer containing the update document. It has static duration to prevent /* A buffer containing the update document. It has static duration to prevent
* it from being placed on the call stack. */ * it from being placed on the call stack. */
static char pcUpdateDocument[ SHADOW_REPORTED_JSON_LENGTH + 1 ] = { 0 }; static char pcUpdateDocument[ SHADOW_REPORTED_JSON_LENGTH + 1 ] = { 0 };
demoStatus = xEstablishMqttSession( prvEventCallback ); /* Remove compiler warnings about unused parameters. */
( void ) pvParameters;
demoStatus = xEstablishMqttSession( &xMqttContext,
&xNetworkContext,
&xBuffer,
prvEventCallback );
if( pdFAIL == demoStatus ) if( pdFAIL == demoStatus )
{ {
@ -581,7 +602,8 @@ void prvShadowDemoTask( void * pvParameters )
else else
{ {
/* First of all, try to delete any Shadow document in the cloud. */ /* First of all, try to delete any Shadow document in the cloud. */
demoStatus = xPublishToTopic( SHADOW_TOPIC_STRING_DELETE( THING_NAME ), demoStatus = xPublishToTopic( &xMqttContext,
SHADOW_TOPIC_STRING_DELETE( democonfigTHING_NAME ),
SHADOW_TOPIC_LENGTH_DELETE( THING_NAME_LENGTH ), SHADOW_TOPIC_LENGTH_DELETE( THING_NAME_LENGTH ),
pcUpdateDocument, pcUpdateDocument,
0U ); 0U );
@ -589,23 +611,26 @@ void prvShadowDemoTask( void * pvParameters )
/* Then try to subscribe shadow topics. */ /* Then try to subscribe shadow topics. */
if( demoStatus == pdPASS ) if( demoStatus == pdPASS )
{ {
demoStatus = xSubscribeToTopic( SHADOW_TOPIC_STRING_UPDATE_DELTA( THING_NAME ), demoStatus = xSubscribeToTopic( &xMqttContext,
SHADOW_TOPIC_STRING_UPDATE_DELTA( democonfigTHING_NAME ),
SHADOW_TOPIC_LENGTH_UPDATE_DELTA( THING_NAME_LENGTH ) ); SHADOW_TOPIC_LENGTH_UPDATE_DELTA( THING_NAME_LENGTH ) );
} }
if( demoStatus == pdPASS ) if( demoStatus == pdPASS )
{ {
demoStatus = xSubscribeToTopic( SHADOW_TOPIC_STRING_UPDATE_ACCEPTED( THING_NAME ), demoStatus = xSubscribeToTopic( &xMqttContext,
SHADOW_TOPIC_STRING_UPDATE_ACCEPTED( democonfigTHING_NAME ),
SHADOW_TOPIC_LENGTH_UPDATE_ACCEPTED( THING_NAME_LENGTH ) ); SHADOW_TOPIC_LENGTH_UPDATE_ACCEPTED( THING_NAME_LENGTH ) );
} }
if( demoStatus == pdPASS ) if( demoStatus == pdPASS )
{ {
demoStatus = xSubscribeToTopic( SHADOW_TOPIC_STRING_UPDATE_REJECTED( THING_NAME ), demoStatus = xSubscribeToTopic( &xMqttContext,
SHADOW_TOPIC_STRING_UPDATE_REJECTED( democonfigTHING_NAME ),
SHADOW_TOPIC_LENGTH_UPDATE_REJECTED( THING_NAME_LENGTH ) ); SHADOW_TOPIC_LENGTH_UPDATE_REJECTED( THING_NAME_LENGTH ) );
} }
/* This demo uses a constant #THING_NAME known at compile time therefore we can use macros to /* This demo uses a constant #democonfigTHING_NAME known at compile time therefore we can use macros to
* assemble shadow topic strings. * assemble shadow topic strings.
* If the thing name is known at run time, then we could use the API #Shadow_GetTopicString to * If the thing name is known at run time, then we could use the API #Shadow_GetTopicString to
* assemble shadow topic strings, here is the example for /update/delta: * assemble shadow topic strings, here is the example for /update/delta:
@ -651,7 +676,8 @@ void prvShadowDemoTask( void * pvParameters )
( int ) 1, ( int ) 1,
( long unsigned ) ( xTaskGetTickCount() % 1000000 ) ); ( long unsigned ) ( xTaskGetTickCount() % 1000000 ) );
demoStatus = xPublishToTopic( SHADOW_TOPIC_STRING_UPDATE( THING_NAME ), demoStatus = xPublishToTopic( &xMqttContext,
SHADOW_TOPIC_STRING_UPDATE( democonfigTHING_NAME ),
SHADOW_TOPIC_LENGTH_UPDATE( THING_NAME_LENGTH ), SHADOW_TOPIC_LENGTH_UPDATE( THING_NAME_LENGTH ),
pcUpdateDocument, pcUpdateDocument,
( SHADOW_DESIRED_JSON_LENGTH + 1 ) ); ( SHADOW_DESIRED_JSON_LENGTH + 1 ) );
@ -683,7 +709,8 @@ void prvShadowDemoTask( void * pvParameters )
( int ) ulCurrentPowerOnState, ( int ) ulCurrentPowerOnState,
( long unsigned ) ulClientToken ); ( long unsigned ) ulClientToken );
demoStatus = xPublishToTopic( SHADOW_TOPIC_STRING_UPDATE( THING_NAME ), demoStatus = xPublishToTopic( &xMqttContext,
SHADOW_TOPIC_STRING_UPDATE( democonfigTHING_NAME ),
SHADOW_TOPIC_LENGTH_UPDATE( THING_NAME_LENGTH ), SHADOW_TOPIC_LENGTH_UPDATE( THING_NAME_LENGTH ),
pcUpdateDocument, pcUpdateDocument,
( SHADOW_DESIRED_JSON_LENGTH + 1 ) ); ( SHADOW_DESIRED_JSON_LENGTH + 1 ) );
@ -698,42 +725,45 @@ void prvShadowDemoTask( void * pvParameters )
{ {
LogInfo( ( "Start to unsubscribe shadow topics and disconnect from MQTT. \r\n" ) ); LogInfo( ( "Start to unsubscribe shadow topics and disconnect from MQTT. \r\n" ) );
demoStatus = xUnsubscribeFromTopic( SHADOW_TOPIC_STRING_UPDATE_DELTA( THING_NAME ), demoStatus = xUnsubscribeFromTopic( &xMqttContext,
SHADOW_TOPIC_STRING_UPDATE_DELTA( democonfigTHING_NAME ),
SHADOW_TOPIC_LENGTH_UPDATE_DELTA( THING_NAME_LENGTH ) ); SHADOW_TOPIC_LENGTH_UPDATE_DELTA( THING_NAME_LENGTH ) );
if( demoStatus != pdPASS ) if( demoStatus != pdPASS )
{ {
LogError( ( "Failed to unsubscribe the topic %s", LogError( ( "Failed to unsubscribe the topic %s",
SHADOW_TOPIC_STRING_UPDATE_DELTA( THING_NAME ) ) ); SHADOW_TOPIC_STRING_UPDATE_DELTA( democonfigTHING_NAME ) ) );
} }
} }
if( demoStatus == pdPASS ) if( demoStatus == pdPASS )
{ {
demoStatus = xUnsubscribeFromTopic( SHADOW_TOPIC_STRING_UPDATE_ACCEPTED( THING_NAME ), demoStatus = xUnsubscribeFromTopic( &xMqttContext,
SHADOW_TOPIC_STRING_UPDATE_ACCEPTED( democonfigTHING_NAME ),
SHADOW_TOPIC_LENGTH_UPDATE_ACCEPTED( THING_NAME_LENGTH ) ); SHADOW_TOPIC_LENGTH_UPDATE_ACCEPTED( THING_NAME_LENGTH ) );
if( demoStatus != pdPASS ) if( demoStatus != pdPASS )
{ {
LogError( ( "Failed to unsubscribe the topic %s", LogError( ( "Failed to unsubscribe the topic %s",
SHADOW_TOPIC_STRING_UPDATE_ACCEPTED( THING_NAME ) ) ); SHADOW_TOPIC_STRING_UPDATE_ACCEPTED( democonfigTHING_NAME ) ) );
} }
} }
if( demoStatus == pdPASS ) if( demoStatus == pdPASS )
{ {
demoStatus = xUnsubscribeFromTopic( SHADOW_TOPIC_STRING_UPDATE_REJECTED( THING_NAME ), demoStatus = xUnsubscribeFromTopic( &xMqttContext,
SHADOW_TOPIC_STRING_UPDATE_REJECTED( democonfigTHING_NAME ),
SHADOW_TOPIC_LENGTH_UPDATE_REJECTED( THING_NAME_LENGTH ) ); SHADOW_TOPIC_LENGTH_UPDATE_REJECTED( THING_NAME_LENGTH ) );
if( demoStatus != pdPASS ) if( demoStatus != pdPASS )
{ {
LogError( ( "Failed to unsubscribe the topic %s", LogError( ( "Failed to unsubscribe the topic %s",
SHADOW_TOPIC_STRING_UPDATE_REJECTED( THING_NAME ) ) ); SHADOW_TOPIC_STRING_UPDATE_REJECTED( democonfigTHING_NAME ) ) );
} }
} }
/* The MQTT session is always disconnected, even there were prior failures. */ /* The MQTT session is always disconnected, even there were prior failures. */
demoStatus = xDisconnectMqttSession(); demoStatus = xDisconnectMqttSession( &xMqttContext, &xNetworkContext );
/* This demo performs only Device Shadow operations. If matching the Shadow /* This demo performs only Device Shadow operations. If matching the Shadow
* MQTT topic fails or there are failure in parsing the received JSON document, * MQTT topic fails or there are failure in parsing the received JSON document,

View File

@ -58,7 +58,7 @@
</Midl> </Midl>
<ClCompile> <ClCompile>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\..\FreeRTOS-Plus\Source\Utilities\logging;..\common\WinPCap;..\..\..\..\..\FreeRTOS\Source\include;..\..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface;..\..\..\..\Source\Utilities\exponential_backoff;..\..\..\..\Source\Application-Protocols\network_transport\freertos_plus_tcp;..\..\..\..\Source\Application-Protocols\network_transport\freertos_plus_tcp\using_mbedtls;..\..\..\..\Source\Utilities\mbedtls_freertos;..\..\..\..\..\Source\mbedtls_utils;..\..\..\..\ThirdParty\mbedtls\include;..\..\..\..\Source\AWS\device-shadow\source\include;..\..\..\..\Source\coreJSON\source\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\..\FreeRTOS-Plus\Source\Utilities\logging;..\common\WinPCap;..\..\..\..\..\FreeRTOS\Source\include;..\..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface;..\..\..\..\Source\Utilities\exponential_backoff;..\..\..\..\Source\Application-Protocols\network_transport\freertos_plus_tcp;..\..\..\..\Source\Application-Protocols\network_transport\freertos_plus_tcp\using_mbedtls;..\..\..\..\Source\Utilities\mbedtls_freertos;..\..\..\..\..\Source\mbedtls_utils;..\..\..\..\ThirdParty\mbedtls\include;..\..\..\..\Source\AWS\device-shadow\source\include;..\..\..\..\Source\coreJSON\source\include;..\..\Mqtt_Demo_Helpers;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MBEDTLS_CONFIG_FILE="mbedtls_config.h";WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>MBEDTLS_CONFIG_FILE="mbedtls_config.h";WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild> <MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -490,7 +490,7 @@
<ClCompile Include="..\..\..\..\..\FreeRTOS-Plus\Demo\Common\Logging\windows\Logging_WinSim.c" /> <ClCompile Include="..\..\..\..\..\FreeRTOS-Plus\Demo\Common\Logging\windows\Logging_WinSim.c" />
<ClCompile Include="..\Common\main.c" /> <ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\ShadowDemoMainExample.c" /> <ClCompile Include="DemoTasks\ShadowDemoMainExample.c" />
<ClCompile Include="DemoTasks\shadow_demo_helpers.c" /> <ClCompile Include="..\..\Mqtt_Demo_Helpers\mqtt_demo_helpers.c" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\..\..\..\FreeRTOS\Source\include\event_groups.h" /> <ClInclude Include="..\..\..\..\..\FreeRTOS\Source\include\event_groups.h" />

View File

@ -67,6 +67,17 @@ extern void vLoggingPrintf( const char * pcFormatString,
/************ End of logging configuration ****************/ /************ End of logging configuration ****************/
/**
* @brief The Thing resource registered on your AWS IoT account to use in the demo.
* A Thing resource is required to communicate with the AWS IoT Device Shadow service.
*
* @note The Things associated with your AWS account can be found in the
* AWS IoT console under Manage/Things, or using the ListThings REST API (that can
* be called with the AWS CLI command line tool).
*
* #define democonfigTHING_NAME "...insert here..."
*/
#ifndef democonfigCLIENT_IDENTIFIER #ifndef democonfigCLIENT_IDENTIFIER
/** /**
@ -83,16 +94,11 @@ extern void vLoggingPrintf( const char * pcFormatString,
#endif #endif
/** /**
* @brief Endpoint of the MQTT broker to connect to. * @brief The AWS IoT broker endpoint to connect to in the demo.
*
* This demo application can be run with any MQTT broker, that supports mutual
* authentication.
*
* For AWS IoT MQTT broker, this is the Thing's REST API Endpoint.
* *
* @note Your AWS IoT Core endpoint can be found in the AWS IoT console under * @note Your AWS IoT Core endpoint can be found in the AWS IoT console under
* Settings/Custom Endpoint, or using the describe-endpoint REST API (with * Settings/Custom Endpoint, or using the DescribeEndpoint REST API (that can
* AWS CLI command line tool). * be called with AWS CLI command line tool).
* *
* #define democonfigMQTT_BROKER_ENDPOINT "...insert here..." * #define democonfigMQTT_BROKER_ENDPOINT "...insert here..."
*/ */
@ -113,8 +119,8 @@ extern void vLoggingPrintf( const char * pcFormatString,
/** /**
* @brief AWS root CA certificate. * @brief AWS root CA certificate.
* *
* For AWS IoT MQTT broker, this certificate is used to identify the AWS IoT * This certificate is used to identify the AWS IoT server and is publicly available.
* server and is publicly available. Refer to the link below. * Refer to the link below.
* https://www.amazontrust.com/repository/AmazonRootCA1.pem * https://www.amazontrust.com/repository/AmazonRootCA1.pem
* *
* @note This certificate should be PEM-encoded. * @note This certificate should be PEM-encoded.
@ -124,7 +130,6 @@ extern void vLoggingPrintf( const char * pcFormatString,
* "...base64 data...\n"\ * "...base64 data...\n"\
* "-----END CERTIFICATE-----\n" * "-----END CERTIFICATE-----\n"
* *
* #define democonfigROOT_CA_PEM "...insert here..."
*/ */
#define democonfigROOT_CA_PEM \ #define democonfigROOT_CA_PEM \
@ -152,7 +157,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
/** /**
* @brief Client certificate. * @brief Client certificate.
* *
* For AWS IoT MQTT broker, refer to the AWS documentation below for details * Please refer to the AWS documentation below for details
* regarding client authentication. * regarding client authentication.
* https://docs.aws.amazon.com/iot/latest/developerguide/client-authentication.html * https://docs.aws.amazon.com/iot/latest/developerguide/client-authentication.html
* *
@ -169,7 +174,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
/** /**
* @brief Client's private key. * @brief Client's private key.
* *
* For AWS IoT MQTT broker, refer to the AWS documentation below for details * Please refer to the AWS documentation below for details
* regarding clientauthentication. * regarding clientauthentication.
* https://docs.aws.amazon.com/iot/latest/developerguide/client-authentication.html * https://docs.aws.amazon.com/iot/latest/developerguide/client-authentication.html
* *
@ -187,7 +192,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
* @brief The username value for authenticating client to the MQTT broker when * @brief The username value for authenticating client to the MQTT broker when
* username/password based client authentication is used. * username/password based client authentication is used.
* *
* For AWS IoT MQTT broker, refer to the AWS IoT documentation below for * Please refer to the AWS IoT documentation below for
* details regarding client authentication with a username and password. * details regarding client authentication with a username and password.
* https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html * https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html
* An authorizer setup needs to be done, as mentioned in the above link, to use * An authorizer setup needs to be done, as mentioned in the above link, to use
@ -200,7 +205,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
* @brief The password value for authenticating client to the MQTT broker when * @brief The password value for authenticating client to the MQTT broker when
* username/password based client authentication is used. * username/password based client authentication is used.
* *
* For AWS IoT MQTT broker, refer to the AWS IoT documentation below for * Please refer to the AWS IoT documentation below for
* details regarding client authentication with a username and password. * details regarding client authentication with a username and password.
* https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html * https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html
* An authorizer setup needs to be done, as mentioned in the above link, to use * An authorizer setup needs to be done, as mentioned in the above link, to use

View File

@ -41,10 +41,7 @@
#include "task.h" #include "task.h"
/* Shadow includes */ /* Shadow includes */
#include "shadow_demo_helpers.h" #include "mqtt_demo_helpers.h"
/* Demo Specific configs. */
#include "demo_config.h"
/* MQTT library includes. */ /* MQTT library includes. */
#include "core_mqtt.h" #include "core_mqtt.h"
@ -55,32 +52,32 @@
/* Transport interface implementation include header for TLS. */ /* Transport interface implementation include header for TLS. */
#include "using_mbedtls.h" #include "using_mbedtls.h"
/* Demo specific config. */
#include "demo_config.h"
/*------------- Demo configurations -------------------------*/ /*------------- Demo configurations -------------------------*/
/** Note: The device client certificate and private key credentials are /**
* obtained by the TLS transport interface implementation from the * Note: The TLS connection credentials for the server root CA certificate,
* and device client certificate and private key should be defined in the
* demo_config.h file. * demo_config.h file.
*/ */
#ifndef democonfigROOT_CA_PEM
#error "Please define the AWS Root CA certificate (democonfigROOT_CA_PEM) in demo_config.h."
#endif
#ifndef democonfigCLIENT_PRIVATE_KEY_PEM #ifndef democonfigCLIENT_PRIVATE_KEY_PEM
#error "Please define client private key(democonfigCLIENT_PRIVATE_KEY_PEM) in demo_config.h." #error "Please define client private key (democonfigCLIENT_PRIVATE_KEY_PEM) in demo_config.h."
#endif #endif
#ifndef democonfigCLIENT_CERTIFICATE_PEM #ifndef democonfigCLIENT_CERTIFICATE_PEM
#error "Please define client certificate(democonfigCLIENT_CERTIFICATE_PEM) in demo_config.h." #error "Please define client certificate (democonfigCLIENT_CERTIFICATE_PEM) in demo_config.h."
#endif #endif
#ifndef democonfigMQTT_BROKER_ENDPOINT #ifndef democonfigMQTT_BROKER_ENDPOINT
#error "Please define democonfigMQTT_BROKER_ENDPOINT in demo_config.h." #error "Please define the AWS IoT broker endpoint (democonfigMQTT_BROKER_ENDPOINT) in demo_config.h."
#endif #endif
#ifndef democonfigMQTT_BROKER_PORT
/**
* @brief The port to use for the demo.
*/
#define democonfigMQTT_BROKER_PORT ( 8883 )
#endif
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/** /**
@ -162,6 +159,7 @@
*/ */
#define AWS_IOT_MQTT_ALPN "\x0ex-amzn-mqtt-ca" #define AWS_IOT_MQTT_ALPN "\x0ex-amzn-mqtt-ca"
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/** /**
@ -181,6 +179,8 @@ typedef struct PublishPackets
MQTTPublishInfo_t pubInfo; MQTTPublishInfo_t pubInfo;
} PublishPackets_t; } PublishPackets_t;
/*-----------------------------------------------------------*/
/** /**
* @brief Global entry time into the application to use as a reference timestamp * @brief Global entry time into the application to use as a reference timestamp
* in the #prvGetTimeMs function. #prvGetTimeMs will always return the difference * in the #prvGetTimeMs function. #prvGetTimeMs will always return the difference
@ -189,7 +189,10 @@ typedef struct PublishPackets
*/ */
static uint32_t ulGlobalEntryTimeMs; static uint32_t ulGlobalEntryTimeMs;
/*-----------------------------------------------------------*/ /**
* @brief The flag to indicate the mqtt session changed.
*/
static BaseType_t xMqttSessionEstablished = pdFALSE;
/** /**
* @brief Packet Identifier generated when Subscribe request was sent to the broker; * @brief Packet Identifier generated when Subscribe request was sent to the broker;
@ -211,35 +214,6 @@ static uint16_t globalUnsubscribePacketIdentifier = 0U;
*/ */
static PublishPackets_t outgoingPublishPackets[ MAX_OUTGOING_PUBLISHES ] = { 0 }; static PublishPackets_t outgoingPublishPackets[ MAX_OUTGOING_PUBLISHES ] = { 0 };
/**
* @brief Static buffer used to hold MQTT messages being sent and received.
*/
static uint8_t ucSharedBuffer[ democonfigNETWORK_BUFFER_SIZE ];
/**
* @brief The MQTT context used for MQTT operation.
*/
static MQTTContext_t mqttContext = { 0 };
/**
* @brief The network context used for Openssl operation.
*/
static NetworkContext_t networkContext = { 0 };
/**
* @brief The flag to indicate the mqtt session changed.
*/
static bool mqttSessionEstablished = false;
/**
* @brief Static buffer used to hold MQTT messages being sent and received.
*/
static MQTTFixedBuffer_t xBuffer =
{
.pBuffer = ucSharedBuffer,
.size = democonfigNETWORK_BUFFER_SIZE
};
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/** /**
@ -319,6 +293,8 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext
* second entry must remain NULL. */ * second entry must remain NULL. */
char * pcAlpnProtocols[] = { NULL, NULL }; char * pcAlpnProtocols[] = { NULL, NULL };
configASSERT( pxNetworkContext != NULL );
/* Set the credentials for establishing a TLS connection. */ /* Set the credentials for establishing a TLS connection. */
xNetworkCredentials.pRootCa = ( const unsigned char * ) democonfigROOT_CA_PEM; xNetworkCredentials.pRootCa = ( const unsigned char * ) democonfigROOT_CA_PEM;
xNetworkCredentials.rootCaSize = sizeof( democonfigROOT_CA_PEM ); xNetworkCredentials.rootCaSize = sizeof( democonfigROOT_CA_PEM );
@ -381,7 +357,7 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext
static BaseType_t prvGetNextFreeIndexForOutgoingPublishes( uint8_t * pucIndex ) static BaseType_t prvGetNextFreeIndexForOutgoingPublishes( uint8_t * pucIndex )
{ {
BaseType_t returnStatus = pdFAIL; BaseType_t xReturnStatus = pdFAIL;
uint8_t ucIndex = 0; uint8_t ucIndex = 0;
configASSERT( outgoingPublishPackets != NULL ); configASSERT( outgoingPublishPackets != NULL );
@ -393,7 +369,7 @@ static BaseType_t prvGetNextFreeIndexForOutgoingPublishes( uint8_t * pucIndex )
* Check if the the ucIndex has a free slot. */ * Check if the the ucIndex has a free slot. */
if( outgoingPublishPackets[ ucIndex ].packetId == MQTT_PACKET_ID_INVALID ) if( outgoingPublishPackets[ ucIndex ].packetId == MQTT_PACKET_ID_INVALID )
{ {
returnStatus = pdPASS; xReturnStatus = pdPASS;
break; break;
} }
} }
@ -401,7 +377,7 @@ static BaseType_t prvGetNextFreeIndexForOutgoingPublishes( uint8_t * pucIndex )
/* Copy the available ucIndex into the output param. */ /* Copy the available ucIndex into the output param. */
*pucIndex = ucIndex; *pucIndex = ucIndex;
return returnStatus; return xReturnStatus;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -494,7 +470,7 @@ void vHandleOtherIncomingPacket( MQTTPacketInfo_t * pxPacketInfo,
static BaseType_t xHandlePublishResend( MQTTContext_t * pxMqttContext ) static BaseType_t xHandlePublishResend( MQTTContext_t * pxMqttContext )
{ {
BaseType_t returnStatus = pdTRUE; BaseType_t xReturnStatus = pdTRUE;
MQTTStatus_t xMQTTStatus = MQTTSuccess; MQTTStatus_t xMQTTStatus = MQTTSuccess;
uint8_t ucIndex = 0U; uint8_t ucIndex = 0U;
@ -521,7 +497,7 @@ static BaseType_t xHandlePublishResend( MQTTContext_t * pxMqttContext )
" failed with status %u.", " failed with status %u.",
outgoingPublishPackets[ ucIndex ].packetId, outgoingPublishPackets[ ucIndex ].packetId,
xMQTTStatus ) ); xMQTTStatus ) );
returnStatus = pdFAIL; xReturnStatus = pdFAIL;
break; break;
} }
else else
@ -532,19 +508,20 @@ static BaseType_t xHandlePublishResend( MQTTContext_t * pxMqttContext )
} }
} }
return returnStatus; return xReturnStatus;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
BaseType_t xEstablishMqttSession( MQTTEventCallback_t eventCallback ) BaseType_t xEstablishMqttSession( MQTTContext_t * pxMqttContext,
NetworkContext_t * pxNetworkContext,
MQTTFixedBuffer_t * pxNetworkBuffer,
MQTTEventCallback_t eventCallback )
{ {
BaseType_t returnStatus = pdTRUE; BaseType_t xReturnStatus = pdTRUE;
MQTTStatus_t xMQTTStatus; MQTTStatus_t xMQTTStatus;
MQTTConnectInfo_t xConnectInfo; MQTTConnectInfo_t xConnectInfo;
TransportInterface_t xTransport; TransportInterface_t xTransport;
MQTTContext_t * pxMqttContext = &mqttContext;
NetworkContext_t * pxNetworkContext = &networkContext;
bool sessionPresent = false; bool sessionPresent = false;
configASSERT( pxMqttContext != NULL ); configASSERT( pxMqttContext != NULL );
@ -561,7 +538,7 @@ BaseType_t xEstablishMqttSession( MQTTEventCallback_t eventCallback )
LogError( ( "Failed to connect to MQTT broker %.*s.", LogError( ( "Failed to connect to MQTT broker %.*s.",
strlen( democonfigMQTT_BROKER_ENDPOINT ), strlen( democonfigMQTT_BROKER_ENDPOINT ),
democonfigMQTT_BROKER_ENDPOINT ) ); democonfigMQTT_BROKER_ENDPOINT ) );
returnStatus = pdFAIL; xReturnStatus = pdFAIL;
} }
else else
{ {
@ -575,11 +552,11 @@ BaseType_t xEstablishMqttSession( MQTTEventCallback_t eventCallback )
&xTransport, &xTransport,
prvGetTimeMs, prvGetTimeMs,
eventCallback, eventCallback,
&xBuffer ); pxNetworkBuffer );
if( xMQTTStatus != MQTTSuccess ) if( xMQTTStatus != MQTTSuccess )
{ {
returnStatus = pdFAIL; xReturnStatus = pdFAIL;
LogError( ( "MQTT init failed with status %u.", xMQTTStatus ) ); LogError( ( "MQTT init failed with status %u.", xMQTTStatus ) );
} }
else else
@ -632,7 +609,7 @@ BaseType_t xEstablishMqttSession( MQTTEventCallback_t eventCallback )
if( xMQTTStatus != MQTTSuccess ) if( xMQTTStatus != MQTTSuccess )
{ {
returnStatus = pdFAIL; xReturnStatus = pdFAIL;
LogError( ( "Connection with MQTT broker failed with status %u.", xMQTTStatus ) ); LogError( ( "Connection with MQTT broker failed with status %u.", xMQTTStatus ) );
} }
else else
@ -641,15 +618,15 @@ BaseType_t xEstablishMqttSession( MQTTEventCallback_t eventCallback )
} }
} }
if( returnStatus == pdFAIL ) if( xReturnStatus == pdFAIL )
{ {
/* Keep a flag for indicating if MQTT session is established. This /* Keep a flag for indicating if MQTT session is established. This
* flag will mark that an MQTT DISCONNECT has to be sent at the end * flag will mark that an MQTT DISCONNECT has to be sent at the end
* of the demo even if there are intermediate failures. */ * of the demo even if there are intermediate failures. */
mqttSessionEstablished = true; xMqttSessionEstablished = true;
} }
if( returnStatus == pdFAIL ) if( xReturnStatus == pdFAIL )
{ {
/* Check if session is present and if there are any outgoing publishes /* Check if session is present and if there are any outgoing publishes
* that need to resend. This is only valid if the broker is * that need to resend. This is only valid if the broker is
@ -674,23 +651,22 @@ BaseType_t xEstablishMqttSession( MQTTEventCallback_t eventCallback )
} }
} }
return returnStatus; return xReturnStatus;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
BaseType_t xDisconnectMqttSession( void ) BaseType_t xDisconnectMqttSession( MQTTContext_t * pxMqttContext,
NetworkContext_t * pxNetworkContext )
{ {
MQTTStatus_t xMQTTStatus = MQTTSuccess; MQTTStatus_t xMQTTStatus = MQTTSuccess;
BaseType_t returnStatus = pdTRUE; BaseType_t xReturnStatus = pdTRUE;
TlsTransportStatus_t xNetworkStatus; TlsTransportStatus_t xNetworkStatus;
MQTTContext_t * pxMqttContext = &mqttContext;
NetworkContext_t * pxNetworkContext = &networkContext;
configASSERT( pxMqttContext != NULL ); configASSERT( pxMqttContext != NULL );
configASSERT( pxNetworkContext != NULL ); configASSERT( pxNetworkContext != NULL );
if( mqttSessionEstablished == true ) if( xMqttSessionEstablished == true )
{ {
/* Send DISCONNECT. */ /* Send DISCONNECT. */
xMQTTStatus = MQTT_Disconnect( pxMqttContext ); xMQTTStatus = MQTT_Disconnect( pxMqttContext );
@ -699,24 +675,24 @@ BaseType_t xDisconnectMqttSession( void )
{ {
LogError( ( "Sending MQTT DISCONNECT failed with status=%u.", LogError( ( "Sending MQTT DISCONNECT failed with status=%u.",
xMQTTStatus ) ); xMQTTStatus ) );
returnStatus = pdFAIL; xReturnStatus = pdFAIL;
} }
} }
/* Close the network connection. */ /* Close the network connection. */
TLS_FreeRTOS_Disconnect( pxNetworkContext ); TLS_FreeRTOS_Disconnect( pxNetworkContext );
return returnStatus; return xReturnStatus;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
BaseType_t xSubscribeToTopic( const char * pcTopicFilter, BaseType_t xSubscribeToTopic( MQTTContext_t * pxMqttContext,
const char * pcTopicFilter,
uint16_t usTopicFilterLength ) uint16_t usTopicFilterLength )
{ {
BaseType_t returnStatus = pdTRUE; BaseType_t xReturnStatus = pdTRUE;
MQTTStatus_t xMQTTStatus; MQTTStatus_t xMQTTStatus;
MQTTContext_t * pxMqttContext = &mqttContext;
MQTTSubscribeInfo_t pSubscriptionList[ mqttexampleTOPIC_COUNT ]; MQTTSubscribeInfo_t pSubscriptionList[ mqttexampleTOPIC_COUNT ];
configASSERT( pxMqttContext != NULL ); configASSERT( pxMqttContext != NULL );
@ -744,7 +720,7 @@ BaseType_t xSubscribeToTopic( const char * pcTopicFilter,
{ {
LogError( ( "Failed to send SUBSCRIBE packet to broker with error = %u.", LogError( ( "Failed to send SUBSCRIBE packet to broker with error = %u.",
xMQTTStatus ) ); xMQTTStatus ) );
returnStatus = pdFAIL; xReturnStatus = pdFAIL;
} }
else else
{ {
@ -763,23 +739,23 @@ BaseType_t xSubscribeToTopic( const char * pcTopicFilter,
if( xMQTTStatus != MQTTSuccess ) if( xMQTTStatus != MQTTSuccess )
{ {
returnStatus = pdFAIL; xReturnStatus = pdFAIL;
LogError( ( "MQTT_ProcessLoop returned with status = %u.", LogError( ( "MQTT_ProcessLoop returned with status = %u.",
xMQTTStatus ) ); xMQTTStatus ) );
} }
} }
return returnStatus; return xReturnStatus;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
BaseType_t xUnsubscribeFromTopic( const char * pcTopicFilter, BaseType_t xUnsubscribeFromTopic( MQTTContext_t * pxMqttContext,
const char * pcTopicFilter,
uint16_t usTopicFilterLength ) uint16_t usTopicFilterLength )
{ {
BaseType_t returnStatus = pdTRUE; BaseType_t xReturnStatus = pdTRUE;
MQTTStatus_t xMQTTStatus; MQTTStatus_t xMQTTStatus;
MQTTContext_t * pxMqttContext = &mqttContext;
MQTTSubscribeInfo_t pSubscriptionList[ 1 ]; MQTTSubscribeInfo_t pSubscriptionList[ 1 ];
configASSERT( pxMqttContext != NULL ); configASSERT( pxMqttContext != NULL );
@ -807,7 +783,7 @@ BaseType_t xUnsubscribeFromTopic( const char * pcTopicFilter,
{ {
LogError( ( "Failed to send UNSUBSCRIBE packet to broker with error = %u.", LogError( ( "Failed to send UNSUBSCRIBE packet to broker with error = %u.",
xMQTTStatus ) ); xMQTTStatus ) );
returnStatus = pdFAIL; xReturnStatus = pdFAIL;
} }
else else
{ {
@ -820,26 +796,26 @@ BaseType_t xUnsubscribeFromTopic( const char * pcTopicFilter,
if( xMQTTStatus != MQTTSuccess ) if( xMQTTStatus != MQTTSuccess )
{ {
returnStatus = pdFAIL; xReturnStatus = pdFAIL;
LogError( ( "MQTT_ProcessLoop returned with status = %u.", LogError( ( "MQTT_ProcessLoop returned with status = %u.",
xMQTTStatus ) ); xMQTTStatus ) );
} }
} }
return returnStatus; return xReturnStatus;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
BaseType_t xPublishToTopic( const char * pcTopicFilter, BaseType_t xPublishToTopic( MQTTContext_t * pxMqttContext,
const char * pcTopicFilter,
int32_t topicFilterLength, int32_t topicFilterLength,
const char * pcPayload, const char * pcPayload,
size_t payloadLength ) size_t payloadLength )
{ {
BaseType_t returnStatus = pdPASS; BaseType_t xReturnStatus = pdPASS;
MQTTStatus_t xMQTTStatus = MQTTSuccess; MQTTStatus_t xMQTTStatus = MQTTSuccess;
uint8_t ucPublishIndex = MAX_OUTGOING_PUBLISHES; uint8_t ucPublishIndex = MAX_OUTGOING_PUBLISHES;
MQTTContext_t * pxMqttContext = &mqttContext;
configASSERT( pxMqttContext != NULL ); configASSERT( pxMqttContext != NULL );
configASSERT( pcTopicFilter != NULL ); configASSERT( pcTopicFilter != NULL );
@ -849,9 +825,9 @@ BaseType_t xPublishToTopic( const char * pcTopicFilter,
* publishes are stored until a PUBACK is received. These messages are * publishes are stored until a PUBACK is received. These messages are
* stored for supporting a resend if a network connection is broken before * stored for supporting a resend if a network connection is broken before
* receiving a PUBACK. */ * receiving a PUBACK. */
returnStatus = prvGetNextFreeIndexForOutgoingPublishes( &ucPublishIndex ); xReturnStatus = prvGetNextFreeIndexForOutgoingPublishes( &ucPublishIndex );
if( returnStatus == pdFAIL ) if( xReturnStatus == pdFAIL )
{ {
LogError( ( "Unable to find a free spot for outgoing PUBLISH message.\n\n" ) ); LogError( ( "Unable to find a free spot for outgoing PUBLISH message.\n\n" ) );
} }
@ -878,7 +854,7 @@ BaseType_t xPublishToTopic( const char * pcTopicFilter,
LogError( ( "Failed to send PUBLISH packet to broker with error = %u.", LogError( ( "Failed to send PUBLISH packet to broker with error = %u.",
xMQTTStatus ) ); xMQTTStatus ) );
vCleanupOutgoingPublishAt( ucPublishIndex ); vCleanupOutgoingPublishAt( ucPublishIndex );
returnStatus = pdFAIL; xReturnStatus = pdFAIL;
} }
else else
{ {
@ -899,12 +875,12 @@ BaseType_t xPublishToTopic( const char * pcTopicFilter,
{ {
LogWarn( ( "MQTT_ProcessLoop returned with status = %u.", LogWarn( ( "MQTT_ProcessLoop returned with status = %u.",
xMQTTStatus ) ); xMQTTStatus ) );
returnStatus = pdFAIL; xReturnStatus = pdFAIL;
} }
} }
} }
return returnStatus; return xReturnStatus;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

View File

@ -20,8 +20,8 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#ifndef SHADOW_DEMO_HELPERS_H #ifndef MQTT_DEMO_HELPERS_H
#define SHADOW_DEMO_HELPERS_H #define MQTT_DEMO_HELPERS_H
/* MQTT API header. */ /* MQTT API header. */
#include "core_mqtt.h" #include "core_mqtt.h"
@ -29,17 +29,24 @@
/* Transport interface implementation include header for TLS. */ /* Transport interface implementation include header for TLS. */
#include "using_mbedtls.h" #include "using_mbedtls.h"
/*-----------------------------------------------------------*/
/** /**
* @brief Establish a MQTT connection. * @brief Establish a MQTT connection.
* *
* @param[in] eventCallback The callback function used to receive incoming * @param[in, out] pxMqttContext The memory for the MQTTContext_t that will be used for the
* MQTT connection.
* @param[out] pxNetworkContext The memory for the NetworkContext_t required for the
* MQTT connection.
* @param[in] pxNetworkBuffer The buffer space for initializing the @p pxMqttContext MQTT
* context used in the MQTT connection.
* @param[in] appCallback The callback function used to receive incoming
* publishes and incoming acks from MQTT library. * publishes and incoming acks from MQTT library.
* *
* @return The status of the final connection attempt. * @return The status of the final connection attempt.
*/ */
BaseType_t xEstablishMqttSession( MQTTEventCallback_t eventCallback ); BaseType_t xEstablishMqttSession( MQTTContext_t * pxMqttContext,
NetworkContext_t * pxNetworkContext,
MQTTFixedBuffer_t * pxNetworkBuffer,
MQTTEventCallback_t eventCallback );
/** /**
* @brief Handle the incoming packet if it's not related to the device shadow. * @brief Handle the incoming packet if it's not related to the device shadow.
@ -53,41 +60,50 @@ void vHandleOtherIncomingPacket( MQTTPacketInfo_t * pxPacketInfo,
/** /**
* @brief Close the MQTT connection. * @brief Close the MQTT connection.
* *
* @param[in, out] pxMqttContext The MQTT context for the MQTT connection to close.
* @param[in, out] pxNetworkContext The network context for the TLS session to
* terminate.
*
* @return pdPASS if DISCONNECT was successfully sent; * @return pdPASS if DISCONNECT was successfully sent;
* pdFAIL otherwise. * pdFAIL otherwise.
*/ */
BaseType_t xDisconnectMqttSession( void ); BaseType_t xDisconnectMqttSession( MQTTContext_t * pxMqttContext,
NetworkContext_t * pxNetworkContext );
/** /**
* @brief Subscribe to a MQTT topic filter. * @brief Subscribe to a MQTT topic filter.
* *
* @param[in] pxMqttContext The MQTT context for the MQTT connection to close.
* @param[in] pcTopicFilter Pointer to the shadow topic buffer. * @param[in] pcTopicFilter Pointer to the shadow topic buffer.
* @param[in] usTopicFilterLength Indicates the length of the shadow * @param[in] usTopicFilterLength Indicates the length of the shadow
* topic filter. * topic buffer.
* *
* @return pdPASS if SUBSCRIBE was successfully sent; * @return pdPASS if SUBSCRIBE was successfully sent;
* pdFAIL otherwise. * pdFAIL otherwise.
*/ */
BaseType_t xSubscribeToTopic( const char * pcTopicFilter, BaseType_t xSubscribeToTopic( MQTTContext_t * pxMqttContext,
const char * pcTopicFilter,
uint16_t usTopicFilterLength ); uint16_t usTopicFilterLength );
/** /**
* @brief Sends an MQTT UNSUBSCRIBE to unsubscribe from the shadow * @brief Sends an MQTT UNSUBSCRIBE to unsubscribe from the shadow
* topic. * topic.
* *
* @param[in] pcTopicFilter Pointer to the shadow topic buffer. * @param[in] pxMqttContext The MQTT context for the MQTT connection.
* @param[in] usTopicFilterLength Indicates the length of the shadow * @param[in] pcTopicFilter Pointer to the MQTT topic filter.
* topic filter. * @param[in] usTopicFilterLength Indicates the length of the topic filter.
* *
* @return pdPASS if UNSUBSCRIBE was successfully sent; * @return pdPASS if UNSUBSCRIBE was successfully sent;
* pdFAIL otherwise. * pdFAIL otherwise.
*/ */
BaseType_t xUnsubscribeFromTopic( const char * pcTopicFilter, BaseType_t xUnsubscribeFromTopic( MQTTContext_t * pxMqttContext,
const char * pcTopicFilter,
uint16_t usTopicFilterLength ); uint16_t usTopicFilterLength );
/** /**
* @brief Publish a message to a MQTT topic. * @brief Publish a message to a MQTT topic.
* *
* @param[in] pxMqttContext The MQTT context for the MQTT connection.
* @param[in] pcTopicFilter Points to the topic. * @param[in] pcTopicFilter Points to the topic.
* @param[in] topicFilterLength The length of the topic. * @param[in] topicFilterLength The length of the topic.
* @param[in] pcPayload Points to the payload. * @param[in] pcPayload Points to the payload.
@ -96,9 +112,10 @@ BaseType_t xUnsubscribeFromTopic( const char * pcTopicFilter,
* @return pdPASS if PUBLISH was successfully sent; * @return pdPASS if PUBLISH was successfully sent;
* pdFAIL otherwise. * pdFAIL otherwise.
*/ */
BaseType_t xPublishToTopic( const char * pcTopicFilter, BaseType_t xPublishToTopic( MQTTContext_t * pxMqttContext,
const char * pcTopicFilter,
int32_t topicFilterLength, int32_t topicFilterLength,
const char * pcPayload, const char * pcPayload,
size_t payloadLength ); size_t payloadLength );
#endif /* ifndef SHADOW_DEMO_HELPERS_H */ #endif /* ifndef MQTT_DEMO_HELPERS_H */