From d725313985b45cf7eb33d6376c8d4841ab70d1cf Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Tue, 14 Oct 2025 15:49:37 -0700 Subject: [PATCH 01/14] Add Quick Connect V2 Demo --- main/CMakeLists.txt | 9 + main/Kconfig.projbuild | 11 +- .../GettingStartedWithQuickConnect.md | 77 +++ .../quickconnect_v2_demo.c | 461 ++++++++++++++++++ .../quickconnect_v2_demo.h | 38 ++ .../quickconnect_v2_demo_config.h | 89 ++++ main/main.c | 8 + 7 files changed, 690 insertions(+), 3 deletions(-) create mode 100644 main/demo_tasks/quickconnect_v2_demo/GettingStartedWithQuickConnect.md create mode 100644 main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c create mode 100644 main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.h create mode 100644 main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 9887e89..e6fa7ee 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -13,6 +13,14 @@ if(CONFIG_GRI_ENABLE_SUB_PUB_UNSUB_DEMO) list(APPEND MAIN_SRCS "demo_tasks/sub_pub_unsub_demo/sub_pub_unsub_demo.c") endif() +# QuickConnect V2 demo +if(CONFIG_GRI_ENABLE_QUICKCONNECT_V2_DEMO) + list(APPEND MAIN_SRCS + "demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c" + "demo_tasks/temp_sub_pub_and_led_control_demo/hardware_drivers/app_driver.c" + ) +endif() + # Temperature Sub Pub and LED control demo if(CONFIG_GRI_ENABLE_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO) list(APPEND MAIN_SRCS @@ -37,6 +45,7 @@ set(MAIN_INCLUDE_DIRS "." "demo_tasks/ota_over_mqtt_demo" "demo_tasks/sub_pub_unsub_demo" + "demo_tasks/quickconnect_v2_demo" "demo_tasks/temp_sub_pub_and_led_control_demo" "demo_tasks/temp_sub_pub_and_led_control_demo/hardware_drivers" "networking/wifi" diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index 7d9136b..5d8263f 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -253,9 +253,14 @@ menu "Featured FreeRTOS IoT Integration" endmenu # coreMQTT-Agent Manager Configurations + config GRI_ENABLE_QUICKCONNECT_V2_DEMO + bool "Enable QuickConnect V2 demo" + depends on !GRI_RUN_QUALIFICATION_TEST + default n + config GRI_ENABLE_SUB_PUB_UNSUB_DEMO bool "Enable pub sub unsub demo" - depends on !GRI_RUN_QUALIFICATION_TEST + depends on !GRI_RUN_QUALIFICATION_TEST && !GRI_ENABLE_QUICKCONNECT_V2_DEMO default y menu "Sub pub unsub demo configurations" @@ -308,7 +313,7 @@ menu "Featured FreeRTOS IoT Integration" config GRI_ENABLE_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO bool "Enable temperature sensor pub sub and LED control demo" - depends on !GRI_RUN_QUALIFICATION_TEST + depends on !GRI_RUN_QUALIFICATION_TEST && !GRI_ENABLE_QUICKCONNECT_V2_DEMO default y menu "Temperature pub sub and LED control demo configurations" @@ -378,7 +383,7 @@ menu "Featured FreeRTOS IoT Integration" config GRI_ENABLE_OTA_DEMO bool "Enable OTA demo" - depends on !GRI_RUN_QUALIFICATION_TEST + depends on !GRI_RUN_QUALIFICATION_TEST && !GRI_ENABLE_QUICKCONNECT_V2_DEMO default y menu "OTA demo configurations" diff --git a/main/demo_tasks/quickconnect_v2_demo/GettingStartedWithQuickConnect.md b/main/demo_tasks/quickconnect_v2_demo/GettingStartedWithQuickConnect.md new file mode 100644 index 0000000..4d20ce7 --- /dev/null +++ b/main/demo_tasks/quickconnect_v2_demo/GettingStartedWithQuickConnect.md @@ -0,0 +1,77 @@ +# Getting Started With Quick Connect V2 Guide + +**_NOTE:_** This guide covers only Quick Connect V2. For all other demos, please refer to the [Getting Started Guide](../../../GettingStartedGuide.md). + +This guide contains instructions on how to setup, build and run only the Quick Connect V2 demo +without use of the security features of the ESP32-C3 i.e. without enabling the +DS peripheral, flash encryption and Secure Boot. The guide is meant to provide the +user with a friendly first-use experience. + +[1 Pre-requisites](#1-pre-requisites)
+ +[2 Demo setup](#2-demo-setup)
+ +[3 Build and flash the demo project](#3-build-and-flash-the-demo-project)
+ +[4 Monitoring the demo](#4-monitoring-the-demo)
+ + +## 1 Pre-requisites + +For hardware and software requirements, refer to sections [1.1 Hardware Requirements](../../../GettingStartedGuide.md#11-hardware-requirements) and [1.2 Software Requirements](../../../GettingStartedGuide.md#12-software-requirements) in the [Getting Started Guide](../../../GettingStartedGuide.md) + +## 2 Demo setup + +### 2.1 Get credentials from Quick Connect V2 + +To get credentials for your device (Thing), visit [Quick Connect Credentials](https://quickconnect.iot.aws.dev/credentials) page and enter a desired device name (Thing Name) in the `Vend Credentials` section, and click the Vend button. Download both the `.crt` and `.key` files. These are your **PEM-encoded device certificate** and **PEM-encoded private key**. (An explanation of these entities is given in the [AWS IoT Core Setup Guide](AWSSetup.md).) + +### 2.2 Configure the project with the AWS IoT Thing Name and AWS device Endpoint + +The **AWS device Endpoint** is provided on the [Quick Connect Examples](https://quickconnect.iot.aws.dev) page. + +Follow the [2.2 Configure the project](../../../GettingStartedGuide.md#22-configure-the-project-with-the-aws-iot-thing-name-and-aws-device-endpoint) section in the [Getting Started Guide](../../../GettingStartedGuide.md) to configure your project. + + +### 2.3 Provision the ESP32-C3 with the private key, device certificate and CA certificate in Development Mode + +For Quick Connect, use the following specific values: + +- `CA_CERT_FILEPATH`: Use the file in the `main/certs` directory, or download the AWS Root CA certificate from [here](https://www.amazontrust.com/repository/AmazonRootCA1.pem). +- `DEVICE_CERT_FILEPATH`: The file path to the PEM-encoded device certificate (`.crt` file downloaded from the Quick Connect Website) +- `PRIVATE_KEY_FILEPATH`: The file path to the PEM-encoded private key (`.key` file downloaded from the Quick Connect Website) +- `KEY_ALG_INFO`: Use `RSA 2048` + +For complete provisioning instructions, follow the [2.3 Provision the ESP32-C3](../../../GettingStartedGuide.md#23-provision-the-esp32-c3-with-the-private-key-device-certificate-and-ca-certificate-in-development-mode) section in the [Getting Started Guide](../../../GettingStartedGuide.md). + + +## 3 Build and flash the demo project + +For build and flash instructions, follow [3 Build and flash](../../../GettingStartedGuide.md#3-build-and-flash-the-demo-project) section of the [Getting Started Guide](../../../GettingStartedGuide.md). + +## 4 Monitoring the demo + +1. On the serial terminal console, confirm that the TLS connection was +successful and that MQTT messages are published. + +```c +I (4115) core_mqtt_agent_manager: WiFi connected. +I (4115) app_wifi: Connected with IP Address:10.0.0.9 +I (4115) esp_netif_handlers: sta ip: 10.0.0.9, mask: 255.255.255.0, gw: 10.0.0.1 +I (4115) main_task: Returned from app_main() +I (4685) core_mqtt_agent_manager: TLS connection established. +I (5025) coreMQTT: MQTT connection established with the broker. +I (5025) core_mqtt_agent_manager: Session present: 0 + +I (5025) quickconnect_v2_demo: coreMQTT-Agent connected. +I (5025) core_mqtt_agent_manager: coreMQTT-Agent connected. +I (5025) quickconnect_v2_demo: Task "DemoTask" sending publish request to coreMQTT-Agent with message [{"label":"ESP32-S3 MCU Temperature","display_type":"line_graph","unit":"C","values":[{"value":0.0,"label":"temp"}]}] on topic "Thing-name" with ID 1. +I (5055) quickconnect_v2_demo: Task "DemoTask" waiting for publish 1 to complete. +I (5175) coreMQTT: Ack packet deserialized with result: MQTTSuccess. +I (5175) coreMQTT: State record updated. New state=MQTTPublishDone. + +``` + +2. On the [Quick Connect Visualizer](https://quickconnect.iot.aws.dev/visualizer) page, enter your device name (Thing name) in the `Visualizing device data` section, then confirm that the MQTT messages from the device are being received and a graph is being displayed. + +**Note**: This demo sends data in line graph format only. For other data visualization formats, refer to the [Quick Connect](https://quickconnect.iot.aws.dev/) documentation. \ No newline at end of file diff --git a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c new file mode 100644 index 0000000..f421df5 --- /dev/null +++ b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c @@ -0,0 +1,461 @@ +/* + * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 + * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/* + * This file demonstrates numerous tasks all of which use the core-MQTT Agent API + * to send unique MQTT payloads to unique topics over the same MQTT connection + * to the same coreMQTT-Agent. + * + * Each created task is a unique instance of the task implemented by + * prvQuickConnectV2Task(). prvQuickConnectV2Task() + * subscribes to a topic, publishes a message to the same + * topic, receives the message, then unsubscribes from the topic in a loop. + * The command context sent to MQTTAgent_Publish() contains a unique number that is sent back to the task + * as a task notification from the callback function that executes when the + * operations are acknowledged (or just sent in the case of QoS 0). The + * task checks the number it receives from the callback equals the number it + * previously set in the command context before printing out either a success + * or failure message. + */ + +/* Includes *******************************************************************/ + +/* Standard includes. */ +#include +#include +#include + +/* FreeRTOS includes. */ +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/event_groups.h" + +/* ESP-IDF includes. */ +#include "esp_log.h" +#include "esp_event.h" +#include "sdkconfig.h" + +/* coreMQTT library include. */ +#include "core_mqtt.h" + +/* coreMQTT-Agent include. */ +#include "core_mqtt_agent.h" + +/* coreMQTT-Agent network manager include. */ +#include "core_mqtt_agent_manager.h" +#include "core_mqtt_agent_manager_events.h" + +/* Subscription manager include. */ +#include "subscription_manager.h" + +/* Public functions include. */ +#include "quickconnect_v2_demo.h" + +/* Demo task configurations include. */ +#include "quickconnect_v2_demo_config.h" + +/* Hardware drivers include. */ +#include "app_driver.h" + +/* coreMQTT-Agent manager configurations include. */ +#include "core_mqtt_agent_manager_config.h" + +/* Preprocessor definitions ***************************************************/ + +/* coreMQTT-Agent event group bit definitions */ +#define CORE_MQTT_AGENT_CONNECTED_BIT ( 1 << 0 ) +#define CORE_MQTT_AGENT_OTA_NOT_IN_PROGRESS_BIT ( 1 << 1 ) + +/* MQTT event group bit definitions. */ +#define MQTT_PUBLISH_COMMAND_COMPLETED_BIT ( 1 << 1 ) + +/* Struct definitions *********************************************************/ + +/** + * @brief Defines the structure to use as the command callback context in this + * demo. + */ +struct MQTTAgentCommandContext +{ + MQTTStatus_t xReturnStatus; + EventGroupHandle_t xMqttEventGroup; + void * pArgs; +}; + +/** + * @brief Parameters for this task. + */ +struct DemoParams +{ + uint32_t ulTaskNumber; +}; + +/* Global variables ***********************************************************/ + +/** + * @brief Logging tag for ESP-IDF logging functions. + */ +static const char * TAG = "quickconnect_v2_demo"; + +/** + * @brief Static handle used for MQTT agent context. + */ +extern MQTTAgentContext_t xGlobalMqttAgentContext; + +/** + * @brief The buffer to hold the topic filter. The topic is generated at runtime + * by adding the task names. + * + */ +static char topicBuf[ quickconnectv2configNUM_TASKS_TO_CREATE ][ quickconnectv2configSTRING_BUFFER_LENGTH ]; + +/** + * @brief The event group used to manage coreMQTT-Agent events. + */ +static EventGroupHandle_t xNetworkEventGroup; + +/** + * @brief The semaphore used to lock access to ulMessageID to eliminate a race + * condition in which multiple tasks try to increment/get ulMessageID. + */ +static SemaphoreHandle_t xMessageIdSemaphore; + +/** + * @brief The message ID for the next message sent by this demo. + */ +static uint32_t ulMessageId = 0; + +/* Static function declarations ***********************************************/ + +/** + * @brief ESP Event Loop library handler for coreMQTT-Agent events. + * + * This handles events defined in core_mqtt_agent_events.h. + */ +static void prvCoreMqttAgentEventHandler( void * pvHandlerArg, + esp_event_base_t xEventBase, + int32_t lEventId, + void * pvEventData ); + +/** + * @brief Passed into MQTTAgent_Publish() as the callback to execute when the + * broker ACKs the PUBLISH message. Its implementation sends a notification + * to the task that called MQTTAgent_Publish() to let the task know the + * PUBLISH operation completed. It also sets the xReturnStatus of the + * structure passed in as the command's context to the value of the + * xReturnStatus parameter - which enables the task to check the status of the + * operation. + * + * See https://freertos.org/mqtt/mqtt-agent-demo.html#example_mqtt_api_call + * + * @param[in] pxCommandContext Context of the initial command. + * @param[in].xReturnStatus The result of the command. + */ +static void prvPublishCommandCallback( MQTTAgentCommandContext_t * pxCommandContext, + MQTTAgentReturnInfo_t * pxReturnInfo ); + +/** + * @brief Called by the task to wait for event from a callback function + * after the task first executes either MQTTAgent_Publish() + * + * See https://freertos.org/mqtt/mqtt-agent-demo.html#example_mqtt_api_call + * + * @param[in] xMqttEventGroup Event group used for MQTT events. + * @param[in] uxBitsToWaitFor Event to wait for. + * + * @return Received event. + */ +static EventBits_t prvWaitForEvent( EventGroupHandle_t xMqttEventGroup, + EventBits_t uxBitsToWaitFor ); + +/** + * @brief The function that implements the task demonstrated by this file. + */ +static void prvQuickConnectV2Task( void * pvParameters ); + +/* Static function definitions ************************************************/ + +static void prvCoreMqttAgentEventHandler( void * pvHandlerArg, + esp_event_base_t xEventBase, + int32_t lEventId, + void * pvEventData ) +{ + ( void ) pvHandlerArg; + ( void ) xEventBase; + ( void ) pvEventData; + + switch( lEventId ) + { + case CORE_MQTT_AGENT_CONNECTED_EVENT: + ESP_LOGI( TAG, + "coreMQTT-Agent connected." ); + xEventGroupSetBits( xNetworkEventGroup, + CORE_MQTT_AGENT_CONNECTED_BIT ); + break; + + case CORE_MQTT_AGENT_DISCONNECTED_EVENT: + ESP_LOGI( TAG, + "coreMQTT-Agent disconnected. Preventing coreMQTT-Agent " + "commands from being enqueued." ); + xEventGroupClearBits( xNetworkEventGroup, + CORE_MQTT_AGENT_CONNECTED_BIT ); + break; + + default: + ESP_LOGE( TAG, + "coreMQTT-Agent event handler received unexpected event: %" PRIu32 "", + lEventId ); + break; + } +} + +static void prvPublishCommandCallback( MQTTAgentCommandContext_t * pxCommandContext, + MQTTAgentReturnInfo_t * pxReturnInfo ) +{ + /* Store the result in the application defined context so the task that + * initiated the publish can check the operation's status. */ + pxCommandContext->xReturnStatus = pxReturnInfo->returnCode; + + if( pxCommandContext->xMqttEventGroup != NULL ) + { + xEventGroupSetBits( pxCommandContext->xMqttEventGroup, + MQTT_PUBLISH_COMMAND_COMPLETED_BIT ); + } +} + +static EventBits_t prvWaitForEvent( EventGroupHandle_t xMqttEventGroup, + EventBits_t uxBitsToWaitFor ) +{ + EventBits_t xReturn; + + xReturn = xEventGroupWaitBits( xMqttEventGroup, + uxBitsToWaitFor, + pdTRUE, /* xClearOnExit. */ + pdTRUE, /* xWaitForAllBits. */ + portMAX_DELAY ); + return xReturn; +} + +static void prvPublishToTopic( MQTTQoS_t xQoS, + char * pcTopicName, + char * pcPayload, + EventGroupHandle_t xMqttEventGroup ) +{ + uint32_t ulPublishMessageId = 0; + + MQTTStatus_t xCommandAdded; + EventBits_t xReceivedEvent = 0; + + MQTTPublishInfo_t xPublishInfo = { 0 }; + + MQTTAgentCommandContext_t xCommandContext = { 0 }; + MQTTAgentCommandInfo_t xCommandParams = { 0 }; + + xTaskNotifyStateClear( NULL ); + + /* Create a unique number for the publish that is about to be sent. + * This number is used in the command context and is sent back to this task + * as a notification in the callback that's executed upon receipt of the + * publish from coreMQTT-Agent. + * That way this task can match an acknowledgment to the message being sent. + */ + xSemaphoreTake( xMessageIdSemaphore, portMAX_DELAY ); + { + ++ulMessageId; + ulPublishMessageId = ulMessageId; + } + xSemaphoreGive( xMessageIdSemaphore ); + + /* Configure the publish operation. The topic name string must persist for + * duration of publish! */ + xPublishInfo.qos = xQoS; + xPublishInfo.pTopicName = pcTopicName; + xPublishInfo.topicNameLength = ( uint16_t ) strlen( pcTopicName ); + xPublishInfo.pPayload = pcPayload; + xPublishInfo.payloadLength = ( uint16_t ) strlen( pcPayload ); + + /* Complete an application defined context associated with this publish + * message. + * This gets updated in the callback function so the variable must persist + * until the callback executes. */ + xCommandContext.xMqttEventGroup = xMqttEventGroup; + + xCommandParams.blockTimeMs = quickconnectv2configMAX_COMMAND_SEND_BLOCK_TIME_MS; + xCommandParams.cmdCompleteCallback = prvPublishCommandCallback; + xCommandParams.pCmdCompleteCallbackContext = &xCommandContext; + + do + { + /* Wait for coreMQTT-Agent task to have working network connection */ + xEventGroupWaitBits( xNetworkEventGroup, + CORE_MQTT_AGENT_CONNECTED_BIT | CORE_MQTT_AGENT_OTA_NOT_IN_PROGRESS_BIT, + pdFALSE, + pdTRUE, + portMAX_DELAY ); + + ESP_LOGI( TAG, + "Task \"%s\" sending publish request to coreMQTT-Agent with message \"%s\" on topic \"%s\" with ID %" PRIu32 ".", + pcTaskGetName( NULL ), + pcPayload, + pcTopicName, + ulPublishMessageId ); + + xCommandAdded = MQTTAgent_Publish( &xGlobalMqttAgentContext, + &xPublishInfo, + &xCommandParams ); + + if( xCommandAdded == MQTTSuccess ) + { + /* For QoS 1 and 2, wait for the publish acknowledgment. For QoS0, + * wait for the publish to be sent. */ + ESP_LOGI( TAG, + "Task \"%s\" waiting for publish %" PRIu32 " to complete.", + pcTaskGetName( NULL ), + ulPublishMessageId ); + + xReceivedEvent = prvWaitForEvent( xMqttEventGroup, + MQTT_PUBLISH_COMMAND_COMPLETED_BIT ); + } + else + { + ESP_LOGE( TAG, + "Failed to enqueue publish command. Error code=%s", + MQTT_Status_strerror( xCommandAdded ) ); + } + + /* Check all ways the status was passed back just for demonstration + * purposes. */ + if( ( ( xReceivedEvent & MQTT_PUBLISH_COMMAND_COMPLETED_BIT ) == 0 ) || + ( xCommandContext.xReturnStatus != MQTTSuccess ) ) + { + ESP_LOGW( TAG, + "Error or timed out waiting for ack for publish message %" PRIu32 ". Re-attempting publish.", + ulPublishMessageId ); + } + else + { + ESP_LOGI( TAG, + "Publish %" PRIu32 " succeeded for task \"%s\".", + ulPublishMessageId, + pcTaskGetName( NULL ) ); + } + } while( ( xReceivedEvent & MQTT_PUBLISH_COMMAND_COMPLETED_BIT ) == 0 || + ( xCommandContext.xReturnStatus != MQTTSuccess ) ); +} + +static void prvQuickConnectV2Task( void * pvParameters ) +{ + struct DemoParams * pxParams = ( struct DemoParams * ) pvParameters; + uint32_t ulTaskNumber = pxParams->ulTaskNumber; + + EventGroupHandle_t xMqttEventGroup; + + MQTTQoS_t xQoS; + char * pcTopicBuffer = topicBuf[ ulTaskNumber ]; + char pcPayload[ quickconnectv2configSTRING_BUFFER_LENGTH ]; + float temperatureValue; + + xMqttEventGroup = xEventGroupCreate(); + + xQoS = ( MQTTQoS_t ) quickconnectv2configQOS_LEVEL; + + /* Take the topic name from thing name. */ + snprintf( pcTopicBuffer, + quickconnectv2configSTRING_BUFFER_LENGTH, + "%s", + configCLIENT_IDENTIFIER ); + + while( 1 ) + { + temperatureValue = app_driver_temp_sensor_read_celsius(); + + /* Create Payload in an Array format */ + snprintf( pcPayload, + quickconnectv2configSTRING_BUFFER_LENGTH, + "[{\"label\":\"ESP32-S3 MCU Temperature\",\"display_type\":\"line_graph\",\"unit\":\"C\",\"values\":[{\"value\":%.1f,\"label\":\"temp\"}]}]", + temperatureValue ); + + prvPublishToTopic( xQoS, + pcTopicBuffer, + pcPayload, + xMqttEventGroup ); + + ESP_LOGI( TAG, + "Task \"%s\" published: %s", + pcTaskGetName( NULL ), + pcPayload ); + + ESP_LOGI( TAG, + "Task \"%s\" completed a loop. Delaying before next loop.", + pcTaskGetName( NULL ) ); + + vTaskDelay( pdMS_TO_TICKS( quickconnectv2configDELAY_BETWEEN_LOOPS_MS ) ); + } + + vEventGroupDelete( xMqttEventGroup ); + vTaskDelete( NULL ); +} + +/* Public function definitions ************************************************/ + +void vStartQuickConnectV2Demo( void ) +{ + static struct DemoParams pxParams[ quickconnectv2configNUM_TASKS_TO_CREATE ]; + char pcTaskNameBuf[ 30 ]; + uint32_t ulTaskNumber; + + xMessageIdSemaphore = xSemaphoreCreateMutex(); + xNetworkEventGroup = xEventGroupCreate(); + xCoreMqttAgentManagerRegisterHandler( prvCoreMqttAgentEventHandler ); + + /* Initialize the coreMQTT-Agent event group. */ + xEventGroupSetBits( xNetworkEventGroup, + CORE_MQTT_AGENT_OTA_NOT_IN_PROGRESS_BIT ); + + /* Each instance of prvQuickConnectV2Task() generates a unique + * name and topic filter for itself from the number passed in as the task + * parameter. */ + /* Create a few instances of prvQuickConnectV2Task(). */ + for( ulTaskNumber = 0; ulTaskNumber < quickconnectv2configNUM_TASKS_TO_CREATE; ulTaskNumber++ ) + { + memset( pcTaskNameBuf, + 0x00, + sizeof( pcTaskNameBuf ) ); + + snprintf( pcTaskNameBuf, + 30, + "DemoTask"); + + pxParams[ ulTaskNumber ].ulTaskNumber = ulTaskNumber; + + xTaskCreate( prvQuickConnectV2Task, + pcTaskNameBuf, + quickconnectv2configTASK_STACK_SIZE, + ( void * ) &pxParams[ ulTaskNumber ], + quickconnectv2configTASK_PRIORITY, + NULL ); + } +} diff --git a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.h b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.h new file mode 100644 index 0000000..6375c39 --- /dev/null +++ b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.h @@ -0,0 +1,38 @@ +/* + * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 + * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#ifndef QUICKCONNECT_V2_DEMO_H +#define QUICKCONNECT_V2_DEMO_H + +/** + * @brief Start the Quick Connect V2 demo. + * + * This function creates tasks that demonstrate publishing to AWS IoT Core + * using the Quick Connect V2 format. + */ +void vStartQuickConnectV2Demo( void ); + +#endif /* QUICKCONNECT_V2_DEMO_H */ \ No newline at end of file diff --git a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h new file mode 100644 index 0000000..d089c55 --- /dev/null +++ b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h @@ -0,0 +1,89 @@ +/* + * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 + * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#ifndef QUICKCONNECT_V2_DEMO_CONFIG_H +#define QUICKCONNECT_V2_DEMO_CONFIG_H + +/* ESP-IDF sdkconfig include. */ +#include + +#if CONFIG_GRI_RUN_QUALIFICATION_TEST + #include "qualification_wrapper_config.h" +#endif /* CONFIG_GRI_RUN_QUALIFICATION_TEST */ + +/* *INDENT-OFF* */ + #ifdef __cplusplus + extern "C" { + #endif +/* *INDENT-ON* */ + +/** + * @brief Size of statically allocated buffers for holding topic names and + * payloads. + */ +#define quickconnectv2configSTRING_BUFFER_LENGTH ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_STRING_BUFFER_LENGTH ) ) + +/** + * @brief Delay for each task between each publish. + */ +#define quickconnectv2configDELAY_BETWEEN_LOOPS_MS ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_DELAY_BETWEEN_SUB_PUB_UNSUB_LOOPS_MS ) ) + +/** + * @brief The maximum amount of time in milliseconds to wait for the commands + * to be posted to the MQTT agent should the MQTT agent's command queue be full. + * Tasks wait in the Blocked state, so don't use any CPU time. + */ +#define quickconnectv2configMAX_COMMAND_SEND_BLOCK_TIME_MS ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS ) ) + +/** + * @brief The QoS level of MQTT messages sent by this demo. This must be 0 or 1 + * if using AWS as AWS only supports levels 0 or 1. If using another MQTT broker + * that supports QoS level 2, this can be set to 2. + */ +#define quickconnectv2configQOS_LEVEL ( ( unsigned long ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_QOS_LEVEL ) ) + +/** + * @brief The number of Quick Connect Demo tasks to create for this demo. + */ +#define quickconnectv2configNUM_TASKS_TO_CREATE ( ( unsigned long ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_NUM_TASKS_TO_CREATE ) ) + +/** + * @brief The task priority of each of the Quick Connect Demo tasks. + */ +#define quickconnectv2configTASK_PRIORITY ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_TASK_PRIORITY ) ) + +/** + * @brief The task stack size for each of the Quick Connect Demo tasks. + */ +#define quickconnectv2configTASK_STACK_SIZE ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_TASK_STACK_SIZE ) ) + +/* *INDENT-OFF* */ + #ifdef __cplusplus + } /* extern "C" */ + #endif +/* *INDENT-ON* */ + +#endif /* QUICKCONNECT_V2_DEMO_CONFIG_H */ diff --git a/main/main.c b/main/main.c index 1a088fd..7ac947b 100644 --- a/main/main.c +++ b/main/main.c @@ -60,6 +60,10 @@ #include "sub_pub_unsub_demo.h" #endif /* CONFIG_GRI_ENABLE_SUB_PUB_UNSUB_DEMO */ +#if CONFIG_GRI_ENABLE_QUICKCONNECT_V2_DEMO + #include "quickconnect_v2_demo.h" +#endif /* CONFIG_GRI_ENABLE_QUICKCONNECT_V2_DEMO */ + #if CONFIG_GRI_ENABLE_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO #include "temp_sub_pub_and_led_control_demo.h" #endif /* CONFIG_GRI_ENABLE_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO */ @@ -253,6 +257,10 @@ static void prvStartEnabledDemos( void ) BaseType_t xResult; #if ( CONFIG_GRI_RUN_QUALIFICATION_TEST == 0 ) + #if CONFIG_GRI_ENABLE_QUICKCONNECT_V2_DEMO + vStartQuickConnectV2Demo(); + #endif /* CONFIG_GRI_ENABLE_QUICKCONNECT_V2_DEMO */ + #if CONFIG_GRI_ENABLE_SUB_PUB_UNSUB_DEMO vStartSubscribePublishUnsubscribeDemo(); #endif /* CONFIG_GRI_ENABLE_SIMPLE_PUB_SUB_DEMO */ From 138a08a97cb0cdf0fec07834d1d48b9a419bef54 Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Wed, 15 Oct 2025 16:06:44 -0700 Subject: [PATCH 02/14] simplified Quick Connect demo by removing semaphores and adding temperature sensors --- GettingStartedGuide.md | 6 ++ main/CMakeLists.txt | 2 +- main/Kconfig.projbuild | 29 ++++++++ ...dWithQuickConnect.md => GettingStarted.md} | 11 +-- .../quickconnect_v2_demo.c | 69 +++++++++---------- .../quickconnect_v2_demo_config.h | 29 ++------ 6 files changed, 80 insertions(+), 66 deletions(-) rename main/demo_tasks/quickconnect_v2_demo/{GettingStartedWithQuickConnect.md => GettingStarted.md} (78%) diff --git a/GettingStartedGuide.md b/GettingStartedGuide.md index 898eb51..b5cbacc 100644 --- a/GettingStartedGuide.md +++ b/GettingStartedGuide.md @@ -16,6 +16,7 @@ Once completed, one can progress to the  [2.1 Setup AWS IoT Core](#21-setup-aws-iot-core)
 [2.2 Configure the project with the AWS IoT Thing Name and AWS device Endpoint](#22-configure-the-project-with-the-aws-iot-thing-name-and-aws-device-endpoint)
 [2.3 Provision the ESP32-C3 with the private key, device certificate and CA certificate in Development Mode](#23-provision-the-esp32-c3-with-the-private-key-device-certificate-and-ca-certificate-in-development-mode)
+ [2.4 Quick Connect demo](#24-quick-connect-demo)
[3 Build and flash the demo project](#3-build-and-flash-the-demo-project)
@@ -154,6 +155,11 @@ python managed_components/espressif__esp_secure_cert_mgr/tools/configure_esp_sec > **NOTE:** For convenience sake, you could place your key and certificate files under the `main/certs` directory. +### 2.4 Quick Connect demo + +The Quick Connect demo differs from other demos as it does not require an AWS account. Refer to the [Getting Started Guide](./main/demo_tasks/quickconnect_v2_demo/GettingStarted.md) + + ## 3 Build and flash the demo project Before you build and flash the demo project, if you are setting up the ESP32-C3 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index e6fa7ee..62788fe 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -17,7 +17,6 @@ endif() if(CONFIG_GRI_ENABLE_QUICKCONNECT_V2_DEMO) list(APPEND MAIN_SRCS "demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c" - "demo_tasks/temp_sub_pub_and_led_control_demo/hardware_drivers/app_driver.c" ) endif() @@ -65,6 +64,7 @@ set(MAIN_REQUIRES FreeRTOS-Libraries-Integration-Tests unity driver + esp_driver_tsens ) idf_component_register( diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index 5d8263f..a8a7e8a 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -258,6 +258,35 @@ menu "Featured FreeRTOS IoT Integration" depends on !GRI_RUN_QUALIFICATION_TEST default n + menu "Quick connect V2 demo configurations" + depends on GRI_ENABLE_QUICKCONNECT_V2_DEMO + + config GRI_QUICKCONNECT_V2_DEMO_STRING_BUFFER_LENGTH + int "Topic name and payload buffer length" + default 700 + help + Size of statically allocated buffers for holding topic names and payloads. + + config GRI_QUICKCONNECT_V2_DEMO_DELAY_BETWEEN_PUB_LOOPS_MS + int "Delay between publish loops in milliseconds" + default 1000 + help + Delay for each task between publish loops. + + config GRI_QUICKCONNECT_V2_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS + int "coreMQTT-Agent command post block time in milliseconds." + default 500 + help + The maximum amount of time in milliseconds to wait for the commands to be posted to the MQTT agent should the MQTT agent's command queue be full. Tasks wait in the Blocked state, so don't use any CPU time. + + config GRI_QUICKCONNECT_V2_DEMO_TASK_STACK_SIZE + int "Quick connect task stack size." + default 3072 + help + The task stack size for each of the Quick Connect tasks. + + endmenu # Quick connect V2 demo configurations + config GRI_ENABLE_SUB_PUB_UNSUB_DEMO bool "Enable pub sub unsub demo" depends on !GRI_RUN_QUALIFICATION_TEST && !GRI_ENABLE_QUICKCONNECT_V2_DEMO diff --git a/main/demo_tasks/quickconnect_v2_demo/GettingStartedWithQuickConnect.md b/main/demo_tasks/quickconnect_v2_demo/GettingStarted.md similarity index 78% rename from main/demo_tasks/quickconnect_v2_demo/GettingStartedWithQuickConnect.md rename to main/demo_tasks/quickconnect_v2_demo/GettingStarted.md index 4d20ce7..efd13ca 100644 --- a/main/demo_tasks/quickconnect_v2_demo/GettingStartedWithQuickConnect.md +++ b/main/demo_tasks/quickconnect_v2_demo/GettingStarted.md @@ -24,11 +24,11 @@ For hardware and software requirements, refer to sections [1.1 Hardware Requirem ### 2.1 Get credentials from Quick Connect V2 -To get credentials for your device (Thing), visit [Quick Connect Credentials](https://quickconnect.iot.aws.dev/credentials) page and enter a desired device name (Thing Name) in the `Vend Credentials` section, and click the Vend button. Download both the `.crt` and `.key` files. These are your **PEM-encoded device certificate** and **PEM-encoded private key**. (An explanation of these entities is given in the [AWS IoT Core Setup Guide](AWSSetup.md).) +To get credentials for your device (Thing), visit [Quick Connect Credentials](https://quickconnect.freertos.aws.com/credentials) page and enter a desired device name (Thing Name) in the `Vend Credentials` section, and click the Vend button. Download both the `.crt` and `.key` files. These are your **PEM-encoded device certificate** and **PEM-encoded private key**. (An explanation of these entities is given in the [AWS IoT Core Setup Guide](AWSSetup.md).) ### 2.2 Configure the project with the AWS IoT Thing Name and AWS device Endpoint -The **AWS device Endpoint** is provided on the [Quick Connect Examples](https://quickconnect.iot.aws.dev) page. +The **AWS device Endpoint** is provided on the [Quick Connect Examples](https://quickconnect.freertos.aws.com/examples) page. Follow the [2.2 Configure the project](../../../GettingStartedGuide.md#22-configure-the-project-with-the-aws-iot-thing-name-and-aws-device-endpoint) section in the [Getting Started Guide](../../../GettingStartedGuide.md) to configure your project. @@ -49,6 +49,9 @@ For complete provisioning instructions, follow the [2.3 Provision the ESP32-C3]( For build and flash instructions, follow [3 Build and flash](../../../GettingStartedGuide.md#3-build-and-flash-the-demo-project) section of the [Getting Started Guide](../../../GettingStartedGuide.md). +**NOTE:** If you encounter a ***stack overflow in task CoreMqttAgentCo has been detected***
+run `idf.py menuconfig`. navigate to Featured FreeRTOS IoT Integration → coreMQTT-Agent Manager Configurations, and increse the `coreMQTT-Agent task stack size` and `Connection handling task stack size` from their default values. + ## 4 Monitoring the demo 1. On the serial terminal console, confirm that the TLS connection was @@ -72,6 +75,6 @@ I (5175) coreMQTT: State record updated. New state=MQTTPublishDone. ``` -2. On the [Quick Connect Visualizer](https://quickconnect.iot.aws.dev/visualizer) page, enter your device name (Thing name) in the `Visualizing device data` section, then confirm that the MQTT messages from the device are being received and a graph is being displayed. +2. On the [Quick Connect Visualizer](https://quickconnect.freertos.aws.com/visualizer) page, enter your device name (Thing name) in the `Visualizing device data` section, then confirm that the MQTT messages from the device are being received and a graph is being displayed. -**Note**: This demo sends data in line graph format only. For other data visualization formats, refer to the [Quick Connect](https://quickconnect.iot.aws.dev/) documentation. \ No newline at end of file +**Note**: This demo sends data in line graph format only. For other data visualization formats, refer to the [Quick Connect](https://quickconnect.freertos.aws.com/examples) documentation. \ No newline at end of file diff --git a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c index f421df5..1e5c4c3 100644 --- a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c +++ b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c @@ -79,6 +79,7 @@ /* Hardware drivers include. */ #include "app_driver.h" +#include "driver/temperature_sensor.h" /* coreMQTT-Agent manager configurations include. */ #include "core_mqtt_agent_manager_config.h" @@ -126,11 +127,11 @@ static const char * TAG = "quickconnect_v2_demo"; extern MQTTAgentContext_t xGlobalMqttAgentContext; /** - * @brief The buffer to hold the topic filter. The topic is generated at runtime - * by adding the task names. + * @brief The buffer to hold the topic filter. + Topic filter value will be the Thing-Name. * */ -static char topicBuf[ quickconnectv2configNUM_TASKS_TO_CREATE ][ quickconnectv2configSTRING_BUFFER_LENGTH ]; +static char topicBuf[ 1 ][ quickconnectv2configSTRING_BUFFER_LENGTH ]; /** * @brief The event group used to manage coreMQTT-Agent events. @@ -138,15 +139,14 @@ static char topicBuf[ quickconnectv2configNUM_TASKS_TO_CREATE ][ quickconnectv2c static EventGroupHandle_t xNetworkEventGroup; /** - * @brief The semaphore used to lock access to ulMessageID to eliminate a race - * condition in which multiple tasks try to increment/get ulMessageID. + * @brief The message ID for the next message sent by this demo. */ -static SemaphoreHandle_t xMessageIdSemaphore; +static uint32_t ulMessageId = 0; /** - * @brief The message ID for the next message sent by this demo. + * @brief Temperature sensor handle. */ -static uint32_t ulMessageId = 0; +static temperature_sensor_handle_t temp_sensor = NULL; /* Static function declarations ***********************************************/ @@ -264,8 +264,6 @@ static void prvPublishToTopic( MQTTQoS_t xQoS, char * pcPayload, EventGroupHandle_t xMqttEventGroup ) { - uint32_t ulPublishMessageId = 0; - MQTTStatus_t xCommandAdded; EventBits_t xReceivedEvent = 0; @@ -276,18 +274,8 @@ static void prvPublishToTopic( MQTTQoS_t xQoS, xTaskNotifyStateClear( NULL ); - /* Create a unique number for the publish that is about to be sent. - * This number is used in the command context and is sent back to this task - * as a notification in the callback that's executed upon receipt of the - * publish from coreMQTT-Agent. - * That way this task can match an acknowledgment to the message being sent. - */ - xSemaphoreTake( xMessageIdSemaphore, portMAX_DELAY ); - { - ++ulMessageId; - ulPublishMessageId = ulMessageId; - } - xSemaphoreGive( xMessageIdSemaphore ); + /* Increment Message Id */ + ++ulMessageId; /* Configure the publish operation. The topic name string must persist for * duration of publish! */ @@ -321,7 +309,7 @@ static void prvPublishToTopic( MQTTQoS_t xQoS, pcTaskGetName( NULL ), pcPayload, pcTopicName, - ulPublishMessageId ); + ulMessageId ); xCommandAdded = MQTTAgent_Publish( &xGlobalMqttAgentContext, &xPublishInfo, @@ -334,7 +322,7 @@ static void prvPublishToTopic( MQTTQoS_t xQoS, ESP_LOGI( TAG, "Task \"%s\" waiting for publish %" PRIu32 " to complete.", pcTaskGetName( NULL ), - ulPublishMessageId ); + ulMessageId ); xReceivedEvent = prvWaitForEvent( xMqttEventGroup, MQTT_PUBLISH_COMMAND_COMPLETED_BIT ); @@ -353,13 +341,13 @@ static void prvPublishToTopic( MQTTQoS_t xQoS, { ESP_LOGW( TAG, "Error or timed out waiting for ack for publish message %" PRIu32 ". Re-attempting publish.", - ulPublishMessageId ); + ulMessageId ); } else { ESP_LOGI( TAG, "Publish %" PRIu32 " succeeded for task \"%s\".", - ulPublishMessageId, + ulMessageId, pcTaskGetName( NULL ) ); } } while( ( xReceivedEvent & MQTT_PUBLISH_COMMAND_COMPLETED_BIT ) == 0 || @@ -380,7 +368,8 @@ static void prvQuickConnectV2Task( void * pvParameters ) xMqttEventGroup = xEventGroupCreate(); - xQoS = ( MQTTQoS_t ) quickconnectv2configQOS_LEVEL; + /* The MQTT QoS value is set to 1 */ + xQoS = ( MQTTQoS_t ) 1; /* Take the topic name from thing name. */ snprintf( pcTopicBuffer, @@ -388,14 +377,23 @@ static void prvQuickConnectV2Task( void * pvParameters ) "%s", configCLIENT_IDENTIFIER ); + /* Initialize temperature sensor */ + temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(-10, 80); + ESP_ERROR_CHECK(temperature_sensor_install(&temp_sensor_config, &temp_sensor)); + ESP_ERROR_CHECK(temperature_sensor_enable(temp_sensor)); + while( 1 ) { - temperatureValue = app_driver_temp_sensor_read_celsius(); + esp_err_t ret = temperature_sensor_get_celsius(temp_sensor, &temperatureValue); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to read temperature: %s", esp_err_to_name(ret)); + temperatureValue = 25.0; /* Default fallback value */ + } /* Create Payload in an Array format */ snprintf( pcPayload, quickconnectv2configSTRING_BUFFER_LENGTH, - "[{\"label\":\"ESP32-S3 MCU Temperature\",\"display_type\":\"line_graph\",\"unit\":\"C\",\"values\":[{\"value\":%.1f,\"label\":\"temp\"}]}]", + "[{\"label\":\"ESP32 MCU Temperature\",\"display_type\":\"line_graph\",\"unit\":\"C\",\"values\":[{\"value\":%.1f,\"label\":\"temp\"}]}]", temperatureValue ); prvPublishToTopic( xQoS, @@ -422,12 +420,11 @@ static void prvQuickConnectV2Task( void * pvParameters ) /* Public function definitions ************************************************/ void vStartQuickConnectV2Demo( void ) -{ - static struct DemoParams pxParams[ quickconnectv2configNUM_TASKS_TO_CREATE ]; - char pcTaskNameBuf[ 30 ]; +{ /* This is a single task demo*/ + static struct DemoParams pxParams[ 1 ]; + char pcTaskNameBuf[ 15 ]; uint32_t ulTaskNumber; - xMessageIdSemaphore = xSemaphoreCreateMutex(); xNetworkEventGroup = xEventGroupCreate(); xCoreMqttAgentManagerRegisterHandler( prvCoreMqttAgentEventHandler ); @@ -439,14 +436,14 @@ void vStartQuickConnectV2Demo( void ) * name and topic filter for itself from the number passed in as the task * parameter. */ /* Create a few instances of prvQuickConnectV2Task(). */ - for( ulTaskNumber = 0; ulTaskNumber < quickconnectv2configNUM_TASKS_TO_CREATE; ulTaskNumber++ ) + for( ulTaskNumber = 0; ulTaskNumber < 1; ulTaskNumber++ ) { memset( pcTaskNameBuf, 0x00, sizeof( pcTaskNameBuf ) ); snprintf( pcTaskNameBuf, - 30, + 10, "DemoTask"); pxParams[ ulTaskNumber ].ulTaskNumber = ulTaskNumber; @@ -455,7 +452,7 @@ void vStartQuickConnectV2Demo( void ) pcTaskNameBuf, quickconnectv2configTASK_STACK_SIZE, ( void * ) &pxParams[ ulTaskNumber ], - quickconnectv2configTASK_PRIORITY, + 1, /* Task Priority */ NULL ); } } diff --git a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h index d089c55..b7230e8 100644 --- a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h +++ b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h @@ -30,10 +30,6 @@ /* ESP-IDF sdkconfig include. */ #include -#if CONFIG_GRI_RUN_QUALIFICATION_TEST - #include "qualification_wrapper_config.h" -#endif /* CONFIG_GRI_RUN_QUALIFICATION_TEST */ - /* *INDENT-OFF* */ #ifdef __cplusplus extern "C" { @@ -44,41 +40,24 @@ * @brief Size of statically allocated buffers for holding topic names and * payloads. */ -#define quickconnectv2configSTRING_BUFFER_LENGTH ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_STRING_BUFFER_LENGTH ) ) +#define quickconnectv2configSTRING_BUFFER_LENGTH ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_STRING_BUFFER_LENGTH ) ) /** * @brief Delay for each task between each publish. */ -#define quickconnectv2configDELAY_BETWEEN_LOOPS_MS ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_DELAY_BETWEEN_SUB_PUB_UNSUB_LOOPS_MS ) ) +#define quickconnectv2configDELAY_BETWEEN_LOOPS_MS ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_DELAY_BETWEEN_PUB_LOOPS_MS ) ) /** * @brief The maximum amount of time in milliseconds to wait for the commands * to be posted to the MQTT agent should the MQTT agent's command queue be full. * Tasks wait in the Blocked state, so don't use any CPU time. */ -#define quickconnectv2configMAX_COMMAND_SEND_BLOCK_TIME_MS ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS ) ) - -/** - * @brief The QoS level of MQTT messages sent by this demo. This must be 0 or 1 - * if using AWS as AWS only supports levels 0 or 1. If using another MQTT broker - * that supports QoS level 2, this can be set to 2. - */ -#define quickconnectv2configQOS_LEVEL ( ( unsigned long ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_QOS_LEVEL ) ) - -/** - * @brief The number of Quick Connect Demo tasks to create for this demo. - */ -#define quickconnectv2configNUM_TASKS_TO_CREATE ( ( unsigned long ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_NUM_TASKS_TO_CREATE ) ) - -/** - * @brief The task priority of each of the Quick Connect Demo tasks. - */ -#define quickconnectv2configTASK_PRIORITY ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_TASK_PRIORITY ) ) +#define quickconnectv2configMAX_COMMAND_SEND_BLOCK_TIME_MS ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS ) ) /** * @brief The task stack size for each of the Quick Connect Demo tasks. */ -#define quickconnectv2configTASK_STACK_SIZE ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_TASK_STACK_SIZE ) ) +#define quickconnectv2configTASK_STACK_SIZE ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_TASK_STACK_SIZE ) ) /* *INDENT-OFF* */ #ifdef __cplusplus From e256c69aa867facf675a1e40315999eaa1c587c9 Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Thu, 16 Oct 2025 14:43:23 -0700 Subject: [PATCH 03/14] decreased topic buffer to 1D and commenting changes --- .../quickconnect_v2_demo.c | 59 +++++-------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c index 1e5c4c3..677e17b 100644 --- a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c +++ b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c @@ -25,20 +25,16 @@ */ /* - * This file demonstrates numerous tasks all of which use the core-MQTT Agent API - * to send unique MQTT payloads to unique topics over the same MQTT connection - * to the same coreMQTT-Agent. + * This file demonstrates the Quick Connect V2 demo which uses the core-MQTT Agent API + * to publish ESP32 temperature sensor data to an MQTT broker without requiring AWS account setup. * - * Each created task is a unique instance of the task implemented by - * prvQuickConnectV2Task(). prvQuickConnectV2Task() - * subscribes to a topic, publishes a message to the same - * topic, receives the message, then unsubscribes from the topic in a loop. - * The command context sent to MQTTAgent_Publish() contains a unique number that is sent back to the task - * as a task notification from the callback function that executes when the - * operations are acknowledged (or just sent in the case of QoS 0). The - * task checks the number it receives from the callback equals the number it - * previously set in the command context before printing out either a success - * or failure message. + * The demo creates a single task that reads the onboard temperature sensor and publishes + * the temperature data in JSON format to a topic named after the thing name. + * The task uses QoS 1 for reliable message delivery and includes error handling for + * sensor read failures with a fallback temperature value. + * + * This demo is designed for quick testing and development without the complexity + * of AWS IoT Core provisioning and certificate management. */ /* Includes *******************************************************************/ @@ -88,7 +84,6 @@ /* coreMQTT-Agent event group bit definitions */ #define CORE_MQTT_AGENT_CONNECTED_BIT ( 1 << 0 ) -#define CORE_MQTT_AGENT_OTA_NOT_IN_PROGRESS_BIT ( 1 << 1 ) /* MQTT event group bit definitions. */ #define MQTT_PUBLISH_COMMAND_COMPLETED_BIT ( 1 << 1 ) @@ -106,14 +101,6 @@ struct MQTTAgentCommandContext void * pArgs; }; -/** - * @brief Parameters for this task. - */ -struct DemoParams -{ - uint32_t ulTaskNumber; -}; - /* Global variables ***********************************************************/ /** @@ -131,7 +118,7 @@ extern MQTTAgentContext_t xGlobalMqttAgentContext; Topic filter value will be the Thing-Name. * */ -static char topicBuf[ 1 ][ quickconnectv2configSTRING_BUFFER_LENGTH ]; +static char topicBuf[ quickconnectv2configSTRING_BUFFER_LENGTH ]; /** * @brief The event group used to manage coreMQTT-Agent events. @@ -299,9 +286,9 @@ static void prvPublishToTopic( MQTTQoS_t xQoS, { /* Wait for coreMQTT-Agent task to have working network connection */ xEventGroupWaitBits( xNetworkEventGroup, - CORE_MQTT_AGENT_CONNECTED_BIT | CORE_MQTT_AGENT_OTA_NOT_IN_PROGRESS_BIT, + CORE_MQTT_AGENT_CONNECTED_BIT, + pdFALSE, pdFALSE, - pdTRUE, portMAX_DELAY ); ESP_LOGI( TAG, @@ -317,7 +304,7 @@ static void prvPublishToTopic( MQTTQoS_t xQoS, if( xCommandAdded == MQTTSuccess ) { - /* For QoS 1 and 2, wait for the publish acknowledgment. For QoS0, + /* For QoS 1, wait for the publish acknowledgment. For QoS0, * wait for the publish to be sent. */ ESP_LOGI( TAG, "Task \"%s\" waiting for publish %" PRIu32 " to complete.", @@ -356,13 +343,9 @@ static void prvPublishToTopic( MQTTQoS_t xQoS, static void prvQuickConnectV2Task( void * pvParameters ) { - struct DemoParams * pxParams = ( struct DemoParams * ) pvParameters; - uint32_t ulTaskNumber = pxParams->ulTaskNumber; - EventGroupHandle_t xMqttEventGroup; MQTTQoS_t xQoS; - char * pcTopicBuffer = topicBuf[ ulTaskNumber ]; char pcPayload[ quickconnectv2configSTRING_BUFFER_LENGTH ]; float temperatureValue; @@ -372,7 +355,7 @@ static void prvQuickConnectV2Task( void * pvParameters ) xQoS = ( MQTTQoS_t ) 1; /* Take the topic name from thing name. */ - snprintf( pcTopicBuffer, + snprintf( topicBuf, quickconnectv2configSTRING_BUFFER_LENGTH, "%s", configCLIENT_IDENTIFIER ); @@ -397,7 +380,7 @@ static void prvQuickConnectV2Task( void * pvParameters ) temperatureValue ); prvPublishToTopic( xQoS, - pcTopicBuffer, + topicBuf, pcPayload, xMqttEventGroup ); @@ -421,20 +404,12 @@ static void prvQuickConnectV2Task( void * pvParameters ) void vStartQuickConnectV2Demo( void ) { /* This is a single task demo*/ - static struct DemoParams pxParams[ 1 ]; char pcTaskNameBuf[ 15 ]; uint32_t ulTaskNumber; xNetworkEventGroup = xEventGroupCreate(); xCoreMqttAgentManagerRegisterHandler( prvCoreMqttAgentEventHandler ); - /* Initialize the coreMQTT-Agent event group. */ - xEventGroupSetBits( xNetworkEventGroup, - CORE_MQTT_AGENT_OTA_NOT_IN_PROGRESS_BIT ); - - /* Each instance of prvQuickConnectV2Task() generates a unique - * name and topic filter for itself from the number passed in as the task - * parameter. */ /* Create a few instances of prvQuickConnectV2Task(). */ for( ulTaskNumber = 0; ulTaskNumber < 1; ulTaskNumber++ ) { @@ -446,12 +421,10 @@ void vStartQuickConnectV2Demo( void ) 10, "DemoTask"); - pxParams[ ulTaskNumber ].ulTaskNumber = ulTaskNumber; - xTaskCreate( prvQuickConnectV2Task, pcTaskNameBuf, quickconnectv2configTASK_STACK_SIZE, - ( void * ) &pxParams[ ulTaskNumber ], + NULL, 1, /* Task Priority */ NULL ); } From c98dbc132aca3ce23a342b44947eaf173c867ea0 Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Fri, 17 Oct 2025 11:13:29 -0700 Subject: [PATCH 04/14] Fixed the AWSsetup.md link in Quick connect GettingStarted.md --- main/demo_tasks/quickconnect_v2_demo/GettingStarted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/demo_tasks/quickconnect_v2_demo/GettingStarted.md b/main/demo_tasks/quickconnect_v2_demo/GettingStarted.md index efd13ca..6c18194 100644 --- a/main/demo_tasks/quickconnect_v2_demo/GettingStarted.md +++ b/main/demo_tasks/quickconnect_v2_demo/GettingStarted.md @@ -24,7 +24,7 @@ For hardware and software requirements, refer to sections [1.1 Hardware Requirem ### 2.1 Get credentials from Quick Connect V2 -To get credentials for your device (Thing), visit [Quick Connect Credentials](https://quickconnect.freertos.aws.com/credentials) page and enter a desired device name (Thing Name) in the `Vend Credentials` section, and click the Vend button. Download both the `.crt` and `.key` files. These are your **PEM-encoded device certificate** and **PEM-encoded private key**. (An explanation of these entities is given in the [AWS IoT Core Setup Guide](AWSSetup.md).) +To get credentials for your device (Thing), visit [Quick Connect Credentials](https://quickconnect.freertos.aws.com/credentials) page and enter a desired device name (Thing Name) in the `Vend Credentials` section, and click the Vend button. Download both the `.crt` and `.key` files. These are your **PEM-encoded device certificate** and **PEM-encoded private key**. (An explanation of these entities is given in the [AWS IoT Core Setup Guide](../../../AWSSetup.md).) ### 2.2 Configure the project with the AWS IoT Thing Name and AWS device Endpoint From b8bb2df96593ddfb07950196efc1913c2bf583a0 Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Thu, 13 Nov 2025 16:24:26 -0800 Subject: [PATCH 05/14] Styling changes and removing esp_driver_tsens dependency to fix the failing demo builds --- main/CMakeLists.txt | 4 +- .../quickconnect_v2_demo/GettingStarted.md | 4 +- .../quickconnect_v2_demo.c | 45 +++++++------------ .../quickconnect_v2_demo.h | 2 +- .../quickconnect_v2_demo_config.h | 8 ++-- main/main.c | 4 +- 6 files changed, 29 insertions(+), 38 deletions(-) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 62788fe..5992782 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -15,8 +15,9 @@ endif() # QuickConnect V2 demo if(CONFIG_GRI_ENABLE_QUICKCONNECT_V2_DEMO) - list(APPEND MAIN_SRCS + list(APPEND MAIN_SRCS "demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c" + "demo_tasks/temp_sub_pub_and_led_control_demo/hardware_drivers/app_driver.c" ) endif() @@ -64,7 +65,6 @@ set(MAIN_REQUIRES FreeRTOS-Libraries-Integration-Tests unity driver - esp_driver_tsens ) idf_component_register( diff --git a/main/demo_tasks/quickconnect_v2_demo/GettingStarted.md b/main/demo_tasks/quickconnect_v2_demo/GettingStarted.md index 6c18194..6bda164 100644 --- a/main/demo_tasks/quickconnect_v2_demo/GettingStarted.md +++ b/main/demo_tasks/quickconnect_v2_demo/GettingStarted.md @@ -28,10 +28,12 @@ To get credentials for your device (Thing), visit [Quick Connect Credentials](ht ### 2.2 Configure the project with the AWS IoT Thing Name and AWS device Endpoint -The **AWS device Endpoint** is provided on the [Quick Connect Examples](https://quickconnect.freertos.aws.com/examples) page. +The **AWS device Endpoint** is provided on the [Quick Connect Examples](https://quickconnect.freertos.aws.com/examples) page in the sample program code under the ENDPOINT variable. Follow the [2.2 Configure the project](../../../GettingStartedGuide.md#22-configure-the-project-with-the-aws-iot-thing-name-and-aws-device-endpoint) section in the [Getting Started Guide](../../../GettingStartedGuide.md) to configure your project. +Select `Enable QuickConnect V2 demo` in the `Featured FreeRTOS IoT Integration` to activate the demo. + ### 2.3 Provision the ESP32-C3 with the private key, device certificate and CA certificate in Development Mode diff --git a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c index 677e17b..4bcc196 100644 --- a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c +++ b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c @@ -75,7 +75,6 @@ /* Hardware drivers include. */ #include "app_driver.h" -#include "driver/temperature_sensor.h" /* coreMQTT-Agent manager configurations include. */ #include "core_mqtt_agent_manager_config.h" @@ -83,10 +82,10 @@ /* Preprocessor definitions ***************************************************/ /* coreMQTT-Agent event group bit definitions */ -#define CORE_MQTT_AGENT_CONNECTED_BIT ( 1 << 0 ) +#define CORE_MQTT_AGENT_CONNECTED_BIT ( 1 << 0 ) /* MQTT event group bit definitions. */ -#define MQTT_PUBLISH_COMMAND_COMPLETED_BIT ( 1 << 1 ) +#define MQTT_PUBLISH_COMMAND_COMPLETED_BIT ( 1 << 1 ) /* Struct definitions *********************************************************/ @@ -115,10 +114,10 @@ extern MQTTAgentContext_t xGlobalMqttAgentContext; /** * @brief The buffer to hold the topic filter. - Topic filter value will be the Thing-Name. + * Topic filter value will be the Thing-Name. * */ -static char topicBuf[ quickconnectv2configSTRING_BUFFER_LENGTH ]; +static char topicBuf[ quickconnectconfigSTRING_BUFFER_LENGTH ]; /** * @brief The event group used to manage coreMQTT-Agent events. @@ -130,11 +129,6 @@ static EventGroupHandle_t xNetworkEventGroup; */ static uint32_t ulMessageId = 0; -/** - * @brief Temperature sensor handle. - */ -static temperature_sensor_handle_t temp_sensor = NULL; - /* Static function declarations ***********************************************/ /** @@ -177,7 +171,7 @@ static void prvPublishCommandCallback( MQTTAgentCommandContext_t * pxCommandCont */ static EventBits_t prvWaitForEvent( EventGroupHandle_t xMqttEventGroup, EventBits_t uxBitsToWaitFor ); - + /** * @brief The function that implements the task demonstrated by this file. */ @@ -278,7 +272,7 @@ static void prvPublishToTopic( MQTTQoS_t xQoS, * until the callback executes. */ xCommandContext.xMqttEventGroup = xMqttEventGroup; - xCommandParams.blockTimeMs = quickconnectv2configMAX_COMMAND_SEND_BLOCK_TIME_MS; + xCommandParams.blockTimeMs = quickconnectconfigMAX_COMMAND_SEND_BLOCK_TIME_MS; xCommandParams.cmdCompleteCallback = prvPublishCommandCallback; xCommandParams.pCmdCompleteCallbackContext = &xCommandContext; @@ -346,7 +340,7 @@ static void prvQuickConnectV2Task( void * pvParameters ) EventGroupHandle_t xMqttEventGroup; MQTTQoS_t xQoS; - char pcPayload[ quickconnectv2configSTRING_BUFFER_LENGTH ]; + char pcPayload[ quickconnectconfigSTRING_BUFFER_LENGTH ]; float temperatureValue; xMqttEventGroup = xEventGroupCreate(); @@ -356,26 +350,21 @@ static void prvQuickConnectV2Task( void * pvParameters ) /* Take the topic name from thing name. */ snprintf( topicBuf, - quickconnectv2configSTRING_BUFFER_LENGTH, + quickconnectconfigSTRING_BUFFER_LENGTH, "%s", configCLIENT_IDENTIFIER ); - /* Initialize temperature sensor */ - temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(-10, 80); - ESP_ERROR_CHECK(temperature_sensor_install(&temp_sensor_config, &temp_sensor)); - ESP_ERROR_CHECK(temperature_sensor_enable(temp_sensor)); + /* Initialize hardware drivers */ + app_driver_init(); while( 1 ) { - esp_err_t ret = temperature_sensor_get_celsius(temp_sensor, &temperatureValue); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to read temperature: %s", esp_err_to_name(ret)); - temperatureValue = 25.0; /* Default fallback value */ - } + /* Read temperature from sensor */ + temperatureValue = app_driver_temp_sensor_read_celsius(); /* Create Payload in an Array format */ snprintf( pcPayload, - quickconnectv2configSTRING_BUFFER_LENGTH, + quickconnectconfigSTRING_BUFFER_LENGTH, "[{\"label\":\"ESP32 MCU Temperature\",\"display_type\":\"line_graph\",\"unit\":\"C\",\"values\":[{\"value\":%.1f,\"label\":\"temp\"}]}]", temperatureValue ); @@ -393,7 +382,7 @@ static void prvQuickConnectV2Task( void * pvParameters ) "Task \"%s\" completed a loop. Delaying before next loop.", pcTaskGetName( NULL ) ); - vTaskDelay( pdMS_TO_TICKS( quickconnectv2configDELAY_BETWEEN_LOOPS_MS ) ); + vTaskDelay( pdMS_TO_TICKS( quickconnectconfigDELAY_BETWEEN_LOOPS_MS ) ); } vEventGroupDelete( xMqttEventGroup ); @@ -403,7 +392,7 @@ static void prvQuickConnectV2Task( void * pvParameters ) /* Public function definitions ************************************************/ void vStartQuickConnectV2Demo( void ) -{ /* This is a single task demo*/ +{ /* This is a single task demo*/ char pcTaskNameBuf[ 15 ]; uint32_t ulTaskNumber; @@ -419,11 +408,11 @@ void vStartQuickConnectV2Demo( void ) snprintf( pcTaskNameBuf, 10, - "DemoTask"); + "DemoTask" ); xTaskCreate( prvQuickConnectV2Task, pcTaskNameBuf, - quickconnectv2configTASK_STACK_SIZE, + quickconnectconfigTASK_STACK_SIZE, NULL, 1, /* Task Priority */ NULL ); diff --git a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.h b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.h index 6375c39..0faf788 100644 --- a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.h +++ b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.h @@ -35,4 +35,4 @@ */ void vStartQuickConnectV2Demo( void ); -#endif /* QUICKCONNECT_V2_DEMO_H */ \ No newline at end of file +#endif /* QUICKCONNECT_V2_DEMO_H */ diff --git a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h index b7230e8..746e90d 100644 --- a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h +++ b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo_config.h @@ -40,24 +40,24 @@ * @brief Size of statically allocated buffers for holding topic names and * payloads. */ -#define quickconnectv2configSTRING_BUFFER_LENGTH ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_STRING_BUFFER_LENGTH ) ) +#define quickconnectconfigSTRING_BUFFER_LENGTH ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_STRING_BUFFER_LENGTH ) ) /** * @brief Delay for each task between each publish. */ -#define quickconnectv2configDELAY_BETWEEN_LOOPS_MS ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_DELAY_BETWEEN_PUB_LOOPS_MS ) ) +#define quickconnectconfigDELAY_BETWEEN_LOOPS_MS ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_DELAY_BETWEEN_PUB_LOOPS_MS ) ) /** * @brief The maximum amount of time in milliseconds to wait for the commands * to be posted to the MQTT agent should the MQTT agent's command queue be full. * Tasks wait in the Blocked state, so don't use any CPU time. */ -#define quickconnectv2configMAX_COMMAND_SEND_BLOCK_TIME_MS ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS ) ) +#define quickconnectconfigMAX_COMMAND_SEND_BLOCK_TIME_MS ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS ) ) /** * @brief The task stack size for each of the Quick Connect Demo tasks. */ -#define quickconnectv2configTASK_STACK_SIZE ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_TASK_STACK_SIZE ) ) +#define quickconnectconfigTASK_STACK_SIZE ( ( unsigned int ) ( CONFIG_GRI_QUICKCONNECT_V2_DEMO_TASK_STACK_SIZE ) ) /* *INDENT-OFF* */ #ifdef __cplusplus diff --git a/main/main.c b/main/main.c index 7ac947b..e7cf893 100644 --- a/main/main.c +++ b/main/main.c @@ -257,10 +257,10 @@ static void prvStartEnabledDemos( void ) BaseType_t xResult; #if ( CONFIG_GRI_RUN_QUALIFICATION_TEST == 0 ) - #if CONFIG_GRI_ENABLE_QUICKCONNECT_V2_DEMO + #if CONFIG_GRI_ENABLE_QUICKCONNECT_V2_DEMO vStartQuickConnectV2Demo(); #endif /* CONFIG_GRI_ENABLE_QUICKCONNECT_V2_DEMO */ - + #if CONFIG_GRI_ENABLE_SUB_PUB_UNSUB_DEMO vStartSubscribePublishUnsubscribeDemo(); #endif /* CONFIG_GRI_ENABLE_SIMPLE_PUB_SUB_DEMO */ From 8936a076ea9757526c4ff75ed4f6d8bc6ed60a1c Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Thu, 13 Nov 2025 17:20:22 -0800 Subject: [PATCH 06/14] formating changes to fix CI Checks / formatting in PR --- main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c index 4bcc196..691136b 100644 --- a/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c +++ b/main/demo_tasks/quickconnect_v2_demo/quickconnect_v2_demo.c @@ -113,8 +113,8 @@ static const char * TAG = "quickconnect_v2_demo"; extern MQTTAgentContext_t xGlobalMqttAgentContext; /** - * @brief The buffer to hold the topic filter. - * Topic filter value will be the Thing-Name. + * @brief The buffer to hold the topic filter. + * Topic filter value will be the Thing-Name. * */ static char topicBuf[ quickconnectconfigSTRING_BUFFER_LENGTH ]; @@ -361,7 +361,7 @@ static void prvQuickConnectV2Task( void * pvParameters ) { /* Read temperature from sensor */ temperatureValue = app_driver_temp_sensor_read_celsius(); - + /* Create Payload in an Array format */ snprintf( pcPayload, quickconnectconfigSTRING_BUFFER_LENGTH, From 4d1e1b200a9d7c0bd8283fb4799a43c713514695 Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Mon, 8 Dec 2025 11:01:01 -0800 Subject: [PATCH 07/14] Switch from 'latest' which is 6.x to v5.5.1 ESP-IDF 6.x no longer supports vends the wifi provisioning component, instead titling it as 'network provisioning'. This is backwards incompatible. We should update to IDF 6+ once it is released. It is currently in beta. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 72cbdaf..eeb5b60 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: - v5.0 - v5.1.2 - release-v5.2 - - latest + - v5.5.1 esp_target: - esp32 - esp32s2 From eeaf9cdf2e2eb98aa01a9a971c9fa70bf1e91d11 Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Mon, 8 Dec 2025 11:10:12 -0800 Subject: [PATCH 08/14] Drop support for ESP-IDF 5.0. 5.0 does not support network provisioning. --- .github/workflows/build.yml | 2 +- main/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eeb5b60..4a879c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,10 +20,10 @@ jobs: fail-fast: false matrix: esp_idf_version: - - v5.0 - v5.1.2 - release-v5.2 - v5.5.1 + - latest esp_target: - esp32 - esp32s2 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 5992782..cf570ec 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -54,7 +54,7 @@ set(MAIN_INCLUDE_DIRS set(MAIN_REQUIRES qrcode - wifi_provisioning + network_provisioning coreMQTT coreMQTT-Agent corePKCS11 From 33931fed178e93682cef3b3dcf43a011c686e95f Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Mon, 5 Jan 2026 15:20:39 -0800 Subject: [PATCH 09/14] update: updated code to use network prov from wifi prov --- main/CMakeLists.txt | 2 ++ main/idf_component.yml | 1 + main/networking/wifi/app_wifi.c | 46 ++++++++++++++++----------------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index cf570ec..2c020a1 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -67,6 +67,8 @@ set(MAIN_REQUIRES driver ) +set(EXCLUDE_COMPONENTS wifi_provisioning) + idf_component_register( SRCS ${MAIN_SRCS} diff --git a/main/idf_component.yml b/main/idf_component.yml index d09368b..8c36ff4 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -6,3 +6,4 @@ dependencies: version: "^0.6.0" rules: - if: "idf_version >=5.0" + espressif/network_provisioning: "^1.2.0" diff --git a/main/networking/wifi/app_wifi.c b/main/networking/wifi/app_wifi.c index a7d77f7..0e927e9 100644 --- a/main/networking/wifi/app_wifi.c +++ b/main/networking/wifi/app_wifi.c @@ -24,11 +24,11 @@ #include #endif -#include +#include #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE - #include + #include #else /* CONFIG_APP_WIFI_PROV_TRANSPORT_SOFTAP */ - #include + #include #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ #include @@ -76,15 +76,15 @@ static void event_handler( void * arg, long int event_id, void * event_data ) { - if( event_base == WIFI_PROV_EVENT ) + if( event_base == NETWORK_PROV_EVENT ) { switch( event_id ) { - case WIFI_PROV_START: + case NETWORK_PROV_START: ESP_LOGI( TAG, "Provisioning started" ); break; - case WIFI_PROV_CRED_RECV: + case NETWORK_PROV_WIFI_CRED_RECV: { wifi_sta_config_t * wifi_sta_cfg = ( wifi_sta_config_t * ) event_data; ESP_LOGI( TAG, "Received Wi-Fi credentials" @@ -94,23 +94,23 @@ static void event_handler( void * arg, break; } - case WIFI_PROV_CRED_FAIL: + case NETWORK_PROV_WIFI_CRED_FAIL: { - wifi_prov_sta_fail_reason_t * reason = ( wifi_prov_sta_fail_reason_t * ) event_data; + network_prov_wifi_sta_fail_reason_t * reason = ( network_prov_wifi_sta_fail_reason_t * ) event_data; ESP_LOGE( TAG, "Provisioning failed!\n\tReason : %s" "\n\tPlease reset to factory and retry provisioning", - ( *reason == WIFI_PROV_STA_AUTH_ERROR ) ? + ( *reason == NETWORK_PROV_WIFI_STA_AUTH_ERROR ) ? "Wi-Fi station authentication failed" : "Wi-Fi access-point not found" ); break; } - case WIFI_PROV_CRED_SUCCESS: + case NETWORK_PROV_WIFI_CRED_SUCCESS: ESP_LOGI( TAG, "Provisioning successful" ); break; - case WIFI_PROV_END: + case NETWORK_PROV_END: /* De-initialize manager once provisioning is finished */ - wifi_prov_mgr_deinit(); + network_prov_mgr_deinit(); break; default: @@ -265,7 +265,7 @@ void app_wifi_init( void ) wifi_event_group = xEventGroupCreate(); /* Register our event handler for Wi-Fi, IP and Provisioning related events */ - ESP_ERROR_CHECK( esp_event_handler_register( WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL ) ); + ESP_ERROR_CHECK( esp_event_handler_register( NETWORK_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL ) ); ESP_ERROR_CHECK( esp_event_handler_register( WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL ) ); ESP_ERROR_CHECK( esp_event_handler_register( IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL ) ); @@ -280,14 +280,14 @@ void app_wifi_init( void ) esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) { /* Configuration for the provisioning manager */ - wifi_prov_mgr_config_t config = + network_prov_mgr_config_t config = { /* What is the Provisioning Scheme that we want ? * wifi_prov_scheme_softap or wifi_prov_scheme_ble */ #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE - .scheme = wifi_prov_scheme_ble, + .scheme = network_prov_scheme_ble, #else /* CONFIG_APP_WIFI_PROV_TRANSPORT_SOFTAP */ - .scheme = wifi_prov_scheme_softap, + .scheme = network_prov_scheme_softap, #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ /* Any default scheme specific event handler that you would @@ -299,7 +299,7 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) * to take care of this automatically. This can be set to * WIFI_PROV_EVENT_HANDLER_NONE when using wifi_prov_scheme_softap*/ #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE - .scheme_event_handler = WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM + .scheme_event_handler = NETWORK_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM #else /* CONFIG_APP_WIFI_PROV_TRANSPORT_SOFTAP */ .scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE, #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ @@ -307,11 +307,11 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) /* Initialize provisioning manager with the * configuration parameters set above */ - ESP_ERROR_CHECK( wifi_prov_mgr_init( config ) ); + ESP_ERROR_CHECK( network_prov_mgr_init( config ) ); bool provisioned = false; /* Let's find out if the device is provisioned */ - ESP_ERROR_CHECK( wifi_prov_mgr_is_provisioned( &provisioned ) ); + ESP_ERROR_CHECK( network_prov_mgr_is_wifi_provisioned( &provisioned ) ); /* If device is not yet provisioned start provisioning service */ if( !provisioned ) @@ -335,7 +335,7 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) * using X25519 key exchange and proof of possession (pop) and AES-CTR * for encryption/decryption of messages. */ - wifi_prov_security_t security = WIFI_PROV_SECURITY_1; + network_prov_security_t security = NETWORK_PROV_SECURITY_1; /* Do we want a proof-of-possession (ignored if Security 0 is selected): * - this should be a string with length > 0 @@ -374,7 +374,7 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) 0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02, }; - err = wifi_prov_scheme_ble_set_service_uuid( custom_service_uuid ); + err = network_prov_scheme_ble_set_service_uuid( custom_service_uuid ); if( err != ESP_OK ) { @@ -384,7 +384,7 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ /* Start provisioning service */ - ESP_ERROR_CHECK( wifi_prov_mgr_start_provisioning( security, pop, service_name, service_key ) ); + ESP_ERROR_CHECK( network_prov_mgr_start_provisioning( security, pop, service_name, service_key ) ); /* Print QR code for provisioning */ #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE app_wifi_print_qr( service_name, pop, PROV_TRANSPORT_BLE ); @@ -399,7 +399,7 @@ esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) /* We don't need the manager as device is already provisioned, * so let's release it's resources */ - wifi_prov_mgr_deinit(); + network_prov_mgr_deinit(); /* Start Wi-Fi station */ wifi_init_sta(); From 36fee3b5db285f5be9ce6f8b5359f44dbf94ae35 Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Mon, 5 Jan 2026 15:23:02 -0800 Subject: [PATCH 10/14] fix: network_prov not found issue --- main/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 2c020a1..fe8b39e 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -54,7 +54,7 @@ set(MAIN_INCLUDE_DIRS set(MAIN_REQUIRES qrcode - network_provisioning + wifi_provisioning coreMQTT coreMQTT-Agent corePKCS11 From 34f09e053dcca0c977c6bd6d466972f0bb14b02a Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Mon, 5 Jan 2026 16:13:59 -0800 Subject: [PATCH 11/14] fix: removed wifi prov for latest CI test --- main/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index fe8b39e..fe064f1 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -54,7 +54,6 @@ set(MAIN_INCLUDE_DIRS set(MAIN_REQUIRES qrcode - wifi_provisioning coreMQTT coreMQTT-Agent corePKCS11 From 5a07445705e038f22291cd42da08ab9c2514cca4 Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Mon, 5 Jan 2026 16:44:24 -0800 Subject: [PATCH 12/14] fix: added mbedtls for latest CI test --- main/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index fe064f1..3c1c95f 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -64,6 +64,7 @@ set(MAIN_REQUIRES FreeRTOS-Libraries-Integration-Tests unity driver + mbedtls ) set(EXCLUDE_COMPONENTS wifi_provisioning) From 9b980ab36b1d25a40438677d6e3ae72bd0d18141 Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Tue, 6 Jan 2026 11:17:06 -0800 Subject: [PATCH 13/14] removed latest CI test as it fails due to mbedtls 4.0 support in corePKCS11 and v5.1.2 as it does not support network prov --- .github/workflows/build.yml | 2 -- main/CMakeLists.txt | 1 - 2 files changed, 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a879c7..ff27fbc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,10 +20,8 @@ jobs: fail-fast: false matrix: esp_idf_version: - - v5.1.2 - release-v5.2 - v5.5.1 - - latest esp_target: - esp32 - esp32s2 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 3c1c95f..fe064f1 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -64,7 +64,6 @@ set(MAIN_REQUIRES FreeRTOS-Libraries-Integration-Tests unity driver - mbedtls ) set(EXCLUDE_COMPONENTS wifi_provisioning) From cdcc641d87c8f8e7cb6f1eb39a2731028a928401 Mon Sep 17 00:00:00 2001 From: Sujan Rauth Subramanyam Date: Tue, 6 Jan 2026 13:25:53 -0800 Subject: [PATCH 14/14] refactor: updated CI tests to use v5.5.2 --- .github/workflows/build.yml | 2 +- main/CMakeLists.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff27fbc..bbef3cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: matrix: esp_idf_version: - release-v5.2 - - v5.5.1 + - v5.5.2 esp_target: - esp32 - esp32s2 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index fe064f1..a2e2016 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -66,6 +66,8 @@ set(MAIN_REQUIRES driver ) +# Exclude wifi_provisioning component to avoid conflicts with network_provisioning +# See: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/migration-guides/release-6.x/6.0/provisioning.html set(EXCLUDE_COMPONENTS wifi_provisioning) idf_component_register(