Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
[submodule "FreeRTOS-Plus/Source/Application-Protocols/corePKCS11"]
path = FreeRTOS-Plus/Source/corePKCS11
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
102 changes: 66 additions & 36 deletions .../AWS/Device_Shadow_Windows_Simulator/Device_Shadow_Demo/DemoTasks/ShadowDemoMainExample.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
/* JSON library includes. */
#include "core_json.h"

/* Shadow demo helpers header. */
#include "shadow_demo_helpers.h"
/* Include MQTT demo helpers header. */
#include "mqtt_demo_helpers.h"

/* Demo Specific configs. */
/* Demo Specific config file. */
#include "demo_config.h"


Expand Down Expand Up @@ -148,24 +148,42 @@
*/
#define SHADOW_REPORTED_JSON_LENGTH ( sizeof( SHADOW_REPORTED_JSON ) - 3 )

#ifndef THING_NAME
/*------------- Demo configurations -------------------------*/

#ifndef democonfigTHING_NAME
#define democonfigTHING_NAME democonfigCLIENT_IDENTIFIER
#endif

/**
* @brief Predefined thing name.
*
* This is the example predefine thing name and could be compiled in ROM code.
* @brief The length of #democonfigTHING_NAME.
*/
#define THING_NAME democonfigCLIENT_IDENTIFIER
#endif
#define THING_NAME_LENGTH ( ( uint16_t ) ( sizeof( democonfigTHING_NAME ) - 1 ) )

/*-----------------------------------------------------------*/

/**
* @brief The length of #THING_NAME.
* @brief The MQTT context used for MQTT operation.
*/
#define THING_NAME_LENGTH ( ( uint16_t ) ( sizeof( THING_NAME ) - 1 ) )
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.
Expand Down Expand Up @@ -523,22 +541,22 @@ static void prvEventCallback( MQTTContext_t * pxMqttContext,
/*-----------------------------------------------------------*/

/*
* @brief Create the task that demonstrates the Shadow API Demo via a
* MQTT mutually authenticated network connection with MQTT broker.
* @brief Create the task that demonstrates the Device Shadow library API via a
* MQTT mutually authenticated network connection with the AWS IoT broker.
*/
void vStartShadowDemo( void )
{
/* This example uses a single application task, which shows that how to
* use Device Shadow library to get shadow topics and validate shadow topics
* via MQTT APIs communicating with the MQTT broker. */
* use Device Shadow library to generate and validate AWS IoT Device Shadow
* MQTT topics, and use the coreMQTT library to communicate with the AWS IoT
* Device Shadow service. */
xTaskCreate( prvShadowDemoTask, /* Function that implements the task. */
"ShadowDemo", /* 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. */
NULL, /* Task parameter - not used in this case. */
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. */
}

/*-----------------------------------------------------------*/

/**
Expand All @@ -564,14 +582,17 @@ void prvShadowDemoTask( void * pvParameters )
{
BaseType_t demoStatus = pdPASS;

/* Remove compiler warnings about unused parameters. */
( void ) pvParameters;

/* A buffer containing the update document. It has static duration to prevent
* it from being placed on the call stack. */
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 )
{
Expand All @@ -581,31 +602,35 @@ void prvShadowDemoTask( void * pvParameters )
else
{
/* 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 ),
pcUpdateDocument,
0U );

/* Then try to subscribe shadow topics. */
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 ) );
}

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 ) );
}

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 ) );
}

/* 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.
* 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:
Expand Down Expand Up @@ -651,7 +676,8 @@ void prvShadowDemoTask( void * pvParameters )
( int ) 1,
( 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 ),
pcUpdateDocument,
( SHADOW_DESIRED_JSON_LENGTH + 1 ) );
Expand Down Expand Up @@ -683,7 +709,8 @@ void prvShadowDemoTask( void * pvParameters )
( int ) ulCurrentPowerOnState,
( 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 ),
pcUpdateDocument,
( SHADOW_DESIRED_JSON_LENGTH + 1 ) );
Expand All @@ -698,42 +725,45 @@ void prvShadowDemoTask( void * pvParameters )
{
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 ) );

if( demoStatus != pdPASS )
{
LogError( ( "Failed to unsubscribe the topic %s",
SHADOW_TOPIC_STRING_UPDATE_DELTA( THING_NAME ) ) );
SHADOW_TOPIC_STRING_UPDATE_DELTA( democonfigTHING_NAME ) ) );
}
}

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 ) );

if( demoStatus != pdPASS )
{
LogError( ( "Failed to unsubscribe the topic %s",
SHADOW_TOPIC_STRING_UPDATE_ACCEPTED( THING_NAME ) ) );
SHADOW_TOPIC_STRING_UPDATE_ACCEPTED( democonfigTHING_NAME ) ) );
}
}

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 ) );

if( demoStatus != pdPASS )
{
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. */
demoStatus = xDisconnectMqttSession();
demoStatus = xDisconnectMqttSession( &xMqttContext, &xNetworkContext );

/* This demo performs only Device Shadow operations. If matching the Shadow
* MQTT topic fails or there are failure in parsing the received JSON document,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
Prop3=19,11
[InternetShortcut]
IDList=
URL=https://www.freertos.org/shadow/index.html
URL=https://www.freertos.org/iot-device-shadow/index.html

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</Midl>
<ClCompile>
<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>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
Expand Down Expand Up @@ -490,7 +490,7 @@
<ClCompile Include="..\..\..\..\..\FreeRTOS-Plus\Demo\Common\Logging\windows\Logging_WinSim.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\ShadowDemoMainExample.c" />
<ClCompile Include="DemoTasks\shadow_demo_helpers.c" />
<ClCompile Include="..\..\Mqtt_Demo_Helpers\mqtt_demo_helpers.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\FreeRTOS\Source\include\event_groups.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@
#define LIBRARY_LOG_LEVEL LOG_ERROR
#endif

/* Prototype for the function used to print to console on Windows simulator
* of FreeRTOS.
* The function prints to the console before the network is connected;
* then a UDP port after the network has connected. */
extern void vLoggingPrintf( const char * pcFormatString,
... );

/* Map the SdkLog macro to the logging function to enable logging
* on Windows simulator. */
#ifndef SdkLog
#define SdkLog( message ) vLoggingPrintf message
#endif

#include "logging_stack.h"
/************ End of logging configuration ****************/

Expand Down
Loading