forked from FreeRTOS/FreeRTOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
- Loading branch information
Showing
10 changed files
with
399 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Plain_Text/DemoTasks/app_1.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* Standard includes. */ | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
/* Kernel includes. */ | ||
#include "FreeRTOS.h" | ||
#include "task.h" | ||
|
||
/* Demo Specific configs. */ | ||
#include "demo_config.h" | ||
|
||
/* MQTT library includes. */ | ||
#include "core_mqtt.h" | ||
|
||
/* Transport interface implementation include header for plaintext connection. */ | ||
#include "transport_plaintext.h" | ||
|
||
/* Defines. */ | ||
#define mqttexampleTOPIC "/example/topic" | ||
#define mqttexampleMESSAGE "Hello World!" | ||
#define mqttexampleDELAY_BETWEEN_PUBLISHES_TICKS ( pdMS_TO_TICKS( 2000U ) ) | ||
struct NetworkContext | ||
{ | ||
PlaintextTransportParams_t* pParams; | ||
}; | ||
|
||
/* Static functions. */ | ||
static void prvMQTTPublish(MQTTContext_t* pxMQTTContext); | ||
/*-----------------------------------------------------------*/ | ||
|
||
void start_app( MQTTContext_t * pMqttCtx ) | ||
{ | ||
/* Publish. */ | ||
for( ; ; ) | ||
{ | ||
prvMQTTPublish( pMqttCtx ); | ||
|
||
/* Leave connection idle for some time. */ | ||
LogInfo( ( "Keeping Connection Idle...\r\n\r\n" ) ); | ||
vTaskDelay( mqttexampleDELAY_BETWEEN_PUBLISHES_TICKS ); | ||
} | ||
} | ||
/*-----------------------------------------------------------*/ | ||
|
||
static void prvMQTTPublish( MQTTContext_t * pxMQTTContext ) | ||
{ | ||
MQTTStatus_t xResult; | ||
MQTTPublishInfo_t xMQTTPublishInfo; | ||
uint16_t usPublishPacketIdentifier; | ||
|
||
/* Some fields are not used by this demo so start with everything at 0. */ | ||
( void ) memset( ( void * ) &xMQTTPublishInfo, 0x00, sizeof( xMQTTPublishInfo ) ); | ||
|
||
xMQTTPublishInfo.qos = MQTTQoS0; | ||
xMQTTPublishInfo.retain = false; | ||
xMQTTPublishInfo.pTopicName = mqttexampleTOPIC; | ||
xMQTTPublishInfo.topicNameLength = ( uint16_t ) strlen( mqttexampleTOPIC ); | ||
xMQTTPublishInfo.pPayload = mqttexampleMESSAGE; | ||
xMQTTPublishInfo.payloadLength = strlen( mqttexampleMESSAGE ); | ||
|
||
/* Get a unique packet id. */ | ||
usPublishPacketIdentifier = MQTT_GetPacketId( pxMQTTContext ); | ||
|
||
LogInfo( ( "Publishing to the MQTT topic %s.\r\n", mqttexampleTOPIC ) ); | ||
/* Send PUBLISH packet. */ | ||
xResult = MQTT_Publish( pxMQTTContext, &xMQTTPublishInfo, usPublishPacketIdentifier ); | ||
configASSERT( xResult == MQTTSuccess ); | ||
} | ||
/*-----------------------------------------------------------*/ |
Oops, something went wrong.