Skip to content

Commit e256c69

Browse files
committed
decreased topic buffer to 1D and commenting changes
1 parent 138a08a commit e256c69

File tree

1 file changed

+16
-43
lines changed

1 file changed

+16
-43
lines changed

main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@
2525
*/
2626

2727
/*
28-
* This file demonstrates numerous tasks all of which use the core-MQTT Agent API
29-
* to send unique MQTT payloads to unique topics over the same MQTT connection
30-
* to the same coreMQTT-Agent.
28+
* This file demonstrates the Quick Connect V2 demo which uses the core-MQTT Agent API
29+
* to publish ESP32 temperature sensor data to an MQTT broker without requiring AWS account setup.
3130
*
32-
* Each created task is a unique instance of the task implemented by
33-
* prvQuickConnectV2Task(). prvQuickConnectV2Task()
34-
* subscribes to a topic, publishes a message to the same
35-
* topic, receives the message, then unsubscribes from the topic in a loop.
36-
* The command context sent to MQTTAgent_Publish() contains a unique number that is sent back to the task
37-
* as a task notification from the callback function that executes when the
38-
* operations are acknowledged (or just sent in the case of QoS 0). The
39-
* task checks the number it receives from the callback equals the number it
40-
* previously set in the command context before printing out either a success
41-
* or failure message.
31+
* The demo creates a single task that reads the onboard temperature sensor and publishes
32+
* the temperature data in JSON format to a topic named after the thing name.
33+
* The task uses QoS 1 for reliable message delivery and includes error handling for
34+
* sensor read failures with a fallback temperature value.
35+
*
36+
* This demo is designed for quick testing and development without the complexity
37+
* of AWS IoT Core provisioning and certificate management.
4238
*/
4339

4440
/* Includes *******************************************************************/
@@ -88,7 +84,6 @@
8884

8985
/* coreMQTT-Agent event group bit definitions */
9086
#define CORE_MQTT_AGENT_CONNECTED_BIT ( 1 << 0 )
91-
#define CORE_MQTT_AGENT_OTA_NOT_IN_PROGRESS_BIT ( 1 << 1 )
9287

9388
/* MQTT event group bit definitions. */
9489
#define MQTT_PUBLISH_COMMAND_COMPLETED_BIT ( 1 << 1 )
@@ -106,14 +101,6 @@ struct MQTTAgentCommandContext
106101
void * pArgs;
107102
};
108103

109-
/**
110-
* @brief Parameters for this task.
111-
*/
112-
struct DemoParams
113-
{
114-
uint32_t ulTaskNumber;
115-
};
116-
117104
/* Global variables ***********************************************************/
118105

119106
/**
@@ -131,7 +118,7 @@ extern MQTTAgentContext_t xGlobalMqttAgentContext;
131118
Topic filter value will be the Thing-Name.
132119
*
133120
*/
134-
static char topicBuf[ 1 ][ quickconnectv2configSTRING_BUFFER_LENGTH ];
121+
static char topicBuf[ quickconnectv2configSTRING_BUFFER_LENGTH ];
135122

136123
/**
137124
* @brief The event group used to manage coreMQTT-Agent events.
@@ -299,9 +286,9 @@ static void prvPublishToTopic( MQTTQoS_t xQoS,
299286
{
300287
/* Wait for coreMQTT-Agent task to have working network connection */
301288
xEventGroupWaitBits( xNetworkEventGroup,
302-
CORE_MQTT_AGENT_CONNECTED_BIT | CORE_MQTT_AGENT_OTA_NOT_IN_PROGRESS_BIT,
289+
CORE_MQTT_AGENT_CONNECTED_BIT,
290+
pdFALSE,
303291
pdFALSE,
304-
pdTRUE,
305292
portMAX_DELAY );
306293

307294
ESP_LOGI( TAG,
@@ -317,7 +304,7 @@ static void prvPublishToTopic( MQTTQoS_t xQoS,
317304

318305
if( xCommandAdded == MQTTSuccess )
319306
{
320-
/* For QoS 1 and 2, wait for the publish acknowledgment. For QoS0,
307+
/* For QoS 1, wait for the publish acknowledgment. For QoS0,
321308
* wait for the publish to be sent. */
322309
ESP_LOGI( TAG,
323310
"Task \"%s\" waiting for publish %" PRIu32 " to complete.",
@@ -356,13 +343,9 @@ static void prvPublishToTopic( MQTTQoS_t xQoS,
356343

357344
static void prvQuickConnectV2Task( void * pvParameters )
358345
{
359-
struct DemoParams * pxParams = ( struct DemoParams * ) pvParameters;
360-
uint32_t ulTaskNumber = pxParams->ulTaskNumber;
361-
362346
EventGroupHandle_t xMqttEventGroup;
363347

364348
MQTTQoS_t xQoS;
365-
char * pcTopicBuffer = topicBuf[ ulTaskNumber ];
366349
char pcPayload[ quickconnectv2configSTRING_BUFFER_LENGTH ];
367350
float temperatureValue;
368351

@@ -372,7 +355,7 @@ static void prvQuickConnectV2Task( void * pvParameters )
372355
xQoS = ( MQTTQoS_t ) 1;
373356

374357
/* Take the topic name from thing name. */
375-
snprintf( pcTopicBuffer,
358+
snprintf( topicBuf,
376359
quickconnectv2configSTRING_BUFFER_LENGTH,
377360
"%s",
378361
configCLIENT_IDENTIFIER );
@@ -397,7 +380,7 @@ static void prvQuickConnectV2Task( void * pvParameters )
397380
temperatureValue );
398381

399382
prvPublishToTopic( xQoS,
400-
pcTopicBuffer,
383+
topicBuf,
401384
pcPayload,
402385
xMqttEventGroup );
403386

@@ -421,20 +404,12 @@ static void prvQuickConnectV2Task( void * pvParameters )
421404

422405
void vStartQuickConnectV2Demo( void )
423406
{ /* This is a single task demo*/
424-
static struct DemoParams pxParams[ 1 ];
425407
char pcTaskNameBuf[ 15 ];
426408
uint32_t ulTaskNumber;
427409

428410
xNetworkEventGroup = xEventGroupCreate();
429411
xCoreMqttAgentManagerRegisterHandler( prvCoreMqttAgentEventHandler );
430412

431-
/* Initialize the coreMQTT-Agent event group. */
432-
xEventGroupSetBits( xNetworkEventGroup,
433-
CORE_MQTT_AGENT_OTA_NOT_IN_PROGRESS_BIT );
434-
435-
/* Each instance of prvQuickConnectV2Task() generates a unique
436-
* name and topic filter for itself from the number passed in as the task
437-
* parameter. */
438413
/* Create a few instances of prvQuickConnectV2Task(). */
439414
for( ulTaskNumber = 0; ulTaskNumber < 1; ulTaskNumber++ )
440415
{
@@ -446,12 +421,10 @@ void vStartQuickConnectV2Demo( void )
446421
10,
447422
"DemoTask");
448423

449-
pxParams[ ulTaskNumber ].ulTaskNumber = ulTaskNumber;
450-
451424
xTaskCreate( prvQuickConnectV2Task,
452425
pcTaskNameBuf,
453426
quickconnectv2configTASK_STACK_SIZE,
454-
( void * ) &pxParams[ ulTaskNumber ],
427+
NULL,
455428
1, /* Task Priority */
456429
NULL );
457430
}

0 commit comments

Comments
 (0)