├── .github ├── .cSpellWords.txt ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ ├── documentation-issue.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md ├── memory_statistics_config.json └── workflows │ ├── build.yml │ ├── ci.yml │ └── release.yml ├── .gitignore ├── .gitmodules ├── .vscode └── settings.json ├── AWSSetup.md ├── CHANGELOG.md ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── GettingStartedGuide.md ├── LICENSE ├── README.md ├── UseSecurityFeatures.md ├── components ├── FreeRTOS-Libraries-Integration-Tests │ ├── CMakeLists.txt │ ├── config │ │ ├── qualification_wrapper_config.h │ │ ├── test_execution_config.h │ │ └── test_param_config.h │ └── port │ │ └── platform_function.c └── qrcode │ ├── CMakeLists.txt │ ├── component.mk │ ├── include │ └── qrcode.h │ └── src │ ├── qrcode.c │ ├── qrcodegen.c │ └── qrcodegen.h ├── cspell.config.yaml ├── main ├── CMakeLists.txt ├── Kconfig.projbuild ├── certs │ ├── aws_codesign.crt │ └── root_cert_auth.crt ├── demo_tasks │ ├── ota_over_mqtt_demo │ │ ├── ota_over_mqtt_demo.c │ │ ├── ota_over_mqtt_demo.h │ │ └── ota_over_mqtt_demo_config.h │ ├── sub_pub_unsub_demo │ │ ├── sub_pub_unsub_demo.c │ │ ├── sub_pub_unsub_demo.h │ │ └── sub_pub_unsub_demo_config.h │ └── temp_sub_pub_and_led_control_demo │ │ ├── hardware_drivers │ │ ├── app_driver.c │ │ └── app_driver.h │ │ ├── temp_sub_pub_and_led_control_demo.c │ │ ├── temp_sub_pub_and_led_control_demo.h │ │ └── temp_sub_pub_and_led_control_demo_config.h ├── idf_component.yml ├── main.c ├── networking │ ├── mqtt │ │ ├── core_mqtt_agent_manager.c │ │ ├── core_mqtt_agent_manager.h │ │ ├── core_mqtt_agent_manager_config.h │ │ ├── core_mqtt_agent_manager_events.c │ │ ├── core_mqtt_agent_manager_events.h │ │ ├── subscription_manager.c │ │ └── subscription_manager.h │ └── wifi │ │ ├── app_wifi.c │ │ └── app_wifi.h └── qualification_app_main.c ├── manifest.yml ├── partitions.csv └── sdkconfig.defaults /.github/.cSpellWords.txt: -------------------------------------------------------------------------------- 1 | BTDM 2 | CBMC 3 | CBOR 4 | ccbits 5 | CMOCK 6 | CMock 7 | CSDK 8 | Cmock 9 | Coverity 10 | DCMOCK 11 | DNDEBUG 12 | DTIM 13 | DTM 14 | DUNITY 15 | EFFF 16 | EFUSE 17 | Espressif 18 | IRAM 19 | LOGD 20 | LOGI 21 | LOGW 22 | MISRA 23 | MQTT 24 | Misra 25 | NETIF 26 | Nayuki 27 | OTAE 28 | QRCODE 29 | QRCODEGEN 30 | SPIWP 31 | UNACKED 32 | UNSUB 33 | UNSUBACK 34 | Wunused 35 | Yscwc 36 | aflags 37 | bssid 38 | cbmc 39 | cbor 40 | cmock 41 | coremqtt 42 | coverity 43 | ctest 44 | cust 45 | espressif 46 | fctry 47 | getpacketid 48 | gpio 49 | isystem 50 | lcov 51 | leds 52 | lmac 53 | mbox 54 | misra 55 | mockrng 56 | mqttexample 57 | mypy 58 | netif 59 | noos 60 | otademoconfig 61 | pcontext 62 | pylint 63 | pytest 64 | pyyaml 65 | qrcode 66 | qrcodegen 67 | qrsize 68 | rsdiv 69 | rssi 70 | search 71 | sinclude 72 | subpubunsubconfig 73 | tsens 74 | unsubscriptions 75 | utest 76 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @FreeRTOS/pr-bar-raiser 2 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check [existing open](https://github.com/FreeRTOS/coreMQTT/issues), or [recently closed](https://github.com/FreeRTOS/coreMQTT/issues?q=is%3Aissue+is%3Aclosed), issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *main* branch. 27 | 1. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 1. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 1. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 1. Ensure that your contributions conform to the [style guide](https://docs.aws.amazon.com/embedded-csdk/202011.00/lib-ref/docs/doxygen/output/html/guide_developer_styleguide.html). 35 | 1. Format your code with uncrustify, using the config available in [FreeRTOS/CI-CD-Github-Actions](https://github.com/FreeRTOS/CI-CD-Github-Actions/blob/main/formatting/uncrustify.cfg). 36 | 1. Ensure local tests pass. 37 | 1. Commit to your fork using clear commit messages. 38 | 1. Send us a pull request, answering any default questions in the pull request interface. 39 | 1. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 40 | 41 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 42 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 43 | 44 | 45 | ## Finding contributions to work on 46 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/FreeRTOS/coreMQTT/labels?q=help+wanted) issues is a great place to start. 47 | 48 | 49 | ## Code of Conduct 50 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 51 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 52 | opensource-codeofconduct@amazon.com with any additional questions or comments. 53 | 54 | 55 | ## Security issue notifications 56 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](https://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 57 | 58 | 59 | ## Licensing 60 | 61 | See the [LICENSE](../LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 62 | 63 | We may ask you to sign a [Contributor License Agreement (CLA)](https://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 64 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Create a report to help us improve iot-reference-esp32c3 by identifying any confirmed 4 | bugs. To discuss a potential bug, or pose other inquiries, please open an issue 5 | using the template linked below. 6 | title: "[BUG] " 7 | labels: 'Type: Bug' 8 | assignees: '' 9 | 10 | --- 11 | 12 | **Describe the bug** 13 | Please provide a clear and concise description explaining the bug. 14 | 15 | **System information** 16 | - Hardware board: [ ... ] 17 | - IDE used: [ ... ] 18 | - Operating System: [ Windows | Linux | MacOS ] 19 | - Code version: (run ``git describe --tags`` to find it) 20 | - Project/Demo: [ mqtt_demo_mutual_auth | shadow_demo | custom application | etc... ] 21 | - If your project is a custom application, please add the relevant code snippet(s) in the section titled `"Code to reproduce bug"`. 22 | 23 | **Expected behavior** 24 | A clear description of the expected behavior. 25 | 26 | **Screenshots or console output** 27 | If appropriate, please paste the console output/error log explaining the issue. If possible, include the call stack. 28 | 29 | **Steps to reproduce bug** 30 | Example: 31 | 1. "I am using project [ ... ], and have configured with [ ... ]" 32 | 2. "When run on [ ... ], I observed that [ ... ]" 33 | 34 | **Code to reproduce bug** 35 | The code should be wrapped in the ``cpp`` tag in order to be displayed clearly. For example: 36 | 37 | ```cpp 38 | printf("Hello World") 39 | ``` 40 | 41 | **Additional context** 42 | Include any additional context relevant to the issue here. 43 | 44 | 45 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: FreeRTOS Community Support Forum 4 | url: https://forums.freertos.org/ 5 | about: Please ask and answer questions about FreeRTOS here. 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Documentation issue 3 | about: Create a report to help us improve our documentation. 4 | title: "[DOC]" 5 | labels: documentation 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the issue** 11 | Please describe the issue and expected clarification in concise language. 12 | 13 | **Reference** 14 | Please attach the URL at which you are experiencing the issue. 15 | 16 | **Screenshot** 17 | If applicable, please attach screenshot. 18 | 19 | **Browser** 20 | - Browser: [e.g. Chrome] 21 | - Version: [e.g. 80.0.3987.132] 22 | 23 | 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest a new feature for this repository. 4 | title: "[Feature Request] " 5 | labels: Feature Request 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to an issue you've encountered? If so, please elaborate.** 11 | Please provide a clear and concise description of the problem. For example, "I'm always frustrated when [ ... ]". 12 | 13 | **Describe the new feature request** 14 | Provide a clear and concise description of the feature you are proposing, as well as applicable use cases. 15 | 16 | **Describe other alternatives you've considered** 17 | Provide a clear and concise description of any alternatives you've considered. 18 | 19 | **Additional context** 20 | Add any additional information supporting the request here (screenshots, logs, references, etc.). 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Description 4 | ----------- 5 | 6 | 7 | Test Steps 8 | ----------- 9 | 10 | 11 | Checklist: 12 | ---------- 13 | 14 | 15 | - [ ] I have tested my changes. No regression in existing tests. 16 | - [ ] I have modified and/or added unit-tests to cover the code changes in this Pull Request. 17 | 18 | Related Issue 19 | ----------- 20 | 21 | 22 | By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. 23 | -------------------------------------------------------------------------------- /.github/memory_statistics_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "lib_name": "coreMQTT", 3 | "src": [ 4 | "source/core_mqtt.c", 5 | "source/core_mqtt_state.c", 6 | "source/core_mqtt_serializer.c" 7 | ], 8 | "include": [ 9 | "source/include", 10 | "source/interface" 11 | ], 12 | "compiler_flags": [ 13 | "MQTT_DO_NOT_USE_CUSTOM_CONFIG" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: "Demo Build Checks" 2 | 3 | env: 4 | bashPass: \033[32;1mPASSED - 5 | bashInfo: \033[33;1mINFO - 6 | bashFail: \033[31;1mFAILED - 7 | bashEnd: \033[0m 8 | 9 | on: 10 | push: 11 | branches: ["**"] 12 | pull_request: 13 | branches: [main] 14 | workflow_dispatch: 15 | 16 | jobs: 17 | build: 18 | runs-on: ubuntu-latest 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | esp_idf_version: 23 | - v5.0 24 | - v5.1.2 25 | - release-v5.2 26 | - latest 27 | esp_target: 28 | - esp32 29 | - esp32s2 30 | - esp32s3 31 | - esp32c3 32 | steps: 33 | - uses: actions/checkout@v3 34 | with: 35 | submodules: true 36 | fetch-depth: 0 37 | 38 | - env: 39 | bashPass: \033[32;1mPASSED - 40 | bashInfo: \033[33;1mINFO - 41 | bashFail: \033[31;1mFAILED - 42 | bashEnd: \033[0m 43 | stepName: Perform Recursive Clone of esp-aws-iot 44 | name: ${{ env.stepName }} 45 | shell: bash 46 | run: | 47 | # ${{ env.stepName }} 48 | echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" 49 | git submodule update --checkout --init --recursive 50 | echo -e "::endgroup::" 51 | echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" 52 | 53 | - name: Build for 54 | uses: espressif/esp-idf-ci-action@v1 55 | with: 56 | esp_idf_version: ${{ matrix.esp_idf_version }} 57 | target: ${{ matrix.esp_target }} 58 | path: './' 59 | command: python -m pip install --upgrade idf-component-manager && idf.py build 60 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: "CI Checks" 2 | 3 | env: 4 | bashPass: \033[32;1mPASSED - 5 | bashInfo: \033[33;1mINFO - 6 | bashFail: \033[31;1mFAILED - 7 | bashEnd: \033[0m 8 | 9 | on: 10 | push: 11 | branches: ["**"] 12 | pull_request: 13 | branches: ["**"] 14 | workflow_dispatch: 15 | 16 | jobs: 17 | spell-check: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Clone This Repo 21 | uses: actions/checkout@v3 22 | - name: Run spellings check 23 | uses: FreeRTOS/CI-CD-Github-Actions/spellings@main 24 | with: 25 | path: ./ 26 | 27 | formatting: 28 | runs-on: ubuntu-20.04 29 | steps: 30 | - uses: actions/checkout@v3 31 | - name: Check formatting 32 | uses: FreeRTOS/CI-CD-Github-Actions/formatting@main 33 | with: 34 | path: ./ 35 | 36 | link-verifier: 37 | runs-on: ubuntu-latest 38 | steps: 39 | - uses: actions/checkout@v3 40 | - name: Check Links 41 | env: 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | uses: FreeRTOS/CI-CD-Github-Actions/link-verifier@main 44 | with: 45 | path: ./ 46 | 47 | verify-manifest: 48 | runs-on: ubuntu-latest 49 | steps: 50 | - uses: actions/checkout@v3 51 | with: 52 | submodules: true 53 | fetch-depth: 0 54 | 55 | - env: 56 | bashPass: \033[32;1mPASSED - 57 | bashInfo: \033[33;1mINFO - 58 | bashFail: \033[31;1mFAILED - 59 | bashEnd: \033[0m 60 | stepName: Perform Recursive Clone of esp-aws-iot 61 | name: ${{ env.stepName }} 62 | shell: bash 63 | run: | 64 | # ${{ env.stepName }} 65 | echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" 66 | git submodule update --checkout --init --recursive 67 | echo -e "::endgroup::" 68 | echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" 69 | 70 | - name: Run manifest verifier 71 | uses: FreeRTOS/CI-CD-GitHub-Actions/manifest-verifier@main 72 | with: 73 | path: ./ 74 | fail-on-incorrect-version: true 75 | 76 | git-secrets: 77 | runs-on: ubuntu-latest 78 | steps: 79 | - uses: actions/checkout@v3 80 | - name: Checkout awslabs/git-secrets 81 | uses: actions/checkout@v3 82 | with: 83 | repository: awslabs/git-secrets 84 | ref: master 85 | path: git-secrets 86 | - name: Install git-secrets 87 | run: cd git-secrets && sudo make install && cd .. 88 | - name: Run git-secrets 89 | run: | 90 | git-secrets --register-aws 91 | git-secrets --scan 92 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release automation 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | commit_id: 7 | description: 'Commit ID/branch to tag and create a release for' 8 | required: true 9 | version_number: 10 | description: 'Release Version (Eg, v202212.00)' 11 | required: true 12 | 13 | env: 14 | repository_compressed_name: ${{ github.event.repository.name }}v${{ github.event.inputs.version_number }} 15 | repostiory_zip_name: ${{ github.event.repository.name }}.zip 16 | 17 | jobs: 18 | tag-commit: 19 | name: Tag commit 20 | runs-on: ubuntu-latest 21 | steps: 22 | - name: Checkout code 23 | uses: actions/checkout@v4 24 | with: 25 | ref: ${{ github.event.inputs.commit_id }} 26 | - name: Configure git identity 27 | env: 28 | ACTOR: ${{ github.actor }} 29 | run: | 30 | git config --global user.name "$ACTOR" 31 | git config --global user.email "$ACTOR"@users.noreply.github.com 32 | - name: create a new branch that references commit id 33 | env: 34 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 35 | COMMIT_ID: ${{ github.event.inputs.commit_id }} 36 | run: git checkout -b "$VERSION_NUMBER" "$COMMIT_ID" 37 | - name: Tag Commit and Push to remote 38 | env: 39 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 40 | run: | 41 | git tag "$VERSION_NUMBER" -a -m "Release $VERSION_NUMBER" 42 | git push origin --tags 43 | - name: Verify tag on remote 44 | env: 45 | VERSION_NUMBER: ${{ github.event.inputs.version_number }} 46 | COMMIT_ID: ${{ github.event.inputs.commit_id }} 47 | run: | 48 | git tag -d "$VERSION_NUMBER" 49 | git remote update 50 | git checkout tags/"$VERSION_NUMBER" 51 | git diff "$COMMIT_ID" tags/"$VERSION_NUMBER" 52 | create-zip: 53 | needs: tag-commit 54 | name: Create ZIP and verify package for release asset. 55 | runs-on: ubuntu-latest 56 | steps: 57 | - name: Install ZIP tools 58 | run: sudo apt-get install zip unzip 59 | - name: Checkout code 60 | uses: actions/checkout@v4 61 | with: 62 | ref: ${{ github.event.inputs.commit_id }} 63 | path: ${{ github.event.repository.name }} 64 | submodules: recursive 65 | - name: Checkout disabled submodules 66 | env: 67 | REPO_NAME: ${{ github.event.repository.name }} 68 | run: | 69 | cd "$REPO_NAME" 70 | git submodule update --init --checkout --recursive 71 | - name: Create ZIP 72 | env: 73 | REPO_NAME: ${{ github.event.repository.name }} 74 | run: | 75 | zip -r ${{ env.repostiory_zip_name }} "$REPO_NAME" -x "*.git*" 76 | ls ./ 77 | - name: Validate created ZIP 78 | env: 79 | REPO_NAME: ${{ github.event.repository.name }} 80 | run: | 81 | mkdir zip-check 82 | mv ${{ env.repostiory_zip_name }} zip-check 83 | cd zip-check 84 | unzip ${{ env.repostiory_zip_name }} -d ${{ env.repository_compressed_name }} 85 | ls ${{ env.repository_compressed_name }} 86 | diff -r -x "*.git*" ${{ env.repository_compressed_name }}/"$REPO_NAME"/ ../"$REPO_NAME"/ 87 | - name: Create artifact of ZIP 88 | uses: actions/upload-artifact@v4 89 | with: 90 | name: ${{ env.repostiory_zip_name }} 91 | path: zip-check/${{ env.repostiory_zip_name }} 92 | create-release: 93 | needs: create-zip 94 | name: Create Release and Upload Release Asset 95 | runs-on: ubuntu-latest 96 | steps: 97 | - name: Create Release 98 | id: create_release 99 | uses: actions/create-release@v1 100 | env: 101 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 102 | with: 103 | tag_name: ${{ github.event.inputs.version_number }} 104 | release_name: ${{ github.event.inputs.version_number }} 105 | body: ${{ github.event.inputs.version_number }} Release 106 | draft: false 107 | prerelease: false 108 | - name: Download ZIP artifact 109 | uses: actions/download-artifact@v4.1.7 110 | with: 111 | name: ${{ env.repostiory_zip_name }} 112 | - name: Upload Release Asset 113 | id: upload-release-asset 114 | uses: actions/upload-release-asset@v1 115 | env: 116 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 117 | with: 118 | upload_url: ${{ steps.create_release.outputs.upload_url }} 119 | asset_path: ./${{ env.repostiory_zip_name }} 120 | asset_name: ${{ env.repostiory_zip_name }} 121 | asset_content_type: application/zip 122 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | **/.DS_Store 3 | main/certs/ 4 | esp_ds_data/ 5 | managed_components/ 6 | sdkconfig 7 | sdkconfig.old 8 | dependencies.lock 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "components/FreeRTOS-Libraries-Integration-Tests/FreeRTOS-Libraries-Integration-Tests"] 2 | path = components/FreeRTOS-Libraries-Integration-Tests/FreeRTOS-Libraries-Integration-Tests 3 | url = https://github.com/FreeRTOS/FreeRTOS-Libraries-Integration-Tests 4 | [submodule "components/esp-aws-iot"] 5 | path = components/esp-aws-iot 6 | url = https://github.com/espressif/esp-aws-iot.git 7 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "idf.adapterTargetName": "esp32c3" 3 | } -------------------------------------------------------------------------------- /AWSSetup.md: -------------------------------------------------------------------------------- 1 | # AWS IoT Core Setup 2 | In case you already have an AWS account and user created, you can skip steps 1 and 2 and directly go to step 3 (Registering your board with AWS IoT). 3 | 4 | ## 1 Sign up for an AWS account 5 | 6 | 1. Open https://portal.aws.amazon.com/billing/signup. 7 | 2. Follow the online instructions. **NOTE:** Part of the sign-up procedure involves receiving a phone call and entering a verification code on the phone keypad. 8 | 3. Make a note of your AWS account number as it will be needed for the following steps. 9 | 10 | ## 2 Create an Administrator IAM user and grant it permissions 11 | 12 | It’s strongly recommended that you adhere to the best practice of using the `Administrator` IAM user. The following steps show you how to create and securely lock away the root user credentials. One should only sign in as the root user to perform a few [account and service management tasks](https://docs.aws.amazon.com/general/latest/gr/root-vs-iam.html#aws_tasks-that-require-root). 13 | 14 | 1. Sign in to the [IAM console](https://console.aws.amazon.com/iam/) as the account owner by choosing **Root user** and entering your AWS account email address. On the next page, enter your password. 15 | 2. On the navigation bar, click your account name, and then click Account. 16 | 17 | ![image](https://user-images.githubusercontent.com/23126711/165860127-2e292c8e-7cd1-4ae6-a9b4-0465a3873e7b.png) 18 | 19 | 3. Scroll down to to **IAM User and Role Access to Billing Information** and click **Edit**. 20 | 21 | ![image](https://user-images.githubusercontent.com/23126711/165860178-43a17955-1e9b-4b06-81fc-a169b587c8e5.png) 22 | 23 | 4. Select the **Activate IAM Access** check box to activate access to the Billing and Cost Management console pages. This is necessary to create an IAM role with AdministrativeAccess in the following steps. 24 | 25 | ![image](https://user-images.githubusercontent.com/23126711/165860214-6c5aae4c-9ee0-4e07-8712-1cd7c067d175.png) 26 | 27 | 5. Click **Update**. 28 | 6. Return to the [IAM console](https://console.aws.amazon.com/iam/). 29 | 7. In the navigation pane, choose **Users** and then choose **Add user**. 30 | 31 | ![image](https://user-images.githubusercontent.com/23126711/165860249-faa9da14-cd2e-4e33-b1a1-97f279149dee.png) 32 | ![image](https://user-images.githubusercontent.com/23126711/165860274-6a3e30f3-a32d-4c49-806d-600b5e571e11.png) 33 | 34 | 8. For **User name**, enter `Administrator`. Select the check box next to **AWS Management Console access**. Then select **Custom password**, and then enter your new password in the text box. 35 | 9. (Optional) By default, AWS requires the new user to create a new password when first signing in. You can clear the check box next to **User must create a new password at next sign-in** to allow the new user to reset their password after they sign in. 36 | 37 | ![image](https://user-images.githubusercontent.com/23126711/165860310-579a0be4-8082-49c0-a6a9-1a7cf40b7088.png) 38 | 39 | 10. Click **Next: Permissions**. 40 | 11. Click **Create group**. 41 | 42 | ![image](https://user-images.githubusercontent.com/23126711/165860339-b3017148-3dec-4265-88a6-27a009e57a6b.png) 43 | 44 | 12. In the **Create group** dialog box, for **Group name** enter `Administrators`. 45 | 13. In the search box next to **Filter policies**, enter **Administrator Access.** 46 | 14. In the policy list, select the check box for **AdministratorAccess**. Then choose **Create group**. 47 | 48 | ![image](https://user-images.githubusercontent.com/23126711/165860389-02ac5479-fd38-4d4e-939c-fbae71e0bc37.png) 49 | 50 | 15. Back in the list of groups, select the check box for your new group. Choose **Refresh** if necessary to see the group in the list. 51 | 52 | ![image](https://user-images.githubusercontent.com/23126711/165860413-f07f5bee-18c2-455a-a18e-4926a78880da.png) 53 | 54 | 16. Click **Next: Tags**. 55 | 17. **(Optional)** Add metadata to the user by attaching tags as key-value pairs. For more information about using tags in IAM, see [Tagging IAM entities](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_tags.html) in the *IAM User Guide*. 56 | 18. Click **Next: Review** to see the list of group memberships to be added to the new user. When you are ready to proceed, click **Create user**. 57 | 58 | ![image](https://user-images.githubusercontent.com/23126711/165860439-420b42d5-6303-47bd-9f6b-12c936326aca.png) 59 | 60 | 19. You should now see a page like the following, stating that your IAM user has been created. Click **Download .csv** in order to save your IAM credentials - store these in a safe place. These are necessary for signing into the AWS console with your newly created IAM user. 61 | 62 | ![image](https://user-images.githubusercontent.com/23126711/165860511-ad970190-ccfe-4df0-86c8-ab0c67b9b4d0.png) 63 | 64 | 20. On the navigation bar, click your account name, and then click **Sign Out**. 65 | 21. Click **Sign In to the Console** or go to https://console.aws.amazon.com/. 66 | 22. Select **IAM user** and enter your Account ID noted earlier, then click **Next**. 67 | 68 | ![image](https://user-images.githubusercontent.com/23126711/165860545-3d4d156b-d4ac-4e32-92b0-5b1161ce49b5.png) 69 | 70 | 23. Enter **Administrator** in **IAM user name,** enter the **Password** set earlier for the IAM user, then click **Sign in**. 71 | 72 | ![image](https://user-images.githubusercontent.com/23126711/165860570-dc8b1961-eb6c-4782-abd3-1ca0de07b91c.png) 73 | 74 | 24. You are now signed in as your **Administrator** IAM user. This IAM user will be used for following steps. 75 | 76 | ## 3 Registering your board with AWS IoT 77 | 78 | Your board must be registered with AWS IoT to communicate with the AWS Cloud. To register your board with AWS IoT, you must have: 79 | 80 | * **An AWS IoT policy:** An AWS IoT policy grants your device permissions to access AWS IoT resources. It is stored in the AWS Cloud. 81 | * **An AWS IoT thing:** An AWS IoT thing allows you to manage your devices in AWS IoT. It represents your device and is stored in the AWS Cloud. 82 | * **A private key and X.509 certificate:** A private key and its corresponding public key certificate allow your device to authenticate and communicate securely with AWS IoT. 83 | * **An AWS endpoint:** An AWS endpoint is the URL, or the AWS IoT Core entry point, your devices will connect to. 84 | 85 | ### 3.1 Creating an AWS IoT policy 86 | 87 | 1. Go to the [AWS IoT console](https://console.aws.amazon.com/iotv2/). 88 | 2. In the navigation pane, click **Secure**, then click **Policies** in the drop-down menu. 89 | 90 | ![image](https://user-images.githubusercontent.com/23126711/165860604-9bc500fe-d1b2-45c8-a997-eb527a0c144c.png) 91 | 92 | 3. Click **Create Policy**. 93 | 4. Enter a name to identify the policy. For this example, the name **DevicePolicy** will be used. 94 | 95 | ![image](https://user-images.githubusercontent.com/23126711/165860619-ef9dfcf0-6e08-454b-a267-2cdfb8c6b2f9.png) 96 | 97 | 5. Identify your **AWS region** by clicking the location dropdown menu at the top of the page to the left of the account dropdown menu. The **AWS region** is the orange text on the right. For this example, the **AWS region** will be **us-west-2**. 98 | 99 | ![image](https://user-images.githubusercontent.com/23126711/165860649-05961265-f2a2-4608-a62c-03076bf16506.png) 100 | 101 | 6. Scroll down to **Policy document** and click the **JSON** button. 102 | 103 | ![image](https://user-images.githubusercontent.com/23126711/165860676-e4ad5798-7049-45fc-90ed-cfa9b6c646a8.png) 104 | 105 | 7. Inside the **Policy document**, copy and paste the following JSON into the policy editor window. Replace `aws-region` and `aws-account-id` with your AWS Region and Account ID. 106 | 107 | ``` 108 | { 109 | "Version": "2012-10-17", 110 | "Statement": [ 111 | { 112 | "Effect": "Allow", 113 | "Action": "iot:Connect", 114 | "Resource":"arn:aws:iot:aws-region:aws-account-id:*" 115 | }, 116 | { 117 | "Effect": "Allow", 118 | "Action": "iot:Publish", 119 | "Resource": "arn:aws:iot:aws-region:aws-account-id:*" 120 | }, 121 | { 122 | "Effect": "Allow", 123 | "Action": "iot:Subscribe", 124 | "Resource": "arn:aws:iot:aws-region:aws-account-id:*" 125 | }, 126 | { 127 | "Effect": "Allow", 128 | "Action": "iot:Receive", 129 | "Resource": "arn:aws:iot:aws-region:aws-account-id:*" 130 | } 131 | ] 132 | } 133 | ``` 134 | 135 | ![image](https://user-images.githubusercontent.com/23126711/165860693-358be23a-c2c1-4c6d-9398-9f93c3b020d0.png) 136 | 137 | This policy grants the following permissions: 138 | 139 | * **iot:Connect:** Grants your device the permission to connect to the AWS IoT message broker with any client ID. 140 | * **iot:Publish:** Grants your device the permission to publish an MQTT message on any MQTT topic. 141 | * **iot:Subscribe:** Grants your device the permission to subscribe to any MQTT topic filter. 142 | * **iot:Receive:** Grants your device the permission to receive messages from the AWS IoT message broker on any MQTT topic. 143 | 144 | For more information regarding [IAM policy creation](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html) refer to [Creating IAM policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html). 145 | 146 | 8. Click **Create**. 147 | 148 | ### 3.2 Creating an IoT thing, private key, and device certificate 149 | 150 | 1. Go to the [AWS IoT console](https://console.aws.amazon.com/iotv2/). 151 | 2. In the navigation pane, choose **Manage**, and then choose **Things**. 152 | 153 | ![image](https://user-images.githubusercontent.com/23126711/165860729-68ddc292-71a7-4bc6-a830-b671b7b5c5cf.png) 154 | 155 | 3. Click **Create things.** 156 | 157 | ![image](https://user-images.githubusercontent.com/23126711/165860761-43739bfc-47b8-4e07-9c19-70cc1964ad27.png) 158 | 159 | 4. Select **Create a single thing** then click **Next**. 160 | 161 | ![image](https://user-images.githubusercontent.com/23126711/165860791-b136b6c5-83f6-4860-aae2-9f5bbb37cdf1.png) 162 | 163 | 5. Enter a name for your thing, and then click **Next**. For this example, the thing name will be **ExampleThing**. 164 | 165 | ![image](https://user-images.githubusercontent.com/23126711/165860814-36cb347e-d9f0-433a-a954-c24ac04e84cc.png) 166 | 167 | 6. Select **Auto-generate a new certificate**, then click **Next**. 168 | 169 | ![image](https://user-images.githubusercontent.com/23126711/165860839-2a5d36c5-6b09-47cd-853e-3b3241981eb5.png) 170 | 171 | 7. Attach the policy you created above by searching for it and clicking the checkbox next to it, then click **Create thing**. **NOTE:** Multiple policies can be attached to a thing. 172 | 173 | ![image](https://user-images.githubusercontent.com/23126711/165860858-4bda82f0-1159-4fc3-9dfd-e21fe3276d18.png) 174 | 175 | 8. Download your **Private Key**, **Public Key**, and **Device Certificate** by clicking the **Download** links for each. These will be used by your device to connect to AWS IoT Core. **NOTE:** The private key and public key can only be downloaded here, so store them in a safe place. Also download the Amazon Root CA 1 certificate. 176 | 177 | ![image](https://user-images.githubusercontent.com/23126711/165860877-e4c08025-fb51-4718-8b22-839d20dd1971.png) 178 | 179 | ### 3.3 Obtaining your AWS endpoint 180 | 181 | 1. Go to [AWS IoT console](https://console.aws.amazon.com/iotv2/). 182 | 2. In the navigation pane, click **Settings**. 183 | 184 | ![image](https://user-images.githubusercontent.com/23126711/165860893-20a44ef2-d13b-494a-841b-df1092a79e9b.png) 185 | 186 | 3. Your **AWS endpoint** is under **Device data endpoint**. Note this endpoint as it will be used later when setting up your board. 187 | 188 | ![image](https://user-images.githubusercontent.com/23126711/165860926-55c402db-092c-4605-9143-8aaeae573988.png) 189 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog for ESP32-C3 MCU Featured FreeRTOS IoT Integration 2 | 3 | ## v202407.00 ( July 2024 ) 4 | - [#88](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/88) Update Long Term Support (LTS) libraries to 202406.01-LTS: 5 | * [coreMQTT v2.3.1](https://github.com/FreeRTOS/coreMQTT/blob/v2.3.1) 6 | * [coreHTTP v3.1.1](https://github.com/FreeRTOS/coreHTTP/tree/v3.1.1) 7 | * [corePKCS11 v3.6.1](https://github.com/FreeRTOS/corePKCS11/tree/v3.6.1) 8 | * [coreJSON v3.3.0](https://github.com/FreeRTOS/coreJSON/tree/v3.3.0) 9 | * [backoffAlgorithm v1.4.1](https://github.com/FreeRTOS/backoffAlgorithm/tree/v1.4.1) 10 | * [AWS IoT Device Shadow v1.4.1](https://github.com/aws/Device-Shadow-for-AWS-IoT-embedded-sdk/tree/v1.4.1) 11 | * [AWS IoT Device Defender v1.4.0](https://github.com/aws/Device-Defender-for-AWS-IoT-embedded-sdk/tree/v1.4.0) 12 | * [AWS IoT Jobs v1.5.1](https://github.com/aws/Jobs-for-AWS-IoT-embedded-sdk/tree/v1.5.1) 13 | * [AWS MQTT file streams v1.1.0](https://github.com/aws/aws-iot-core-mqtt-file-streams-embedded-c/tree/v1.1.0) 14 | 15 | - [#79](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/79) Fix out of order PUBACK and PUBLISH handling 16 | - [#71](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/71) Update Security Feature guide to cover ESP-IDF latest version changes 17 | - [#77](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/77) Notify other tasks that OTA is stopped when fail to activate new image 18 | - [#76](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/76) Post OTA_STOPPED_EVENT once new image verification finished 19 | - [#68](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/68) Shrink idle and timer task stack and OTA buffers to fit into mimimal size when using ESP IDF v5.1 20 | - [#66](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/66) Add C linage for C++ support 21 | - [#64](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/64) Fix GPIO level in temperature sensor pub sub and LED control demo 22 | - [#57](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/57) Add matrix build for supported targets 23 | - [#43](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/43) Add process loop call in MQTT Agent manager to fix TLS connection dropped. 24 | - [#20](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/20) Updated esp_secure_cert_mgr and IDF v5.0 support 25 | 26 | ## v202212.00 ( December 2022 ) 27 | - [#12](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/12) Update Long Term Support (LTS) libraries to 202210.01-LTS: 28 | * [coreMQTT v2.1.1](https://github.com/FreeRTOS/coreMQTT/blob/v2.1.1/CHANGELOG.md) 29 | * [coreHTTP v3.0.0](https://github.com/FreeRTOS/coreHTTP/tree/v3.0.0) 30 | * [corePKCS11 v3.5.0](https://github.com/FreeRTOS/corePKCS11/tree/v3.5.0) 31 | * [coreJSON v3.2.0](https://github.com/FreeRTOS/coreJSON/tree/v3.2.0) 32 | * [backoffAlgorithm v1.3.0](https://github.com/FreeRTOS/backoffAlgorithm/tree/v1.3.0) 33 | * [AWS IoT Device Shadow v1.3.0](https://github.com/aws/Device-Shadow-for-AWS-IoT-embedded-sdk/tree/v1.3.0) 34 | * [AWS IoT Device Defender v1.3.0](https://github.com/aws/Device-Defender-for-AWS-IoT-embedded-sdk/tree/v1.3.0) 35 | * [AWS IoT Jobs v1.3.0](https://github.com/aws/Jobs-for-AWS-IoT-embedded-sdk/tree/v1.3.0) 36 | * [AWS IoT Over-the-air Update v3.4.0](https://github.com/aws/ota-for-aws-iot-embedded-sdk/tree/v3.4.0) 37 | 38 | - [#5](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/5) and [#10](https://github.com/FreeRTOS/iot-reference-esp32c3/pull/10) Documentation updates 39 | 40 | ## v202204.00 ( April 2022 ) 41 | 42 | This is the first release for the repository. 43 | 44 | The repository contains IoT Reference integration projects using the ESP32-C3. This release includes the following examples: 45 | * MQTT Publish/Subscribe/Unsubscribe with OTA capability 46 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | set(EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_LIST_DIR}/components/esp-aws-iot/libraries/" 4 | ) 5 | 6 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 7 | include_directories(BEFORE "${CMAKE_CURRENT_LIST_DIR}/main") 8 | project(FeaturedFreeRTOSIoTIntegration) 9 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *main* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Amazon.com, Inc. or its affiliates 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Featured FreeRTOS IoT Integration on Espressif SoCs 2 | 3 | ## Introduction 4 | 5 | This repository contains a project that demonstrates how to integrate FreeRTOS modular software libraries with the hardware capabilities of [Espressif SoCs](https://www.espressif.com/en/products/socs/) and the enhanced security capabilities. 6 | The project contains reference implementations that demonstrate IoT application tasks that run concurrently and communicate with enhanced security with [AWS IoT](https://aws.amazon.com/iot-core/). The implementation also shows how to perform over-the-air firmware updates that use the [AWS IoT OTA service](https://docs.aws.amazon.com/freertos/latest/userguide/freertos-ota-dev.html) and the secure bootloader capabilities of Secure Boot V2. 7 | 8 | The reference implementation is tested to run on the following IoT development boards: 9 | 1. ESP32 10 | 2. ESP32-C3 11 | 3. ESP32-S3 12 | 13 | See the [Featured IoT Reference Integration page](https://www.freertos.org/featured-freertos-iot-integration-targeting-an-espressif-esp32-c3-risc-v-mcu) on FreeRTOS.org for more details about the DS peripheral, Secure Boot and OTA. 14 | 15 | ## Cloning the Repository 16 | 17 | To clone using HTTPS: 18 | 19 | ``` 20 | git clone https://github.com/FreeRTOS/iot-reference-esp32.git --recurse-submodules 21 | ``` 22 | 23 | Using SSH: 24 | 25 | ``` 26 | git clone git@github.com:FreeRTOS/iot-reference-esp32.git --recurse-submodules 27 | ``` 28 | 29 | If you have downloaded the repo without using the --recurse-submodules argument, you should run: 30 | 31 | ``` 32 | git submodule update --init --recursive 33 | ``` 34 | 35 | ## Demos 36 | 37 | This repository currently supports 3 demos implemented as FreeRTOS [tasks](https://www.freertos.org/taskandcr.html), each of which utilize the same MQTT connection. The demos use the [coreMQTT](https://www.freertos.org/mqtt/index.html) library, while the [coreMQTT-Agent](https://www.freertos.org/mqtt-agent/index.html) library is employed to manage thread safety for the MQTT connection. The demos are the following: 38 | 39 | * **ota_over_mqtt_demo**: This demo uses the [AWS IoT OTA service](https://docs.aws.amazon.com/freertos/latest/userguide/freertos-ota-dev.html) for FreeRTOS to configure and create OTA updates. The OTA client software on the ESP32-C3 follows the [Modular Over the Air Updates](https://freertos.org/freertos-core/over-the-air-updates/index.html) design and runs in the background within a FreeRTOS agent (or daemon) task. A new firmware image is first signed and uploaded to the OTA service, and the project is then configured to store the corresponding public key certificate. The demo subscribes to, and listens on, an OTA job topic in order to be notified of an OTA update. Upon receiving notification of a pending OTA update, the device downloads the firmware patch and performs code signature verification of the downloaded image by using the public key certificate. On successful verification, the device reboots and the updated image is activated. The OTA client then performs a self-test on the updated image to check for its integrity. 40 | * **sub_pub_unsub_demo**: The demo creates tasks which subscribe to a topic on AWS IoT Core, publish a constant string to the same topic, receive their publish (since they are subscribed to the topic they publish to), and then unsubscribe from the topic in a loop. 41 | * **temp_sub_pub_and_led_control_demo**: This demo creates a task which subscribes to a topic on AWS IoT Core. This task then reads the temperature from the onboard temperature sensor, publishes this information in JSON format to the same topic, and then receives this publish (since it is subscribed to the same topic it just published to) in a loop. This demo also enables a user to send a JSON packet back to the device to turn an LED off or on. 42 | 43 | All three demos can be selected to run together concurrently as separate tasks. 44 | 45 | ## Getting started with the demos 46 | 47 | To get started and run the demos, follow the [Getting Started Guide](GettingStartedGuide.md). 48 | 49 | ## Contributing 50 | 51 | See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. 52 | 53 | ## License 54 | 55 | Example source code under ./main/ is licensed under the MIT-0 License. See the [LICENSE](LICENSE) file. For all other source code licenses including components/, see source header documentation. 56 | -------------------------------------------------------------------------------- /components/FreeRTOS-Libraries-Integration-Tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This gives QUALIFICATION_TEST_SOURCES, and QUALIFICATION_TEST_INCLUDE_DIRS 2 | include(${CMAKE_CURRENT_LIST_DIR}/FreeRTOS-Libraries-Integration-Tests/qualification_test.cmake) 3 | 4 | # This gives TRANSPORT_TEST_SOURCES, and TRANSPORT_TEST_INCLUDE_DIRS 5 | include(${CMAKE_CURRENT_LIST_DIR}/FreeRTOS-Libraries-Integration-Tests/src/transport_interface_test.cmake) 6 | 7 | # This gives MQTT_TEST_SOURCES, and MQTT_TEST_INCLUDE_DIRS 8 | include(${CMAKE_CURRENT_LIST_DIR}/FreeRTOS-Libraries-Integration-Tests/src/mqtt_test.cmake) 9 | 10 | # This gives PKCS11_TEST_SOURCES, and PKCS11_TEST_INCLUDE_DIRS 11 | include(${CMAKE_CURRENT_LIST_DIR}/FreeRTOS-Libraries-Integration-Tests/src/pkcs11_test.cmake) 12 | 13 | set(IDT_INCLUDE_DIRS 14 | ${QUALIFICATION_TEST_INCLUDE_DIRS} 15 | ${TRANSPORT_TEST_INCLUDE_DIRS} 16 | ${MQTT_TEST_INCLUDE_DIRS} 17 | ${OTA_PAL_TEST_INCLUDE_DIRS} 18 | ${PKCS11_TEST_INCLUDE_DIRS} 19 | ${CMAKE_CURRENT_LIST_DIR}/config 20 | ) 21 | 22 | set(IDT_SRCS 23 | ${QUALIFICATION_TEST_SOURCES} 24 | ${TRANSPORT_TEST_SOURCES} 25 | ${MQTT_TEST_SOURCES} 26 | ${OTA_PAL_TEST_SOURCES} 27 | ${PKCS11_TEST_SOURCES} 28 | ${CMAKE_CURRENT_LIST_DIR}/port/platform_function.c 29 | ${CMAKE_CURRENT_LIST_DIR}/../esp-aws-iot/libraries/corePKCS11/corePKCS11/source/dependency/3rdparty/mbedtls_utils/mbedtls_utils.c 30 | ) 31 | 32 | set(IDT_REQUIRES 33 | unity 34 | coreMQTT 35 | coreHTTP 36 | freertos 37 | corePKCS11 38 | aws-iot-core-mqtt-file-streams-embedded-c 39 | ) 40 | 41 | idf_component_register( 42 | SRCS 43 | ${IDT_SRCS} 44 | INCLUDE_DIRS 45 | ${IDT_INCLUDE_DIRS} 46 | REQUIRES 47 | ${IDT_REQUIRES} 48 | ) 49 | -------------------------------------------------------------------------------- /components/FreeRTOS-Libraries-Integration-Tests/config/qualification_wrapper_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef QUALIFICATION_WRAPPER_CONFIG_H 28 | #define QUALIFICATION_WRAPPER_CONFIG_H 29 | 30 | /* ESP-IDF sdkconfig include. */ 31 | #include 32 | 33 | #if ( CONFIG_GRI_RUN_QUALIFICATION_TEST == 1 ) 34 | #include "test_execution_config.h" 35 | #include "test_param_config.h" 36 | 37 | /* Common config */ 38 | #if ( MQTT_TEST_ENABLED == 1 ) 39 | #define CONFIG_GRI_THING_NAME ( MQTT_TEST_CLIENT_IDENTIFIER ) 40 | #elif ( OTA_E2E_TEST_ENABLED == 1 ) || ( DEVICE_ADVISOR_TEST_ENABLED == 1 ) 41 | #define CONFIG_GRI_THING_NAME ( IOT_THING_NAME ) 42 | #else 43 | #define CONFIG_GRI_THING_NAME "noUse" 44 | #endif 45 | #define CONFIG_GRI_MQTT_ENDPOINT ( MQTT_SERVER_ENDPOINT ) 46 | #define CONFIG_GRI_MQTT_PORT ( MQTT_SERVER_PORT ) 47 | 48 | #if !defined( CONFIG_GRI_OTA_DEMO_APP_VERSION_MAJOR ) 49 | #define CONFIG_GRI_OTA_DEMO_APP_VERSION_MAJOR ( OTA_APP_VERSION_MAJOR ) 50 | #endif /* CONFIG_GRI_OTA_DEMO_APP_VERSION_MAJOR */ 51 | 52 | #if !defined( CONFIG_GRI_OTA_DEMO_APP_VERSION_MINOR ) 53 | #define CONFIG_GRI_OTA_DEMO_APP_VERSION_MINOR ( OTA_APP_VERSION_MINOR ) 54 | #endif /* CONFIG_GRI_OTA_DEMO_APP_VERSION_MINOR */ 55 | 56 | #if !defined( CONFIG_GRI_OTA_DEMO_APP_VERSION_BUILD ) 57 | #define CONFIG_GRI_OTA_DEMO_APP_VERSION_BUILD ( OTA_APP_VERSION_BUILD ) 58 | #endif /* CONFIG_GRI_OTA_DEMO_APP_VERSION_BUILD */ 59 | 60 | #if ( OTA_E2E_TEST_ENABLED == 1 ) 61 | /* Enable OTA demo. */ 62 | #define CONFIG_GRI_ENABLE_OTA_DEMO ( 1 ) 63 | #endif /* OTA_E2E_TEST_ENABLED == 1 */ 64 | #endif /* CONFIG_GRI_RUN_QUALIFICATION_TEST */ 65 | 66 | #endif /* QUALIFICATION_WRAPPER_CONFIG_H */ 67 | -------------------------------------------------------------------------------- /components/FreeRTOS-Libraries-Integration-Tests/config/test_execution_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS FreeRTOS LTS Qualification Tests preview 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | /** 24 | * @file test_execution_config_template.h 25 | * @brief This is a template to setup the execution configurations for LTS qualification test. 26 | */ 27 | 28 | #ifndef TEST_EXECUTION_CONFIG_H 29 | #define TEST_EXECUTION_CONFIG_H 30 | 31 | #include 32 | 33 | /* Configuration wrapper. */ 34 | #if CONFIG_GRI_DEVICE_ADVISOR_TEST_ENABLED 35 | #define DEVICE_ADVISOR_TEST_ENABLED_SETTING ( 1 ) 36 | #else 37 | #define DEVICE_ADVISOR_TEST_ENABLED_SETTING ( 0 ) 38 | #endif /* CONFIG_GRI_DEVICE_ADVISOR_TEST_ENABLED */ 39 | 40 | #if CONFIG_GRI_MQTT_TEST_ENABLED 41 | #define MQTT_TEST_ENABLED_SETTING ( 1 ) 42 | #else 43 | #define MQTT_TEST_ENABLED_SETTING ( 0 ) 44 | #endif /* CONFIG_GRI_MQTT_TEST_ENABLED */ 45 | 46 | #if CONFIG_GRI_TRANSPORT_INTERFACE_TEST_ENABLED 47 | #define TRANSPORT_INTERFACE_TEST_ENABLED_SETTING ( 1 ) 48 | #else 49 | #define TRANSPORT_INTERFACE_TEST_ENABLED_SETTING ( 0 ) 50 | #endif /* CONFIG_GRI_TRANSPORT_INTERFACE_TEST_ENABLED */ 51 | 52 | #if CONFIG_GRI_OTA_PAL_TEST_ENABLED 53 | #define OTA_PAL_TEST_ENABLED_SETTING ( 1 ) 54 | #else 55 | #define OTA_PAL_TEST_ENABLED_SETTING ( 0 ) 56 | #endif /* CONFIG_GRI_OTA_PAL_TEST_ENABLED */ 57 | 58 | #if CONFIG_GRI_OTA_E2E_TEST_ENABLED 59 | #define OTA_E2E_TEST_ENABLED_SETTING ( 1 ) 60 | #else 61 | #define OTA_E2E_TEST_ENABLED_SETTING ( 0 ) 62 | #endif /* CONFIG_GRI_OTA_E2E_TEST_ENABLED */ 63 | 64 | #if CONFIG_GRI_CORE_PKCS11_TEST_ENABLED 65 | #define CORE_PKCS11_TEST_ENABLED_SETTING ( 1 ) 66 | #else 67 | #define CORE_PKCS11_TEST_ENABLED_SETTING ( 0 ) 68 | #endif /* CONFIG_GRI_CORE_PKCS11_TEST_ENABLED */ 69 | /* Configuration wrapper. */ 70 | 71 | /** 72 | * @brief Configuration to enable Device Advisor testing. 73 | * 74 | * #define DEVICE_ADVISOR_TEST_ENABLED (0) 75 | */ 76 | #define DEVICE_ADVISOR_TEST_ENABLED ( DEVICE_ADVISOR_TEST_ENABLED_SETTING ) 77 | 78 | /** 79 | * @brief Configuration to enable the MQTT test. 80 | * 81 | * #define MQTT_TEST_ENABLED (0) 82 | */ 83 | #define MQTT_TEST_ENABLED ( MQTT_TEST_ENABLED_SETTING ) 84 | 85 | /** 86 | * @brief Configuration to enable the transport interface test. 87 | * 88 | * #define TRANSPORT_INTERFACE_TEST_ENABLED (0) 89 | */ 90 | 91 | #define TRANSPORT_INTERFACE_TEST_ENABLED ( TRANSPORT_INTERFACE_TEST_ENABLED_SETTING ) 92 | 93 | /** 94 | * @brief Configuration to enable the OTA PAL test. 95 | * 96 | * #define OTA_PAL_TEST_ENABLED (0) 97 | */ 98 | #define OTA_PAL_TEST_ENABLED ( OTA_PAL_TEST_ENABLED_SETTING ) 99 | 100 | /** 101 | * @brief Configuration to enable the OTA End-to-end test. 102 | * 103 | * #define OTA_E2E_TEST_ENABLED (0) 104 | */ 105 | #define OTA_E2E_TEST_ENABLED ( OTA_E2E_TEST_ENABLED_SETTING ) 106 | 107 | /** 108 | * @brief Configuration to enable the corePKCS11 test. 109 | * 110 | * #define CORE_PKCS11_TEST_ENABLED (0) 111 | */ 112 | #define CORE_PKCS11_TEST_ENABLED ( CORE_PKCS11_TEST_ENABLED_SETTING ) 113 | 114 | #endif /* TEST_EXECUTION_CONFIG_H */ 115 | -------------------------------------------------------------------------------- /components/FreeRTOS-Libraries-Integration-Tests/config/test_param_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS FreeRTOS LTS Qualification Tests preview 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | /** 24 | * @file test_param_config.h 25 | * @brief This setup the test parameters for LTS qualification test. 26 | */ 27 | 28 | #ifndef TEST_PARAM_CONFIG_H 29 | #define TEST_PARAM_CONFIG_H 30 | 31 | #include 32 | 33 | /* Configuration wrapper. */ 34 | #if GRI_QUALIFICATION_FORCE_GENERATE_NEW_KEY_PAIR 35 | #define QUALIFICATION_FORCE_GENERATE_NEW_KEY_PAIR_SETTING ( 1 ) 36 | #else 37 | #define QUALIFICATION_FORCE_GENERATE_NEW_KEY_PAIR_SETTING ( 0 ) 38 | #endif /* GRI_QUALIFICATION_FORCE_GENERATE_NEW_KEY_PAIR */ 39 | 40 | #if GRI_QUALIFICATION_OTA_PAL_USE_FILE_SYSTEM 41 | #define QUALIFICATION_OTA_PAL_USE_FILE_SYSTEM_SETTING ( 1 ) 42 | #else 43 | #define QUALIFICATION_OTA_PAL_USE_FILE_SYSTEM_SETTING ( 0 ) 44 | #endif /* GRI_QUALIFICATION_OTA_PAL_USE_FILE_SYSTEM */ 45 | /* Configuration wrapper. */ 46 | 47 | /** 48 | * @brief Configuration that indicates if the device should generate a key pair. 49 | * 50 | * @note When FORCE_GENERATE_NEW_KEY_PAIR is set to 1, the device should generate 51 | * a new on-device key pair and output public key. When set to 0, the device 52 | * should keep existing key pair. 53 | * 54 | * #define FORCE_GENERATE_NEW_KEY_PAIR 0 55 | */ 56 | #define FORCE_GENERATE_NEW_KEY_PAIR QUALIFICATION_FORCE_GENERATE_NEW_KEY_PAIR_SETTING 57 | 58 | 59 | /** 60 | * @brief Endpoint of the MQTT broker to connect to in mqtt test. 61 | * 62 | * #define MQTT_SERVER_ENDPOINT "PLACE_HOLDER" 63 | */ 64 | #define MQTT_SERVER_ENDPOINT CONFIG_GRI_QUALIFICATION_MQTT_ENDPOINT 65 | 66 | 67 | /** 68 | * @brief Port of the MQTT broker to connect to in mqtt test. 69 | * 70 | * #define MQTT_SERVER_PORT (8883) 71 | */ 72 | #define MQTT_SERVER_PORT CONFIG_GRI_QUALIFICATION_MQTT_PORT 73 | 74 | /** 75 | * @brief The client identifier for MQTT test. 76 | * 77 | * #define MQTT_TEST_CLIENT_IDENTIFIER "PLACE_HOLDER" 78 | */ 79 | #define MQTT_TEST_CLIENT_IDENTIFIER CONFIG_GRI_QUALIFICATION_CLIENT_IDENTIFIER 80 | 81 | /** 82 | * @brief Timeout for MQTT_ProcessLoop() function in milliseconds. 83 | * The timeout value is appropriately chosen for receiving an incoming 84 | * PUBLISH message and ack responses for QoS 1 and QoS 2 communications 85 | * with the broker. 86 | * 87 | * #define MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ( 700 ) 88 | */ 89 | #define MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS CONFIG_GRI_QUALIFICATION_PROCESS_LOOP_TIMEOUT_MS 90 | 91 | /** 92 | * @brief Network buffer size specified in bytes. Must be large enough to hold the maximum 93 | * anticipated MQTT payload. 94 | * 95 | * #define MQTT_TEST_NETWORK_BUFFER_SIZE ( 5000 ) 96 | */ 97 | #define MQTT_TEST_NETWORK_BUFFER_SIZE ( CONFIG_GRI_QUALIFICATION_NETWORK_BUFFER_SIZE ) 98 | 99 | /** 100 | * @brief Endpoint of the echo server to connect to in transport interface test. 101 | * 102 | * #define ECHO_SERVER_ENDPOINT "PLACE_HOLDER" 103 | */ 104 | #define ECHO_SERVER_ENDPOINT CONFIG_GRI_QUALIFICATION_ECHO_SERVER 105 | 106 | /** 107 | * @brief Port of the echo server to connect to in transport interface test. 108 | * 109 | * #define ECHO_SERVER_PORT (9000) 110 | */ 111 | #define ECHO_SERVER_PORT CONFIG_GRI_QUALIFICATION_ECHO_SERVER_PORT 112 | 113 | /** 114 | * @brief Root certificate of the echo server. 115 | * 116 | * @note This certificate should be PEM-encoded. 117 | * 118 | * Must include the PEM header and footer: 119 | * "-----BEGIN CERTIFICATE-----\n"\ 120 | * "...base64 data...\n"\ 121 | * "-----END CERTIFICATE-----\n" 122 | * 123 | * #define ECHO_SERVER_ROOT_CA "PLACE_HOLDER" 124 | */ 125 | 126 | 127 | /** 128 | * @brief Client certificate to connect to echo server. 129 | * 130 | * @note This certificate should be PEM-encoded. 131 | * 132 | * Must include the PEM header and footer: 133 | * "-----BEGIN CERTIFICATE-----\n"\ 134 | * "...base64 data...\n"\ 135 | * "-----END CERTIFICATE-----\n" 136 | * 137 | * #define TRANSPORT_CLIENT_CERTIFICATE NULL 138 | */ 139 | 140 | 141 | /** 142 | * @brief Client private key to connect to echo server. 143 | * 144 | * @note This is should only be used for testing purpose. 145 | * 146 | * For qualification, the key should be generated on-device. 147 | * 148 | * #define TRANSPORT_CLIENT_PRIVATE_KEY NULL 149 | */ 150 | 151 | 152 | #define PKCS11_TEST_RSA_KEY_SUPPORT ( 1 ) 153 | #define PKCS11_TEST_EC_KEY_SUPPORT ( 0 ) 154 | #define PKCS11_TEST_IMPORT_PRIVATE_KEY_SUPPORT ( 1 ) 155 | #define PKCS11_TEST_GENERATE_KEYPAIR_SUPPORT ( 0 ) 156 | #define PKCS11_TEST_PREPROVISIONED_SUPPORT ( 0 ) 157 | #define PKCS11_TEST_LABEL_DEVICE_PRIVATE_KEY_FOR_TLS pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS 158 | #define PKCS11_TEST_LABEL_DEVICE_PUBLIC_KEY_FOR_TLS pkcs11configLABEL_DEVICE_PUBLIC_KEY_FOR_TLS 159 | #define PKCS11_TEST_LABEL_DEVICE_CERTIFICATE_FOR_TLS pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS 160 | 161 | /** 162 | * @brief The IoT Thing name for the device for OTA test. 163 | * 164 | * #define IOT_THING_NAME "PLACE_HOLDER" 165 | */ 166 | #define IOT_THING_NAME CONFIG_GRI_QUALIFICATION_THING_NAME 167 | 168 | /** 169 | * @brief Log macro for MQTT test. 170 | */ 171 | #ifndef LogDebug 172 | #define LogDebug( x ) 173 | #endif 174 | 175 | #ifndef LogInfo 176 | #define LogInfo( x ) 177 | #endif 178 | 179 | #ifndef LogWarn 180 | #define LogWarn( x ) 181 | #endif 182 | 183 | #ifndef LogError 184 | #define LogError( x ) 185 | #endif 186 | 187 | #define OUTGOING_PUBLISH_RECORD_COUNT ( 10 ) 188 | #define INCOMING_PUBLISH_RECORD_COUNT ( 10 ) 189 | 190 | #endif /* TEST_PARAM_CONFIG_H */ 191 | -------------------------------------------------------------------------------- /components/FreeRTOS-Libraries-Integration-Tests/port/platform_function.c: -------------------------------------------------------------------------------- 1 | #include "platform_function.h" 2 | 3 | #include 4 | #include 5 | #include "freertos/FreeRTOS.h" 6 | #include "freertos/FreeRTOSConfig.h" 7 | #include "freertos/task.h" 8 | #include "freertos/semphr.h" 9 | #include "esp_log.h" 10 | #include 11 | #include 12 | 13 | /* Random number generator include. */ 14 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL( 5, 0, 0 ) 15 | #include "esp_random.h" 16 | #else 17 | #include "esp_system.h" 18 | #endif 19 | 20 | 21 | #define TEST_RESULT_BUFFER_CAPACITY 2048 22 | 23 | static const char * TAG = "idt_platform_function"; 24 | 25 | typedef struct TaskParam 26 | { 27 | StaticSemaphore_t joinMutexBuffer; 28 | SemaphoreHandle_t joinMutexHandle; 29 | FRTestThreadFunction_t threadFunc; 30 | void * pParam; 31 | TaskHandle_t taskHandle; 32 | } TaskParam_t; 33 | 34 | extern uint32_t MqttTestGetTimeMs( void ); 35 | /*-----------------------------------------------------------*/ 36 | 37 | int FRTest_GenerateRandInt() 38 | { 39 | return ( int ) esp_random(); 40 | } 41 | 42 | /*-----------------------------------------------------------*/ 43 | 44 | static void ThreadWrapper( void * pParam ) 45 | { 46 | TaskParam_t * pTaskParam = pParam; 47 | 48 | if( ( pTaskParam != NULL ) && ( pTaskParam->threadFunc != NULL ) && ( pTaskParam->joinMutexHandle != NULL ) ) 49 | { 50 | pTaskParam->threadFunc( pTaskParam->pParam ); 51 | 52 | /* Give the mutex. */ 53 | xSemaphoreGive( pTaskParam->joinMutexHandle ); 54 | } 55 | 56 | vTaskDelete( NULL ); 57 | } 58 | /*-----------------------------------------------------------*/ 59 | 60 | FRTestThreadHandle_t FRTest_ThreadCreate( FRTestThreadFunction_t threadFunc, 61 | void * pParam ) 62 | { 63 | TaskParam_t * pTaskParam = NULL; 64 | FRTestThreadHandle_t threadHandle = NULL; 65 | BaseType_t xReturned; 66 | 67 | pTaskParam = malloc( sizeof( TaskParam_t ) ); 68 | configASSERT( pTaskParam != NULL ); 69 | 70 | pTaskParam->joinMutexHandle = xSemaphoreCreateBinaryStatic( &pTaskParam->joinMutexBuffer ); 71 | configASSERT( pTaskParam->joinMutexHandle != NULL ); 72 | 73 | pTaskParam->threadFunc = threadFunc; 74 | pTaskParam->pParam = pParam; 75 | 76 | xReturned = xTaskCreate( ThreadWrapper, /* Task code. */ 77 | "ThreadWrapper", /* All tasks have same name. */ 78 | 8192, /* Task stack size. */ 79 | pTaskParam, /* Where the task writes its result. */ 80 | tskIDLE_PRIORITY, /* Task priority. */ 81 | &pTaskParam->taskHandle ); 82 | configASSERT( xReturned == pdPASS ); 83 | 84 | threadHandle = pTaskParam; 85 | 86 | return threadHandle; 87 | } 88 | 89 | /*-----------------------------------------------------------*/ 90 | 91 | int FRTest_ThreadTimedJoin( FRTestThreadHandle_t threadHandle, 92 | uint32_t timeoutMs ) 93 | { 94 | TaskParam_t * pTaskParam = threadHandle; 95 | BaseType_t xReturned; 96 | int retValue = 0; 97 | 98 | /* Check the parameters. */ 99 | configASSERT( pTaskParam != NULL ); 100 | configASSERT( pTaskParam->joinMutexHandle != NULL ); 101 | 102 | /* Wait for the thread. */ 103 | xReturned = xSemaphoreTake( pTaskParam->joinMutexHandle, pdMS_TO_TICKS( timeoutMs ) ); 104 | 105 | if( xReturned != pdTRUE ) 106 | { 107 | ESP_LOGW( TAG, "Waiting thread exist failed after %" PRIu32 " %d. Task abort.", timeoutMs, xReturned ); 108 | 109 | /* Return negative value to indicate error. */ 110 | retValue = -1; 111 | 112 | /* There may be used after free. Assert here to indicate error. */ 113 | configASSERT( 0 ); 114 | } 115 | 116 | free( pTaskParam ); 117 | 118 | return retValue; 119 | } 120 | 121 | /*-----------------------------------------------------------*/ 122 | 123 | void FRTest_TimeDelay( uint32_t delayMs ) 124 | { 125 | vTaskDelay( pdMS_TO_TICKS( delayMs ) ); 126 | } 127 | 128 | /*-----------------------------------------------------------*/ 129 | 130 | void * FRTest_MemoryAlloc( size_t size ) 131 | { 132 | return pvPortMalloc( size ); 133 | } 134 | 135 | /*-----------------------------------------------------------*/ 136 | 137 | void FRTest_MemoryFree( void * ptr ) 138 | { 139 | return vPortFree( ptr ); 140 | } 141 | /*-----------------------------------------------------------*/ 142 | 143 | uint32_t FRTest_GetTimeMs( void ) 144 | { 145 | return MqttTestGetTimeMs(); 146 | } 147 | /*-----------------------------------------------------------*/ 148 | -------------------------------------------------------------------------------- /components/qrcode/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS ./src/qrcodegen.c ./src/qrcode.c 2 | INCLUDE_DIRS include 3 | REQUIRES 4 | PRIV_REQUIRES ) 5 | 6 | -------------------------------------------------------------------------------- /components/qrcode/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | COMPONENT_PRIV_INCLUDEDIRS := src 3 | COMPONENT_SRCDIRS := src 4 | -------------------------------------------------------------------------------- /components/qrcode/include/qrcode.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Espressif Systems (Shanghai) PTE LTD */ 2 | /* */ 3 | /* Licensed under the Apache License, Version 2.0 (the "License"); */ 4 | /* you may not use this file except in compliance with the License. */ 5 | /* You may obtain a copy of the License at */ 6 | /* */ 7 | /* http://www.apache.org/licenses/LICENSE-2.0 */ 8 | /* */ 9 | /* Unless required by applicable law or agreed to in writing, software */ 10 | /* distributed under the License is distributed on an "AS IS" BASIS, */ 11 | /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ 12 | /* See the License for the specific language governing permissions and */ 13 | /* limitations under the License. */ 14 | #pragma once 15 | 16 | #include 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * @brief Generate and display QR Code on the console 24 | * Encodes the given string into a QR Code & displays it on the console 25 | * 26 | * @attention 1. Can successfully encode a UTF-8 string of up to 2953 bytes or an alphanumeric 27 | * string of up to 4296 characters or any digit string of up to 7089 characters 28 | * 29 | * @param text string to encode into a QR Code. 30 | * 31 | * @return 32 | * - ESP_OK: succeed 33 | * - ESP_FAIL: Failed to encode string into a QR Code 34 | * - ESP_ERR_NO_MEM: Failed to allocate buffer for given MAX_QRCODE_VERSION 35 | */ 36 | esp_err_t qrcode_display( const char * text ); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /components/qrcode/src/qrcode.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Espressif Systems (Shanghai) PTE LTD */ 2 | /* */ 3 | /* Licensed under the Apache License, Version 2.0 (the "License"); */ 4 | /* you may not use this file except in compliance with the License. */ 5 | /* You may obtain a copy of the License at */ 6 | /* */ 7 | /* http://www.apache.org/licenses/LICENSE-2.0 */ 8 | /* */ 9 | /* Unless required by applicable law or agreed to in writing, software */ 10 | /* distributed under the License is distributed on an "AS IS" BASIS, */ 11 | /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ 12 | /* See the License for the specific language governing permissions and */ 13 | /* limitations under the License. */ 14 | 15 | #include 16 | #include 17 | 18 | #include "qrcodegen.h" 19 | 20 | #define MAX_QRCODE_VERSION 5 21 | 22 | static const char * lt[] = 23 | { 24 | /* 0 */ 25 | " ", 26 | /* 1 */ "\u2580 ", 27 | /* 2 */ " \u2580", 28 | /* 3 */ "\u2580\u2580", 29 | /* 4 */ "\u2584 ", 30 | /* 5 */ "\u2588 ", 31 | /* 6 */ "\u2584\u2580", 32 | /* 7 */ "\u2588\u2580", 33 | /* 8 */ " \u2584", 34 | /* 9 */ "\u2580\u2584", 35 | /* 10 */ " \u2588", 36 | /* 11 */ "\u2580\u2588", 37 | /* 12 */ "\u2584\u2584", 38 | /* 13 */ "\u2588\u2584", 39 | /* 14 */ "\u2584\u2588", 40 | /* 15 */ "\u2588\u2588", 41 | }; 42 | 43 | void print_qr_char( unsigned char n ) 44 | { 45 | printf( "%s", lt[ n ] ); 46 | } 47 | 48 | extern void print_qr_char( unsigned char ); 49 | static void printQr( const uint8_t qrcode[] ) 50 | { 51 | int size = qrcodegen_getSize( qrcode ); 52 | int border = 2; 53 | unsigned char num = 0; 54 | 55 | for( int y = -border; y < size + border; y += 2 ) 56 | { 57 | for( int x = -border; x < size + border; x += 2 ) 58 | { 59 | num = 0; 60 | 61 | if( qrcodegen_getModule( qrcode, x, y ) ) 62 | { 63 | num |= 1 << 0; 64 | } 65 | 66 | if( ( x < size + border ) && qrcodegen_getModule( qrcode, x + 1, y ) ) 67 | { 68 | num |= 1 << 1; 69 | } 70 | 71 | if( ( y < size + border ) && qrcodegen_getModule( qrcode, x, y + 1 ) ) 72 | { 73 | num |= 1 << 2; 74 | } 75 | 76 | if( ( x < size + border ) && ( y < size + border ) && qrcodegen_getModule( qrcode, x + 1, y + 1 ) ) 77 | { 78 | num |= 1 << 3; 79 | } 80 | 81 | print_qr_char( num ); 82 | } 83 | 84 | printf( "\n" ); 85 | } 86 | 87 | printf( "\n" ); 88 | } 89 | 90 | esp_err_t qrcode_display( const char * text ) 91 | { 92 | enum qrcodegen_Ecc errCorLvl = qrcodegen_Ecc_LOW; 93 | uint8_t * qrcode, * tempBuffer; 94 | esp_err_t err = ESP_FAIL; 95 | 96 | qrcode = calloc( 1, qrcodegen_BUFFER_LEN_FOR_VERSION( MAX_QRCODE_VERSION ) ); 97 | 98 | if( !qrcode ) 99 | { 100 | return ESP_ERR_NO_MEM; 101 | } 102 | 103 | tempBuffer = calloc( 1, qrcodegen_BUFFER_LEN_FOR_VERSION( MAX_QRCODE_VERSION ) ); 104 | 105 | if( !tempBuffer ) 106 | { 107 | free( qrcode ); 108 | return ESP_ERR_NO_MEM; 109 | } 110 | 111 | /* Make and print the QR Code symbol */ 112 | bool ok = qrcodegen_encodeText( text, tempBuffer, qrcode, errCorLvl, 113 | qrcodegen_VERSION_MIN, MAX_QRCODE_VERSION, qrcodegen_Mask_AUTO, true ); 114 | 115 | if( ok ) 116 | { 117 | printQr( qrcode ); 118 | err = ESP_OK; 119 | } 120 | 121 | free( qrcode ); 122 | free( tempBuffer ); 123 | return err; 124 | } 125 | -------------------------------------------------------------------------------- /components/qrcode/src/qrcodegen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * QR Code generator library (C) 3 | * 4 | * Copyright (c) Project Nayuki. (MIT License) 5 | * https://www.nayuki.io/page/qr-code-generator-library 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * - The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * - The Software is provided "as is", without warranty of any kind, express or 16 | * implied, including but not limited to the warranties of merchantability, 17 | * fitness for a particular purpose and noninfringement. In no event shall the 18 | * authors or copyright holders be liable for any claim, damages or other 19 | * liability, whether in an action of contract, tort or otherwise, arising from, 20 | * out of or in connection with the Software or the use or other dealings in the 21 | * Software. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | 36 | /* 37 | * This library creates QR Code symbols, which is a type of two-dimension barcode. 38 | * Invented by Denso Wave and described in the ISO/IEC 18004 standard. 39 | * A QR Code structure is an immutable square grid of black and white cells. 40 | * The library provides functions to create a QR Code from text or binary data. 41 | * The library covers the QR Code Model 2 specification, supporting all versions (sizes) 42 | * from 1 to 40, all 4 error correction levels, and 4 character encoding modes. 43 | * 44 | * Ways to create a QR Code object: 45 | * - High level: Take the payload data and call qrcodegen_encodeText() or qrcodegen_encodeBinary(). 46 | * - Low level: Custom-make the list of segments and call 47 | * qrcodegen_encodeSegments() or qrcodegen_encodeSegmentsAdvanced(). 48 | * (Note that all ways require supplying the desired error correction level and various byte buffers.) 49 | */ 50 | 51 | 52 | /*---- Enum and struct types----*/ 53 | 54 | /* 55 | * The error correction level in a QR Code symbol. 56 | */ 57 | enum qrcodegen_Ecc 58 | { 59 | /* Must be declared in ascending order of error protection */ 60 | /* so that an internal qrcodegen function works properly */ 61 | qrcodegen_Ecc_LOW = 0, /* The QR Code can tolerate about 7% erroneous codewords */ 62 | qrcodegen_Ecc_MEDIUM, /* The QR Code can tolerate about 15% erroneous codewords */ 63 | qrcodegen_Ecc_QUARTILE, /* The QR Code can tolerate about 25% erroneous codewords */ 64 | qrcodegen_Ecc_HIGH, /* The QR Code can tolerate about 30% erroneous codewords */ 65 | }; 66 | 67 | 68 | /* 69 | * The mask pattern used in a QR Code symbol. 70 | */ 71 | enum qrcodegen_Mask 72 | { 73 | /* A special value to tell the QR Code encoder to */ 74 | /* automatically select an appropriate mask pattern */ 75 | qrcodegen_Mask_AUTO = -1, 76 | /* The eight actual mask patterns */ 77 | qrcodegen_Mask_0 = 0, 78 | qrcodegen_Mask_1, 79 | qrcodegen_Mask_2, 80 | qrcodegen_Mask_3, 81 | qrcodegen_Mask_4, 82 | qrcodegen_Mask_5, 83 | qrcodegen_Mask_6, 84 | qrcodegen_Mask_7, 85 | }; 86 | 87 | 88 | /* 89 | * Describes how a segment's data bits are interpreted. 90 | */ 91 | enum qrcodegen_Mode 92 | { 93 | qrcodegen_Mode_NUMERIC = 0x1, 94 | qrcodegen_Mode_ALPHANUMERIC = 0x2, 95 | qrcodegen_Mode_BYTE = 0x4, 96 | qrcodegen_Mode_KANJI = 0x8, 97 | qrcodegen_Mode_ECI = 0x7, 98 | }; 99 | 100 | 101 | /* 102 | * A segment of character/binary/control data in a QR Code symbol. 103 | * The mid-level way to create a segment is to take the payload data 104 | * and call a factory function such as qrcodegen_makeNumeric(). 105 | * The low-level way to create a segment is to custom-make the bit buffer 106 | * and initialize a qrcodegen_Segment struct with appropriate values. 107 | * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. 108 | * Any segment longer than this is meaningless for the purpose of generating QR Codes. 109 | * Moreover, the maximum allowed bit length is 32767 because 110 | * the largest QR Code (version 40) has 31329 modules. 111 | */ 112 | struct qrcodegen_Segment 113 | { 114 | /* The mode indicator of this segment. */ 115 | enum qrcodegen_Mode mode; 116 | 117 | /* The length of this segment's unencoded data. Measured in characters for */ 118 | /* numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode. */ 119 | /* Always zero or positive. Not the same as the data's bit length. */ 120 | int numChars; 121 | 122 | /* The data bits of this segment, packed in bitwise big endian. */ 123 | /* Can be null if the bit length is zero. */ 124 | uint8_t * data; 125 | 126 | /* The number of valid data bits used in the buffer. Requires */ 127 | /* 0 <= bitLength <= 32767, and bitLength <= (capacity of data array) * 8. */ 128 | /* The character count (numChars) must agree with the mode and the bit buffer length. */ 129 | int bitLength; 130 | }; 131 | 132 | 133 | 134 | /*---- Macro constants and functions ----*/ 135 | 136 | #define qrcodegen_VERSION_MIN 1 /* The minimum version number supported in the QR Code Model 2 standard */ 137 | #define qrcodegen_VERSION_MAX 40 /* The maximum version number supported in the QR Code Model 2 standard */ 138 | 139 | /* Calculates the number of bytes needed to store any QR Code up to and including the given version number, */ 140 | /* as a compile-time constant. For example, 'uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(25)];' */ 141 | /* can store any single QR Code from version 1 to 25 (inclusive). The result fits in an int (or int16). */ 142 | /* Requires qrcodegen_VERSION_MIN <= n <= qrcodegen_VERSION_MAX. */ 143 | #define qrcodegen_BUFFER_LEN_FOR_VERSION( n ) ( ( ( ( n ) * 4 + 17 ) * ( ( n ) * 4 + 17 ) + 7 ) / 8 + 1 ) 144 | 145 | /* The worst-case number of bytes needed to store one QR Code, up to and including */ 146 | /* version 40. This value equals 3918, which is just under 4 kilobytes. */ 147 | /* Use this more convenient value to avoid calculating tighter memory bounds for buffers. */ 148 | #define qrcodegen_BUFFER_LEN_MAX qrcodegen_BUFFER_LEN_FOR_VERSION( qrcodegen_VERSION_MAX ) 149 | 150 | 151 | 152 | /*---- Functions (high level) to generate QR Codes ----*/ 153 | 154 | /* 155 | * Encodes the given text string to a QR Code, returning true if encoding succeeded. 156 | * If the data is too long to fit in any version in the given range 157 | * at the given ECC level, then false is returned. 158 | * - The input text must be encoded in UTF-8 and contain no NULs. 159 | * - The variables ecl and mask must correspond to enum constant values. 160 | * - Requires 1 <= minVersion <= maxVersion <= 40. 161 | * - The arrays tempBuffer and qrcode must each have a length 162 | * of at least qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion). 163 | * - After the function returns, tempBuffer contains no useful data. 164 | * - If successful, the resulting QR Code may use numeric, 165 | * alphanumeric, or byte mode to encode the text. 166 | * - In the most optimistic case, a QR Code at version 40 with low ECC 167 | * can hold any UTF-8 string up to 2953 bytes, or any alphanumeric string 168 | * up to 4296 characters, or any digit string up to 7089 characters. 169 | * These numbers represent the hard upper limit of the QR Code standard. 170 | * - Please consult the QR Code specification for information on 171 | * data capacities per version, ECC level, and text encoding mode. 172 | */ 173 | bool qrcodegen_encodeText( const char * text, 174 | uint8_t tempBuffer[], 175 | uint8_t qrcode[], 176 | enum qrcodegen_Ecc ecl, 177 | int minVersion, 178 | int maxVersion, 179 | enum qrcodegen_Mask mask, 180 | bool boostEcl ); 181 | 182 | 183 | /* 184 | * Encodes the given binary data to a QR Code, returning true if encoding succeeded. 185 | * If the data is too long to fit in any version in the given range 186 | * at the given ECC level, then false is returned. 187 | * - The input array range dataAndTemp[0 : dataLen] should normally be 188 | * valid UTF-8 text, but is not required by the QR Code standard. 189 | * - The variables ecl and mask must correspond to enum constant values. 190 | * - Requires 1 <= minVersion <= maxVersion <= 40. 191 | * - The arrays dataAndTemp and qrcode must each have a length 192 | * of at least qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion). 193 | * - After the function returns, the contents of dataAndTemp may have changed, 194 | * and does not represent useful data anymore. 195 | * - If successful, the resulting QR Code will use byte mode to encode the data. 196 | * - In the most optimistic case, a QR Code at version 40 with low ECC can hold any byte 197 | * sequence up to length 2953. This is the hard upper limit of the QR Code standard. 198 | * - Please consult the QR Code specification for information on 199 | * data capacities per version, ECC level, and text encoding mode. 200 | */ 201 | bool qrcodegen_encodeBinary( uint8_t dataAndTemp[], 202 | size_t dataLen, 203 | uint8_t qrcode[], 204 | enum qrcodegen_Ecc ecl, 205 | int minVersion, 206 | int maxVersion, 207 | enum qrcodegen_Mask mask, 208 | bool boostEcl ); 209 | 210 | 211 | /*---- Functions (low level) to generate QR Codes ----*/ 212 | 213 | /* 214 | * Renders a QR Code representing the given segments at the given error correction level. 215 | * The smallest possible QR Code version is automatically chosen for the output. Returns true if 216 | * QR Code creation succeeded, or false if the data is too long to fit in any version. The ECC level 217 | * of the result may be higher than the ecl argument if it can be done without increasing the version. 218 | * This function allows the user to create a custom sequence of segments that switches 219 | * between modes (such as alphanumeric and byte) to encode text in less space. 220 | * This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary(). 221 | * To save memory, the segments' data buffers can alias/overlap tempBuffer, and will 222 | * result in them being clobbered, but the QR Code output will still be correct. 223 | * But the qrcode array must not overlap tempBuffer or any segment's data buffer. 224 | */ 225 | bool qrcodegen_encodeSegments( const struct qrcodegen_Segment segs[], 226 | size_t len, 227 | enum qrcodegen_Ecc ecl, 228 | uint8_t tempBuffer[], 229 | uint8_t qrcode[] ); 230 | 231 | 232 | /* 233 | * Renders a QR Code representing the given segments with the given encoding parameters. 234 | * Returns true if QR Code creation succeeded, or false if the data is too long to fit in the range of versions. 235 | * The smallest possible QR Code version within the given range is automatically 236 | * chosen for the output. Iff boostEcl is true, then the ECC level of the result 237 | * may be higher than the ecl argument if it can be done without increasing the 238 | * version. The mask is either between qrcodegen_Mask_0 to 7 to force that mask, or 239 | * qrcodegen_Mask_AUTO to automatically choose an appropriate mask (which may be slow). 240 | * This function allows the user to create a custom sequence of segments that switches 241 | * between modes (such as alphanumeric and byte) to encode text in less space. 242 | * This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary(). 243 | * To save memory, the segments' data buffers can alias/overlap tempBuffer, and will 244 | * result in them being clobbered, but the QR Code output will still be correct. 245 | * But the qrcode array must not overlap tempBuffer or any segment's data buffer. 246 | */ 247 | bool qrcodegen_encodeSegmentsAdvanced( const struct qrcodegen_Segment segs[], 248 | size_t len, 249 | enum qrcodegen_Ecc ecl, 250 | int minVersion, 251 | int maxVersion, 252 | enum qrcodegen_Mask mask, 253 | bool boostEcl, 254 | uint8_t tempBuffer[], 255 | uint8_t qrcode[] ); 256 | 257 | 258 | /* 259 | * Tests whether the given string can be encoded as a segment in alphanumeric mode. 260 | * A string is encodable iff each character is in the following set: 0 to 9, A to Z 261 | * (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. 262 | */ 263 | bool qrcodegen_isAlphanumeric( const char * text ); 264 | 265 | 266 | /* 267 | * Tests whether the given string can be encoded as a segment in numeric mode. 268 | * A string is encodable iff each character is in the range 0 to 9. 269 | */ 270 | bool qrcodegen_isNumeric( const char * text ); 271 | 272 | 273 | /* 274 | * Returns the number of bytes (uint8_t) needed for the data buffer of a segment 275 | * containing the given number of characters using the given mode. Notes: 276 | * - Returns SIZE_MAX on failure, i.e. numChars > INT16_MAX or 277 | * the number of needed bits exceeds INT16_MAX (i.e. 32767). 278 | * - Otherwise, all valid results are in the range [0, ceil(INT16_MAX / 8)], i.e. at most 4096. 279 | * - It is okay for the user to allocate more bytes for the buffer than needed. 280 | * - For byte mode, numChars measures the number of bytes, not Unicode code points. 281 | * - For ECI mode, numChars must be 0, and the worst-case number of bytes is returned. 282 | * An actual ECI segment can have shorter data. For non-ECI modes, the result is exact. 283 | */ 284 | size_t qrcodegen_calcSegmentBufferSize( enum qrcodegen_Mode mode, 285 | size_t numChars ); 286 | 287 | 288 | /* 289 | * Returns a segment representing the given binary data encoded in 290 | * byte mode. All input byte arrays are acceptable. Any text string 291 | * can be converted to UTF-8 bytes and encoded as a byte mode segment. 292 | */ 293 | struct qrcodegen_Segment qrcodegen_makeBytes( const uint8_t data[], 294 | size_t len, 295 | uint8_t buf[] ); 296 | 297 | 298 | /* 299 | * Returns a segment representing the given string of decimal digits encoded in numeric mode. 300 | */ 301 | struct qrcodegen_Segment qrcodegen_makeNumeric( const char * digits, 302 | uint8_t buf[] ); 303 | 304 | 305 | /* 306 | * Returns a segment representing the given text string encoded in alphanumeric mode. 307 | * The characters allowed are: 0 to 9, A to Z (uppercase only), space, 308 | * dollar, percent, asterisk, plus, hyphen, period, slash, colon. 309 | */ 310 | struct qrcodegen_Segment qrcodegen_makeAlphanumeric( const char * text, 311 | uint8_t buf[] ); 312 | 313 | 314 | /* 315 | * Returns a segment representing an Extended Channel Interpretation 316 | * (ECI) designator with the given assignment value. 317 | */ 318 | struct qrcodegen_Segment qrcodegen_makeEci( long assignVal, 319 | uint8_t buf[] ); 320 | 321 | 322 | /*---- Functions to extract raw data from QR Codes ----*/ 323 | 324 | /* 325 | * Returns the side length of the given QR Code, assuming that encoding succeeded. 326 | * The result is in the range [21, 177]. Note that the length of the array buffer 327 | * is related to the side length - every 'uint8_t qrcode[]' must have length at least 328 | * qrcodegen_BUFFER_LEN_FOR_VERSION(version), which equals ceil(size^2 / 8 + 1). 329 | */ 330 | int qrcodegen_getSize( const uint8_t qrcode[] ); 331 | 332 | 333 | /* 334 | * Returns the color of the module (pixel) at the given coordinates, which is false 335 | * for white or true for black. The top left corner has the coordinates (x=0, y=0). 336 | * If the given coordinates are out of bounds, then false (white) is returned. 337 | */ 338 | bool qrcodegen_getModule( const uint8_t qrcode[], 339 | int x, 340 | int y ); 341 | 342 | 343 | #ifdef __cplusplus 344 | } 345 | #endif 346 | -------------------------------------------------------------------------------- /cspell.config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | $schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json 3 | version: '0.2' 4 | # Allows things like stringLength 5 | allowCompoundWords: true 6 | 7 | # Read files not to spell check from the git ignore 8 | useGitignore: true 9 | 10 | # Language settings for C 11 | languageSettings: 12 | - caseSensitive: false 13 | enabled: true 14 | languageId: c 15 | locale: "*" 16 | 17 | # Add a dictionary, and the path to the word list 18 | dictionaryDefinitions: 19 | - name: freertos-words 20 | path: '.github/.cSpellWords.txt' 21 | addWords: true 22 | 23 | dictionaries: 24 | - freertos-words 25 | 26 | # Paths and files to ignore 27 | ignorePaths: 28 | - 'dependency' 29 | - 'docs' 30 | - 'ThirdParty' 31 | - 'History.txt' 32 | -------------------------------------------------------------------------------- /main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(MAIN_SRCS 2 | "main.c" 3 | "networking/wifi/app_wifi.c" 4 | "networking/mqtt/subscription_manager.c" 5 | "networking/mqtt/core_mqtt_agent_manager.c" 6 | "networking/mqtt/core_mqtt_agent_manager_events.c" 7 | ) 8 | 9 | # Demo enables 10 | 11 | # Sub Pub Unsub demo 12 | if(CONFIG_GRI_ENABLE_SUB_PUB_UNSUB_DEMO) 13 | list(APPEND MAIN_SRCS "demo_tasks/sub_pub_unsub_demo/sub_pub_unsub_demo.c") 14 | endif() 15 | 16 | # Temperature Sub Pub and LED control demo 17 | if(CONFIG_GRI_ENABLE_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO) 18 | list(APPEND MAIN_SRCS 19 | "demo_tasks/temp_sub_pub_and_led_control_demo/temp_sub_pub_and_led_control_demo.c" 20 | "demo_tasks/temp_sub_pub_and_led_control_demo/hardware_drivers/app_driver.c" 21 | ) 22 | endif() 23 | 24 | # OTA demo 25 | if(CONFIG_GRI_ENABLE_OTA_DEMO) 26 | list(APPEND MAIN_SRCS "demo_tasks/ota_over_mqtt_demo/ota_over_mqtt_demo.c") 27 | endif() 28 | 29 | # Qualification Test 30 | if( CONFIG_GRI_RUN_QUALIFICATION_TEST ) 31 | list(APPEND MAIN_SRCS 32 | "qualification_app_main.c" 33 | "demo_tasks/sub_pub_unsub_demo/sub_pub_unsub_demo.c") 34 | endif() 35 | 36 | set(MAIN_INCLUDE_DIRS 37 | "." 38 | "demo_tasks/ota_over_mqtt_demo" 39 | "demo_tasks/sub_pub_unsub_demo" 40 | "demo_tasks/temp_sub_pub_and_led_control_demo" 41 | "demo_tasks/temp_sub_pub_and_led_control_demo/hardware_drivers" 42 | "networking/wifi" 43 | "networking/mqtt" 44 | ) 45 | 46 | set(MAIN_REQUIRES 47 | qrcode 48 | wifi_provisioning 49 | coreMQTT 50 | coreMQTT-Agent 51 | corePKCS11 52 | coreJSON 53 | backoffAlgorithm 54 | esp_secure_cert_mgr 55 | aws-iot-core-mqtt-file-streams-embedded-c 56 | FreeRTOS-Libraries-Integration-Tests 57 | unity 58 | driver 59 | ) 60 | 61 | idf_component_register( 62 | SRCS 63 | ${MAIN_SRCS} 64 | INCLUDE_DIRS 65 | ${MAIN_INCLUDE_DIRS} 66 | REQUIRES 67 | ${MAIN_REQUIRES} 68 | ) 69 | 70 | # OTA demo 71 | if( CONFIG_GRI_ENABLE_OTA_DEMO OR CONFIG_GRI_RUN_QUALIFICATION_TEST ) 72 | target_add_binary_data(${COMPONENT_TARGET} "certs/aws_codesign.crt" TEXT) 73 | endif() 74 | 75 | # Root Certificate 76 | target_add_binary_data(${COMPONENT_TARGET} "certs/root_cert_auth.crt" TEXT) 77 | -------------------------------------------------------------------------------- /main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Featured FreeRTOS IoT Integration" 2 | config APP_WIFI_PROV_SHOW_QR 3 | bool "Show provisioning QR code" 4 | default y 5 | help 6 | Show the QR code for provisioning. 7 | 8 | choice APP_WIFI_PROV_TRANSPORT 9 | bool "Provisioning Transport method" 10 | default APP_WIFI_PROV_TRANSPORT_BLE 11 | help 12 | Wi-Fi provisioning component offers both, SoftAP and BLE transports. Choose any one. 13 | config APP_WIFI_PROV_TRANSPORT_SOFTAP 14 | bool "Soft AP" 15 | config APP_WIFI_PROV_TRANSPORT_BLE 16 | bool "BLE" 17 | select BT_ENABLED 18 | endchoice 19 | 20 | config APP_WIFI_PROV_TRANSPORT 21 | int 22 | default 1 if APP_WIFI_PROV_TRANSPORT_SOFTAP 23 | default 2 if APP_WIFI_PROV_TRANSPORT_BLE 24 | 25 | config GRI_RUN_QUALIFICATION_TEST 26 | bool "Run qualification test." 27 | default n 28 | help 29 | Enable to run qualification test. Use configurations in test_execution_config.h and test_param_config.h. 30 | Disable to demo. Use configurations below (in sdkconfig). 31 | 32 | menu "Qualification Test Configurations" 33 | 34 | menu "Qualification Execution Test Configurations" 35 | config GRI_DEVICE_ADVISOR_TEST_ENABLED 36 | bool "Device Advisor Test." 37 | default n 38 | 39 | config GRI_MQTT_TEST_ENABLED 40 | bool "MQTT Test." 41 | default n 42 | 43 | config GRI_TRANSPORT_INTERFACE_TEST_ENABLED 44 | bool "Transport Interface Test." 45 | default n 46 | 47 | config GRI_CORE_PKCS11_TEST_ENABLED 48 | bool "CorePKCS#11 Test." 49 | default n 50 | 51 | endmenu # "Qualification Execution Test Configurations" 52 | 53 | menu "Qualification Parameter Configurations" 54 | config GRI_QUALIFICATION_FORCE_GENERATE_NEW_KEY_PAIR 55 | bool "Generate a key pair." 56 | default n 57 | 58 | config GRI_QUALIFICATION_MQTT_ENDPOINT 59 | string "Endpoint for MQTT Broker to use" 60 | default "PLACE_HOLDER" 61 | help 62 | MQTT Broker for Device Advisor Test/MQTT Test/OTA end-to-end Test. 63 | 64 | config GRI_QUALIFICATION_MQTT_PORT 65 | int "Port for MQTT Broker to use" 66 | default 8883 67 | 68 | config GRI_QUALIFICATION_CLIENT_IDENTIFIER 69 | string "Client Identifier for MQTT Test" 70 | default "PLACE_HOLDER" 71 | 72 | config GRI_QUALIFICATION_NETWORK_BUFFER_SIZE 73 | int "Network Buffer Size for MQTT Test" 74 | default 5000 75 | 76 | config GRI_QUALIFICATION_PROCESS_LOOP_TIMEOUT_MS 77 | int "Timeout to run MQTT process loop for MQTT Test" 78 | default 700 79 | 80 | config GRI_QUALIFICATION_ECHO_SERVER 81 | string "Echo Server Domain Name/IP for Transport Interface Test" 82 | default "PLACE_HOLDER" 83 | help 84 | Domain Name or IP address for Transport Interface Test. 85 | 86 | config GRI_QUALIFICATION_ECHO_SERVER_PORT 87 | int "Port for Echo Server to use" 88 | default 9000 89 | 90 | config GRI_QUALIFICATION_THING_NAME 91 | string "Thing Name for Device Advisor Test/OTA end-to-end Test" 92 | default "PLACE_HOLDER" 93 | 94 | endmenu # "Qualification Parameter Configurations" 95 | 96 | menu "Sub pub unsub demo configurations" 97 | config GRI_SUB_PUB_UNSUB_DEMO_STRING_BUFFER_LENGTH 98 | int "Topic name and payload buffer length" 99 | default 100 100 | help 101 | Size of statically allocated buffers for holding topic names and payloads. 102 | 103 | config GRI_SUB_PUB_UNSUB_DEMO_DELAY_BETWEEN_SUB_PUB_UNSUB_LOOPS_MS 104 | int "Delay between sub pub unsub loops in milliseconds" 105 | default 5000 106 | help 107 | Delay for each task between subscription, publish, unsubscription loops. 108 | 109 | config GRI_SUB_PUB_UNSUB_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS 110 | int "coreMQTT-Agent command post block time in milliseconds." 111 | default 500 112 | help 113 | 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. 114 | 115 | config GRI_SUB_PUB_UNSUB_DEMO_QOS_LEVEL 116 | int "QoS level of MQTT operations" 117 | default 1 118 | range 0 2 119 | help 120 | 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. 121 | 122 | config GRI_SUB_PUB_UNSUB_DEMO_NUM_TASKS_TO_CREATE 123 | int "Number of SubPubUnsub tasks to create" 124 | default 1 125 | help 126 | The number of SubPubUnsub tasks to create for this demo. 127 | 128 | config GRI_SUB_PUB_UNSUB_DEMO_TASK_PRIORITY 129 | int "SubPubUnsub task priority." 130 | default 1 131 | help 132 | The task priority of each of the SubPubUnsub tasks. 133 | 134 | config GRI_SUB_PUB_UNSUB_DEMO_TASK_STACK_SIZE 135 | int "SubPubUnsub task stack size." 136 | default 3072 137 | help 138 | The task stack size for each of the SubPubUnsub tasks. 139 | 140 | endmenu # Sub pub unsub demo configurations 141 | 142 | menu "OTA demo configurations" 143 | config GRI_OTA_DEMO_MAX_FILE_PATH_SIZE 144 | int "Max file path size." 145 | default 260 146 | help 147 | The maximum size of the file paths used in the demo. 148 | 149 | config GRI_OTA_DEMO_MAX_STREAM_NAME_SIZE 150 | int "Max stream name size." 151 | default 128 152 | help 153 | The maximum size of the stream name required for downloading update file from streaming service. 154 | 155 | config GRI_OTA_DEMO_TASK_DELAY_MS 156 | int "OTA statistic output delay milliseconds." 157 | default 1000 158 | help 159 | The delay used in the OTA demo task to periodically output the OTA statistics like number of packets received, dropped, processed and queued per connection. 160 | 161 | config GRI_OTA_DEMO_MQTT_TIMEOUT_MS 162 | int "MQTT operation timeout milliseconds." 163 | default 5000 164 | help 165 | The maximum time for which OTA demo waits for an MQTT operation to be complete. This involves receiving an acknowledgment for broker for SUBSCRIBE, UNSUBSCRIBE and non QOS0 publishes. 166 | 167 | config GRI_OTA_DEMO_AGENT_TASK_PRIORITY 168 | int "OTA agent task priority." 169 | default 4 170 | 171 | config GRI_OTA_DEMO_AGENT_TASK_STACK_SIZE 172 | int "OTA agent task stack size." 173 | default 4096 174 | 175 | config GRI_OTA_DEMO_DEMO_TASK_PRIORITY 176 | int "OTA demo task priority." 177 | default 1 178 | 179 | config GRI_OTA_DEMO_DEMO_TASK_STACK_SIZE 180 | int "OTA demo task stack size." 181 | default 3072 182 | 183 | config GRI_OTA_MAX_NUM_DATA_BUFFERS 184 | int "OTA buffer number." 185 | default 2 186 | 187 | endmenu # OTA demo configurations 188 | endmenu # Qualification Test Configurations 189 | 190 | config GRI_MQTT_ENDPOINT 191 | string "Endpoint for MQTT Broker to use" 192 | depends on !GRI_RUN_QUALIFICATION_TEST 193 | default "" 194 | 195 | config GRI_MQTT_PORT 196 | int "Port for MQTT Broker to use" 197 | depends on !GRI_RUN_QUALIFICATION_TEST 198 | default 8883 199 | 200 | config GRI_THING_NAME 201 | string "Thing name" 202 | depends on !GRI_RUN_QUALIFICATION_TEST 203 | default "" 204 | 205 | config GRI_OUTPUT_CERTS_KEYS 206 | bool "Output provisioned certificates and keys." 207 | default y 208 | 209 | menu "coreMQTT-Agent Manager Configurations" 210 | 211 | config GRI_MQTT_AGENT_TASK_STACK_SIZE 212 | int "coreMQTT-Agent task stack size" 213 | default 4096 214 | 215 | config GRI_MQTT_AGENT_TASK_PRIORITY 216 | int "coreMQTT-Agent task priority" 217 | default 4 218 | 219 | config GRI_CONNECTION_TASK_STACK_SIZE 220 | int "Connection handling task stack size" 221 | default 3072 222 | 223 | config GRI_CONNECTION_TASK_PRIORITY 224 | int "Connection handling task priority" 225 | default 4 226 | 227 | config GRI_RETRY_MAX_BACKOFF_DELAY_MS 228 | int "Maximum backoff delay on connection retry in milliseconds" 229 | default 5000 230 | 231 | config GRI_RETRY_BACKOFF_BASE_MS 232 | int "Base back-off delay on connection retry in milliseconds" 233 | default 500 234 | 235 | config GRI_MQTT_AGENT_NETWORK_BUFFER_SIZE 236 | int "coreMQTT-Agent network buffer size" 237 | default 10000 238 | 239 | config GRI_MQTT_AGENT_COMMAND_QUEUE_LENGTH 240 | int "coreMQTT-Agent command queue length" 241 | default 10 242 | 243 | config GRI_MQTT_AGENT_KEEP_ALIVE_INTERVAL_SECONDS 244 | int "coreMQTT-Agent keep alive interval in seconds" 245 | default 60 246 | help 247 | The maximum time interval in seconds which is allowed to elapsed between two Control Packets. 248 | 249 | config GRI_MQTT_AGENT_CONNACK_RECV_TIMEOUT_MS 250 | int "Timeout for receiving CONNACK in milliseconds" 251 | default 1000 252 | 253 | 254 | endmenu # coreMQTT-Agent Manager Configurations 255 | 256 | config GRI_ENABLE_SUB_PUB_UNSUB_DEMO 257 | bool "Enable pub sub unsub demo" 258 | depends on !GRI_RUN_QUALIFICATION_TEST 259 | default y 260 | 261 | menu "Sub pub unsub demo configurations" 262 | depends on GRI_ENABLE_SUB_PUB_UNSUB_DEMO 263 | 264 | config GRI_SUB_PUB_UNSUB_DEMO_STRING_BUFFER_LENGTH 265 | int "Topic name and payload buffer length" 266 | default 100 267 | help 268 | Size of statically allocated buffers for holding topic names and payloads. 269 | 270 | config GRI_SUB_PUB_UNSUB_DEMO_DELAY_BETWEEN_SUB_PUB_UNSUB_LOOPS_MS 271 | int "Delay between sub pub unsub loops in milliseconds" 272 | default 5000 273 | help 274 | Delay for each task between subscription, publish, unsubscription loops. 275 | 276 | config GRI_SUB_PUB_UNSUB_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS 277 | int "coreMQTT-Agent command post block time in milliseconds." 278 | default 500 279 | help 280 | 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. 281 | 282 | config GRI_SUB_PUB_UNSUB_DEMO_QOS_LEVEL 283 | int "QoS level of MQTT operations" 284 | default 1 285 | range 0 2 286 | help 287 | 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. 288 | 289 | config GRI_SUB_PUB_UNSUB_DEMO_NUM_TASKS_TO_CREATE 290 | int "Number of SubPubUnsub tasks to create" 291 | default 1 292 | help 293 | The number of SubPubUnsub tasks to create for this demo. 294 | 295 | config GRI_SUB_PUB_UNSUB_DEMO_TASK_PRIORITY 296 | int "SubPubUnsub task priority." 297 | default 1 298 | help 299 | The task priority of each of the SubPubUnsub tasks. 300 | 301 | config GRI_SUB_PUB_UNSUB_DEMO_TASK_STACK_SIZE 302 | int "SubPubUnsub task stack size." 303 | default 3072 304 | help 305 | The task stack size for each of the SubPubUnsub tasks. 306 | 307 | endmenu # Sub pub unsub demo configurations 308 | 309 | config GRI_ENABLE_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO 310 | bool "Enable temperature sensor pub sub and LED control demo" 311 | depends on !GRI_RUN_QUALIFICATION_TEST 312 | default y 313 | 314 | menu "Temperature pub sub and LED control demo configurations" 315 | depends on GRI_ENABLE_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO 316 | 317 | choice GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_TYPE 318 | prompt "LED type" 319 | default GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_GPIO if IDF_TARGET_ESP32 || IDF_TARGET_ESP32C2 320 | default GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_RMT 321 | help 322 | Defines the default peripheral for the GRI 323 | 324 | config GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_GPIO 325 | bool "GPIO" 326 | config GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_RMT 327 | bool "RMT - Addressable LED" 328 | endchoice 329 | 330 | config GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_GPIO_NUMBER 331 | int "GRI GPIO number" 332 | default 8 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32H2 || IDF_TARGET_ESP32C2 333 | default 18 if IDF_TARGET_ESP32S2 334 | default 48 if IDF_TARGET_ESP32S3 335 | default 5 336 | help 337 | GPIO number (IOxx) to blink on and off or the RMT signal for the addressable LED. 338 | Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used for LED. 339 | 340 | config GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_STRING_BUFFER_LENGTH 341 | int "Topic name and payload buffer length" 342 | default 150 343 | help 344 | Size of statically allocated buffers for holding topic names and payloads. 345 | 346 | config GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_DELAY_BETWEEN_PUBLISH_OPERATIONS_MS 347 | int "Delay between publishes in milliseconds" 348 | default 3000 349 | help 350 | Delay for the synchronous publisher task between publishes. 351 | 352 | config GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS 353 | int "coreMQTT-Agent command post block time in milliseconds." 354 | default 500 355 | help 356 | 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. 357 | 358 | config GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_QOS_LEVEL 359 | int "QoS level of MQTT operations" 360 | default 1 361 | range 0 2 362 | help 363 | 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. 364 | 365 | config GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_TASK_PRIORITY 366 | int "Temperature sensor publishing task priority." 367 | default 1 368 | help 369 | The task priority of the temperature sensor publishing task. 370 | 371 | config GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_TASK_STACK_SIZE 372 | int "Temperature sensor publishing task stack size." 373 | default 3072 374 | help 375 | The task stack size of the temperature sensor publishing task. 376 | 377 | endmenu # Temperature pub sub and LED control demo configurations 378 | 379 | config GRI_ENABLE_OTA_DEMO 380 | bool "Enable OTA demo" 381 | depends on !GRI_RUN_QUALIFICATION_TEST 382 | default y 383 | 384 | menu "OTA demo configurations" 385 | depends on GRI_ENABLE_OTA_DEMO 386 | 387 | config GRI_OTA_DEMO_MAX_FILE_PATH_SIZE 388 | int "Max file path size." 389 | default 260 390 | help 391 | The maximum size of the file paths used in the demo. 392 | 393 | config GRI_OTA_DEMO_MAX_STREAM_NAME_SIZE 394 | int "Max stream name size." 395 | default 128 396 | help 397 | The maximum size of the stream name required for downloading update file from streaming service. 398 | 399 | config GRI_OTA_DEMO_TASK_DELAY_MS 400 | int "OTA statistic output delay milliseconds." 401 | default 1000 402 | help 403 | The delay used in the OTA demo task to periodically output the OTA statistics like number of packets received, dropped, processed and queued per connection. 404 | 405 | config GRI_OTA_DEMO_MQTT_TIMEOUT_MS 406 | int "MQTT operation timeout milliseconds." 407 | default 5000 408 | help 409 | The maximum time for which OTA demo waits for an MQTT operation to be complete. This involves receiving an acknowledgment for broker for SUBSCRIBE, UNSUBSCRIBE and non QOS0 publishes. 410 | 411 | config GRI_OTA_DEMO_AGENT_TASK_PRIORITY 412 | int "OTA agent task priority." 413 | default 4 414 | 415 | config GRI_OTA_DEMO_AGENT_TASK_STACK_SIZE 416 | int "OTA agent task stack size." 417 | default 4096 418 | 419 | config GRI_OTA_DEMO_DEMO_TASK_PRIORITY 420 | int "OTA demo task priority." 421 | default 1 422 | 423 | config GRI_OTA_DEMO_DEMO_TASK_STACK_SIZE 424 | int "OTA demo task stack size." 425 | default 3072 426 | 427 | config GRI_OTA_DEMO_APP_VERSION_MAJOR 428 | int "Application version major." 429 | default 0 430 | 431 | config GRI_OTA_DEMO_APP_VERSION_MINOR 432 | int "Application version minor." 433 | default 0 434 | 435 | config GRI_OTA_DEMO_APP_VERSION_BUILD 436 | int "Application version build." 437 | default 0 438 | 439 | config GRI_OTA_MAX_NUM_DATA_BUFFERS 440 | int "OTA buffer number." 441 | default 2 442 | 443 | endmenu # OTA demo configurations 444 | 445 | endmenu # Golden Reference Integration 446 | 447 | 448 | -------------------------------------------------------------------------------- /main/certs/aws_codesign.crt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FreeRTOS/iot-reference-esp32/d628228ea995b2c564adc9a0528ef659ac7e2363/main/certs/aws_codesign.crt -------------------------------------------------------------------------------- /main/certs/root_cert_auth.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF 3 | ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6 4 | b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL 5 | MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv 6 | b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj 7 | ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM 8 | 9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw 9 | IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6 10 | VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L 11 | 93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm 12 | jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC 13 | AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA 14 | A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI 15 | U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs 16 | N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv 17 | o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU 18 | 5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy 19 | rqXRfboQnoZsG4q5WTP468SQvvG5 20 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /main/demo_tasks/ota_over_mqtt_demo/ota_over_mqtt_demo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef OTA_OVER_MQTT_DEMO_H 28 | #define OTA_OVER_MQTT_DEMO_H 29 | 30 | #include "freertos/FreeRTOS.h" 31 | #include "core_mqtt_agent.h" 32 | #include "ota_config.h" 33 | 34 | /* *INDENT-OFF* */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | /* *INDENT-ON* */ 39 | 40 | /** 41 | * @brief Starts the OTA codesigning demo. 42 | */ 43 | void vStartOTACodeSigningDemo( void ); 44 | 45 | /** 46 | * @brief Default callback used to receive default messages for OTA. 47 | * 48 | * The callback is not subscribed with MQTT broker, but only with local subscription manager. 49 | * A wildcard OTA job topic is used for subscription so that all unsolicited messages related to OTA is 50 | * forwarded to this callback for filtration. Right now the callback is used to filter responses to job requests 51 | * from the OTA service. 52 | * 53 | * @param[in] pvIncomingPublishCallbackContext MQTT context which stores the connection. 54 | * @param[in] pPublishInfo MQTT packet that stores the information of the file block. 55 | * 56 | * @return true if the message is processed by OTA. 57 | */ 58 | bool vOTAProcessMessage( void * pvIncomingPublishCallbackContext, 59 | MQTTPublishInfo_t * pxPublishInfo ); 60 | 61 | /* *INDENT-OFF* */ 62 | #ifdef __cplusplus 63 | } /* extern "C" */ 64 | #endif 65 | /* *INDENT-ON* */ 66 | 67 | #endif /* OTA_OVER_MQTT_DEMO_H */ 68 | -------------------------------------------------------------------------------- /main/demo_tasks/ota_over_mqtt_demo/ota_over_mqtt_demo_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef OTA_OVER_MQTT_DEMO_CONFIG_H 28 | #define OTA_OVER_MQTT_DEMO_CONFIG_H 29 | 30 | /* ESP-IDF sdkconfig include. */ 31 | #include 32 | 33 | #if CONFIG_GRI_RUN_QUALIFICATION_TEST 34 | #include "qualification_wrapper_config.h" 35 | #endif /* CONFIG_GRI_RUN_QUALIFICATION_TEST */ 36 | 37 | /* *INDENT-OFF* */ 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | /* *INDENT-ON* */ 42 | 43 | /** 44 | * @brief The thing name of the device. 45 | */ 46 | #define otademoconfigCLIENT_IDENTIFIER ( CONFIG_GRI_THING_NAME ) 47 | 48 | /** 49 | * @brief The maximum size of the file paths used in the demo. 50 | */ 51 | #define otademoconfigMAX_FILE_PATH_SIZE ( CONFIG_GRI_OTA_DEMO_MAX_FILE_PATH_SIZE ) 52 | 53 | /** 54 | * @brief The maximum size of the stream name required for downloading update file 55 | * from streaming service. 56 | */ 57 | #define otademoconfigMAX_STREAM_NAME_SIZE ( CONFIG_GRI_OTA_DEMO_MAX_STREAM_NAME_SIZE ) 58 | 59 | /** 60 | * @brief The delay used in the OTA demo task to periodically output the OTA 61 | * statistics like number of packets received, dropped, processed and queued per connection. 62 | */ 63 | #define otademoconfigTASK_DELAY_MS ( CONFIG_GRI_OTA_DEMO_TASK_DELAY_MS ) 64 | 65 | /** 66 | * @brief The maximum time for which OTA demo waits for an MQTT operation to be complete. 67 | * This involves receiving an acknowledgment for broker for SUBSCRIBE, UNSUBSCRIBE and non 68 | * QOS0 publishes. 69 | */ 70 | #define otademoconfigMQTT_TIMEOUT_MS ( CONFIG_GRI_OTA_DEMO_MQTT_TIMEOUT_MS ) 71 | 72 | /** 73 | * @brief The task priority of OTA agent task. 74 | */ 75 | #define otademoconfigAGENT_TASK_PRIORITY ( CONFIG_GRI_OTA_DEMO_AGENT_TASK_PRIORITY ) 76 | 77 | /** 78 | * @brief The stack size of OTA agent task. 79 | */ 80 | #define otademoconfigAGENT_TASK_STACK_SIZE ( CONFIG_GRI_OTA_DEMO_AGENT_TASK_STACK_SIZE ) 81 | 82 | /** 83 | * @brief The task priority of the OTA demo task. 84 | */ 85 | #define otademoconfigDEMO_TASK_PRIORITY ( CONFIG_GRI_OTA_DEMO_DEMO_TASK_PRIORITY ) 86 | 87 | /** 88 | * @brief The task stack size of the OTA demo task. 89 | */ 90 | #define otademoconfigDEMO_TASK_STACK_SIZE ( CONFIG_GRI_OTA_DEMO_DEMO_TASK_STACK_SIZE ) 91 | 92 | /** 93 | * @brief The number of OTA data buffer. 94 | */ 95 | #define otademoconfigMAX_NUM_OTA_DATA_BUFFERS ( CONFIG_GRI_OTA_MAX_NUM_DATA_BUFFERS ) 96 | 97 | /** 98 | * @brief The version for the firmware which is running. OTA agent uses this 99 | * version number to perform anti-rollback validation. The firmware version for the 100 | * download image should be higher than the current version, otherwise the new image is 101 | * rejected in self test phase. 102 | */ 103 | #define APP_VERSION_MAJOR ( CONFIG_GRI_OTA_DEMO_APP_VERSION_MAJOR ) 104 | #define APP_VERSION_MINOR ( CONFIG_GRI_OTA_DEMO_APP_VERSION_MINOR ) 105 | #define APP_VERSION_BUILD ( CONFIG_GRI_OTA_DEMO_APP_VERSION_BUILD ) 106 | 107 | /* *INDENT-OFF* */ 108 | #ifdef __cplusplus 109 | } /* extern "C" */ 110 | #endif 111 | /* *INDENT-ON* */ 112 | 113 | #endif /* OTA_OVER_MQTT_DEMO_CONFIG_H */ 114 | -------------------------------------------------------------------------------- /main/demo_tasks/sub_pub_unsub_demo/sub_pub_unsub_demo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef SUB_PUB_UNSUB_DEMO_H 28 | #define SUB_PUB_UNSUB_DEMO_H 29 | 30 | /* *INDENT-OFF* */ 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | /* *INDENT-ON* */ 35 | 36 | /** 37 | * @brief This function starts the SubPubUnsub demo. 38 | */ 39 | void vStartSubscribePublishUnsubscribeDemo( void ); 40 | 41 | /* *INDENT-OFF* */ 42 | #ifdef __cplusplus 43 | } /* extern "C" */ 44 | #endif 45 | /* *INDENT-ON* */ 46 | 47 | #endif /* SUB_PUB_UNSUB_DEMO_H */ 48 | -------------------------------------------------------------------------------- /main/demo_tasks/sub_pub_unsub_demo/sub_pub_unsub_demo_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef SUB_PUB_UNSUB_DEMO_CONFIG_H 28 | #define SUB_PUB_UNSUB_DEMO_CONFIG_H 29 | 30 | /* ESP-IDF sdkconfig include. */ 31 | #include 32 | 33 | #if CONFIG_GRI_RUN_QUALIFICATION_TEST 34 | #include "qualification_wrapper_config.h" 35 | #endif /* CONFIG_GRI_RUN_QUALIFICATION_TEST */ 36 | 37 | /* *INDENT-OFF* */ 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | /* *INDENT-ON* */ 42 | 43 | /** 44 | * @brief Size of statically allocated buffers for holding topic names and 45 | * payloads. 46 | */ 47 | #define subpubunsubconfigSTRING_BUFFER_LENGTH ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_STRING_BUFFER_LENGTH ) ) 48 | 49 | /** 50 | * @brief Delay for each task between subscription, publish, unsubscription 51 | * loops. 52 | */ 53 | #define subpubunsubconfigDELAY_BETWEEN_SUB_PUB_UNSUB_LOOPS_MS ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_DELAY_BETWEEN_SUB_PUB_UNSUB_LOOPS_MS ) ) 54 | 55 | /** 56 | * @brief The maximum amount of time in milliseconds to wait for the commands 57 | * to be posted to the MQTT agent should the MQTT agent's command queue be full. 58 | * Tasks wait in the Blocked state, so don't use any CPU time. 59 | */ 60 | #define subpubunsubconfigMAX_COMMAND_SEND_BLOCK_TIME_MS ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS ) ) 61 | 62 | /** 63 | * @brief The QoS level of MQTT messages sent by this demo. This must be 0 or 1 64 | * if using AWS as AWS only supports levels 0 or 1. If using another MQTT broker 65 | * that supports QoS level 2, this can be set to 2. 66 | */ 67 | #define subpubunsubconfigQOS_LEVEL ( ( unsigned long ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_QOS_LEVEL ) ) 68 | 69 | /** 70 | * @brief The number of SubPubUnsub tasks to create for this demo. 71 | */ 72 | #define subpubunsubconfigNUM_TASKS_TO_CREATE ( ( unsigned long ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_NUM_TASKS_TO_CREATE ) ) 73 | 74 | /** 75 | * @brief The task priority of each of the SubPubUnsub tasks. 76 | */ 77 | #define subpubunsubconfigTASK_PRIORITY ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_TASK_PRIORITY ) ) 78 | 79 | /** 80 | * @brief The task stack size for each of the SubPubUnsub tasks. 81 | */ 82 | #define subpubunsubconfigTASK_STACK_SIZE ( ( unsigned int ) ( CONFIG_GRI_SUB_PUB_UNSUB_DEMO_TASK_STACK_SIZE ) ) 83 | 84 | /* *INDENT-OFF* */ 85 | #ifdef __cplusplus 86 | } /* extern "C" */ 87 | #endif 88 | /* *INDENT-ON* */ 89 | 90 | #endif /* SUB_PUB_UNSUB_DEMO_CONFIG_H */ 91 | -------------------------------------------------------------------------------- /main/demo_tasks/temp_sub_pub_and_led_control_demo/hardware_drivers/app_driver.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "esp_log.h" 4 | #include "freertos/FreeRTOS.h" 5 | #include "freertos/task.h" 6 | #include "app_driver.h" 7 | #include "esp_idf_version.h" 8 | 9 | #ifdef APP_SOC_TEMP_SENSOR_SUPPORTED 10 | static const char * TAG = "app_driver"; 11 | #endif 12 | 13 | #define GRI_LED_GPIO CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_GPIO_NUMBER 14 | 15 | #ifdef CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_RMT 16 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL( 5, 0, 0 ) 17 | static led_strip_handle_t led_strip; 18 | #else 19 | static led_strip_t * led_strip; 20 | #endif 21 | #endif 22 | 23 | #if ESP_IDF_VERSION == ESP_IDF_VERSION_VAL( 4, 3, 0 ) 24 | #ifndef CONFIG_IDF_TARGET_ESP32 25 | #define APP_SOC_TEMP_SENSOR_SUPPORTED 26 | #else 27 | #define APP_SOC_TEMP_SENSOR_SUPPORTED SOC_TEMP_SENSOR_SUPPORTED 28 | #endif 29 | #endif 30 | 31 | static esp_err_t temperature_sensor_init() 32 | { 33 | #ifdef APP_SOC_TEMP_SENSOR_SUPPORTED 34 | /* Initialize touch pad peripheral, it will start a timer to run a filter */ 35 | ESP_LOGI( TAG, "Initializing Temperature sensor" ); 36 | temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT(); 37 | temp_sensor_get_config( &temp_sensor ); 38 | ESP_LOGD( TAG, "default dac %d, clk_div %d", temp_sensor.dac_offset, temp_sensor.clk_div ); 39 | temp_sensor.dac_offset = TSENS_DAC_DEFAULT; /* DEFAULT: range:-10℃ ~ 80℃, error < 1℃. */ 40 | temp_sensor_set_config( temp_sensor ); 41 | return( temp_sensor_start() ); 42 | #else 43 | /* For the SoCs that do not have a temperature sensor (like ESP32) we report a dummy value. */ 44 | return ESP_OK; 45 | #endif /* ifdef APP_SOC_TEMP_SENSOR_SUPPORTED */ 46 | } 47 | 48 | static esp_err_t led_init() 49 | { 50 | esp_err_t ret = ESP_FAIL; 51 | 52 | #ifdef CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_RMT 53 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL( 5, 0, 0 ) 54 | led_strip_config_t strip_config = 55 | { 56 | .strip_gpio_num = GRI_LED_GPIO, 57 | .max_leds = 1, /* at least one LED on board */ 58 | }; 59 | led_strip_rmt_config_t rmt_config = 60 | { 61 | .resolution_hz = 10 * 1000 * 1000, /* 10MHz */ 62 | }; 63 | ret = led_strip_new_rmt_device( &strip_config, &rmt_config, &led_strip ); 64 | #else /* if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL( 5, 0, 0 ) */ 65 | led_strip = led_strip_init( 0, GRI_LED_GPIO, 1 ); 66 | #endif /* if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL( 5, 0, 0 ) */ 67 | #elif CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_GPIO 68 | ret = gpio_reset_pin( GRI_LED_GPIO ); 69 | ret |= gpio_set_direction( GRI_LED_GPIO, GPIO_MODE_OUTPUT ); 70 | #endif /* ifdef CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_RMT */ 71 | ret |= app_driver_led_on(); 72 | return ret; 73 | } 74 | 75 | esp_err_t app_driver_init() 76 | { 77 | esp_err_t temp_sensor_ret, led_ret; 78 | 79 | temp_sensor_ret = temperature_sensor_init(); 80 | led_ret = led_init(); 81 | 82 | if( temp_sensor_ret && led_ret ) 83 | { 84 | return ESP_OK; 85 | } 86 | else 87 | { 88 | return ESP_FAIL; 89 | } 90 | } 91 | 92 | esp_err_t app_driver_led_on() 93 | { 94 | esp_err_t ret = ESP_FAIL; 95 | 96 | #ifdef CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_RMT 97 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL( 5, 0, 0 ) 98 | ret = led_strip_set_pixel( led_strip, 0, 0, 25, 0 ); 99 | /* Refresh the strip to send data */ 100 | ret |= led_strip_refresh( led_strip ); 101 | #else 102 | led_strip->set_pixel( led_strip, 0, 0, 25, 0 ); 103 | led_strip->refresh( led_strip, 100 ); 104 | #endif 105 | #elif CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_GPIO 106 | ret = gpio_set_level( GRI_LED_GPIO, 1 ); 107 | #endif /* ifdef CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_RMT */ 108 | return ret; 109 | } 110 | 111 | esp_err_t app_driver_led_off() 112 | { 113 | esp_err_t ret = ESP_FAIL; 114 | 115 | #ifdef CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_RMT 116 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL( 5, 0, 0 ) 117 | ret = led_strip_clear( led_strip ); 118 | #else 119 | led_strip->clear( led_strip, 50 ); 120 | #endif 121 | #elif CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_LED_GPIO 122 | ret = gpio_set_level( GRI_LED_GPIO, 0 ); 123 | #endif 124 | return ret; 125 | } 126 | 127 | float app_driver_temp_sensor_read_celsius() 128 | { 129 | #ifdef APP_SOC_TEMP_SENSOR_SUPPORTED 130 | float tsens_out; 131 | temp_sensor_read_celsius( &tsens_out ); 132 | return tsens_out; 133 | #else 134 | /* For the SoCs that do not have a temperature sensor (like ESP32) we report a dummy value. */ 135 | return 0.0f; 136 | #endif 137 | } 138 | -------------------------------------------------------------------------------- /main/demo_tasks/temp_sub_pub_and_led_control_demo/hardware_drivers/app_driver.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-2022 Espressif Systems (Shanghai) PTE LTD */ 2 | /* */ 3 | /* Licensed under the Apache License, Version 2.0 (the "License"); */ 4 | /* you may not use this file except in compliance with the License. */ 5 | /* You may obtain a copy of the License at */ 6 | /* http://www.apache.org/licenses/LICENSE-2.0 */ 7 | /* */ 8 | /* Unless required by applicable law or agreed to in writing, software */ 9 | /* distributed under the License is distributed on an "AS IS" BASIS, */ 10 | /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ 11 | /* See the License for the specific language governing permissions and */ 12 | /* limitations under the License. */ 13 | 14 | #ifndef APP_DRIVER_H_ 15 | #define APP_DRIVER_H_ 16 | 17 | /* *INDENT-OFF* */ 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | /* *INDENT-ON* */ 22 | 23 | #include "driver/temperature_sensor.h" 24 | #include "driver/gpio.h" 25 | #include "led_strip.h" 26 | 27 | esp_err_t app_driver_init(); 28 | 29 | float app_driver_temp_sensor_read_celsius(); 30 | 31 | esp_err_t app_driver_led_on(); 32 | 33 | esp_err_t app_driver_led_off(); 34 | 35 | /* *INDENT-OFF* */ 36 | #ifdef __cplusplus 37 | } /* extern "C" */ 38 | #endif 39 | /* *INDENT-ON* */ 40 | 41 | #endif /* APP_DRIVER_H_ */ 42 | -------------------------------------------------------------------------------- /main/demo_tasks/temp_sub_pub_and_led_control_demo/temp_sub_pub_and_led_control_demo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef TEMP_SUB_PUB_AND_LED_CONTROL_DEMO_H 28 | #define TEMP_SUB_PUB_AND_LED_CONTROL_DEMO_H 29 | 30 | /* *INDENT-OFF* */ 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | /* *INDENT-ON* */ 35 | 36 | /** 37 | * @brief This function starts the Temp Sub Pub and LED Control demo. 38 | */ 39 | void vStartTempSubPubAndLEDControlDemo( void ); 40 | 41 | /* *INDENT-OFF* */ 42 | #ifdef __cplusplus 43 | } /* extern "C" */ 44 | #endif 45 | /* *INDENT-ON* */ 46 | 47 | #endif /* TEMP_SUB_PUB_AND_LED_CONTROL_DEMO_H */ 48 | -------------------------------------------------------------------------------- /main/demo_tasks/temp_sub_pub_and_led_control_demo/temp_sub_pub_and_led_control_demo_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef TEMP_SUB_PUB_AND_LED_CONTROL_DEMO_CONFIG_H 28 | #define TEMP_SUB_PUB_AND_LED_CONTROL_DEMO_CONFIG_H 29 | 30 | /* ESP-IDF sdkconfig include. */ 31 | #include 32 | 33 | /* *INDENT-OFF* */ 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | /* *INDENT-ON* */ 38 | 39 | /** 40 | * @brief Size of statically allocated buffers for holding topic names and 41 | * payloads. 42 | */ 43 | #define temppubsubandledcontrolconfigSTRING_BUFFER_LENGTH ( ( unsigned int ) ( CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_STRING_BUFFER_LENGTH ) ) 44 | 45 | /** 46 | * @brief Delay for the synchronous publisher task between publishes. 47 | */ 48 | #define temppubsubandledcontrolconfigDELAY_BETWEEN_PUBLISH_OPERATIONS_MS ( ( unsigned int ) ( CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_DELAY_BETWEEN_PUBLISH_OPERATIONS_MS ) ) 49 | 50 | /** 51 | * @brief The maximum amount of time in milliseconds to wait for the commands 52 | * to be posted to the MQTT agent should the MQTT agent's command queue be full. 53 | * Tasks wait in the Blocked state, so don't use any CPU time. 54 | */ 55 | #define temppubsubandledcontrolconfigMAX_COMMAND_SEND_BLOCK_TIME_MS ( ( unsigned int ) ( CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS ) ) 56 | 57 | /** 58 | * @brief The QoS level of MQTT messages sent by this demo. This must be 0 or 1 59 | * if using AWS as AWS only supports levels 0 or 1. If using another MQTT broker 60 | * that supports QoS level 2, this can be set to 2. 61 | */ 62 | #define temppubsubandledcontrolconfigQOS_LEVEL ( ( unsigned long ) ( CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_QOS_LEVEL ) ) 63 | 64 | /** 65 | * @brief The task priority of temperature pub sub and LED control task. 66 | */ 67 | #define temppubsubandledcontrolconfigTASK_PRIORITY ( ( unsigned int ) ( CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_TASK_PRIORITY ) ) 68 | 69 | /** 70 | * @brief The task stack size of temperature pub sub and LED control task. 71 | */ 72 | #define temppubsubandledcontrolconfigTASK_STACK_SIZE ( ( unsigned int ) ( CONFIG_GRI_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO_TASK_STACK_SIZE ) ) 73 | 74 | /* *INDENT-OFF* */ 75 | #ifdef __cplusplus 76 | } /* extern "C" */ 77 | #endif 78 | /* *INDENT-ON* */ 79 | 80 | #endif /* TEMP_SUB_PUB_AND_LED_CONTROL_DEMO_CONFIG_H */ 81 | -------------------------------------------------------------------------------- /main/idf_component.yml: -------------------------------------------------------------------------------- 1 | ## IDF Component Manager Manifest File 2 | dependencies: 3 | espressif/led_strip: ">=1.1.0-alpha" 4 | espressif/esp_secure_cert_mgr: "^2.0.8" 5 | espressif/cbor: 6 | version: "^0.6.0" 7 | rules: 8 | - if: "idf_version >=5.0" 9 | -------------------------------------------------------------------------------- /main/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 FreeRTOS Reference Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /* Includes *******************************************************************/ 28 | 29 | /* Standard includes. */ 30 | #include 31 | 32 | /* FreeRTOS includes. */ 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | /* ESP-IDF includes. */ 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | /* ESP Secure Certificate Manager include. */ 47 | #include "esp_secure_cert_read.h" 48 | 49 | /* Network transport include. */ 50 | #include "network_transport.h" 51 | 52 | /* coreMQTT-Agent network manager include. */ 53 | #include "core_mqtt_agent_manager.h" 54 | 55 | /* WiFi provisioning/connection handler include. */ 56 | #include "app_wifi.h" 57 | 58 | /* Demo includes. */ 59 | #if CONFIG_GRI_ENABLE_SUB_PUB_UNSUB_DEMO 60 | #include "sub_pub_unsub_demo.h" 61 | #endif /* CONFIG_GRI_ENABLE_SUB_PUB_UNSUB_DEMO */ 62 | 63 | #if CONFIG_GRI_ENABLE_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO 64 | #include "temp_sub_pub_and_led_control_demo.h" 65 | #endif /* CONFIG_GRI_ENABLE_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO */ 66 | 67 | #if CONFIG_GRI_ENABLE_OTA_DEMO 68 | #include "ota_pal.h" 69 | #include "ota_over_mqtt_demo.h" 70 | #endif /* CONFIG_GRI_ENABLE_OTA_DEMO */ 71 | 72 | #if CONFIG_GRI_RUN_QUALIFICATION_TEST 73 | #include "qualification_wrapper_config.h" 74 | #endif /* CONFIG_GRI_RUN_QUALIFICATION_TEST */ 75 | 76 | /** 77 | * @brief The AWS RootCA1 passed in from ./certs/root_cert_auth.pem 78 | */ 79 | extern const char root_cert_auth_start[] asm ( "_binary_root_cert_auth_crt_start" ); 80 | extern const char root_cert_auth_end[] asm ( "_binary_root_cert_auth_crt_end" ); 81 | 82 | /* Global variables ***********************************************************/ 83 | 84 | /** 85 | * @brief Logging tag for ESP-IDF logging functions. 86 | */ 87 | static const char * TAG = "main"; 88 | 89 | /** 90 | * @brief The global network context used to store the credentials 91 | * and TLS connection. 92 | */ 93 | static NetworkContext_t xNetworkContext; 94 | 95 | #if CONFIG_GRI_ENABLE_OTA_DEMO 96 | 97 | /** 98 | * @brief The AWS code signing certificate passed in from ./certs/aws_codesign.crt 99 | */ 100 | extern const char pcAwsCodeSigningCertPem[] asm ( "_binary_aws_codesign_crt_start" ); 101 | 102 | #endif /* CONFIG_GRI_ENABLE_OTA_DEMO */ 103 | 104 | /* Static function declarations ***********************************************/ 105 | 106 | /** 107 | * @brief This function initializes the global network context with credentials. 108 | * 109 | * This handles retrieving and initializing the global network context with the 110 | * credentials it needs to establish a TLS connection. 111 | */ 112 | static BaseType_t prvInitializeNetworkContext( void ); 113 | 114 | /** 115 | * @brief This function starts all enabled demos. 116 | */ 117 | static void prvStartEnabledDemos( void ); 118 | 119 | #if CONFIG_GRI_RUN_QUALIFICATION_TEST 120 | extern BaseType_t xQualificationStart( void ); 121 | #endif /* CONFIG_GRI_RUN_QUALIFICATION_TEST */ 122 | 123 | /* Static function definitions ************************************************/ 124 | 125 | static BaseType_t prvInitializeNetworkContext( void ) 126 | { 127 | /* This is returned by this function. */ 128 | BaseType_t xRet = pdPASS; 129 | 130 | /* This is used to store the error return of ESP-IDF functions. */ 131 | esp_err_t xEspErrRet; 132 | 133 | /* Verify that the MQTT endpoint and thing name have been configured by the 134 | * user. */ 135 | if( strlen( CONFIG_GRI_MQTT_ENDPOINT ) == 0 ) 136 | { 137 | ESP_LOGE( TAG, "Empty endpoint for MQTT broker. Set endpoint by " 138 | "running idf.py menuconfig, then Golden Reference Integration -> " 139 | "Endpoint for MQTT Broker to use." ); 140 | xRet = pdFAIL; 141 | } 142 | 143 | if( strlen( CONFIG_GRI_THING_NAME ) == 0 ) 144 | { 145 | ESP_LOGE( TAG, "Empty thingname for MQTT broker. Set thing name by " 146 | "running idf.py menuconfig, then Golden Reference Integration -> " 147 | "Thing name." ); 148 | xRet = pdFAIL; 149 | } 150 | 151 | /* Initialize network context. */ 152 | 153 | xNetworkContext.pcHostname = CONFIG_GRI_MQTT_ENDPOINT; 154 | xNetworkContext.xPort = CONFIG_GRI_MQTT_PORT; 155 | 156 | /* Get the device certificate from esp_secure_crt_mgr and put into network 157 | * context. */ 158 | xEspErrRet = esp_secure_cert_get_device_cert( &xNetworkContext.pcClientCert, 159 | &xNetworkContext.pcClientCertSize ); 160 | 161 | if( xEspErrRet == ESP_OK ) 162 | { 163 | #if CONFIG_GRI_OUTPUT_CERTS_KEYS 164 | ESP_LOGI( TAG, "\nDevice Cert: \nLength: %" PRIu32 "\n%s", 165 | xNetworkContext.pcClientCertSize, 166 | xNetworkContext.pcClientCert ); 167 | #endif /* CONFIG_GRI_OUTPUT_CERTS_KEYS */ 168 | } 169 | else 170 | { 171 | ESP_LOGE( TAG, "Error in getting device certificate. Error: %s", 172 | esp_err_to_name( xEspErrRet ) ); 173 | 174 | xRet = pdFAIL; 175 | } 176 | 177 | /* Putting the Root CA certificate into the network context. */ 178 | xNetworkContext.pcServerRootCA = root_cert_auth_start; 179 | xNetworkContext.pcServerRootCASize = root_cert_auth_end - root_cert_auth_start; 180 | 181 | if( xEspErrRet == ESP_OK ) 182 | { 183 | #if CONFIG_GRI_OUTPUT_CERTS_KEYS 184 | ESP_LOGI( TAG, "\nCA Cert: \nLength: %" PRIu32 "\n%s", 185 | xNetworkContext.pcServerRootCASize, 186 | xNetworkContext.pcServerRootCA ); 187 | #endif /* CONFIG_GRI_OUTPUT_CERTS_KEYS */ 188 | } 189 | else 190 | { 191 | ESP_LOGE( TAG, "Error in getting CA certificate. Error: %s", 192 | esp_err_to_name( xEspErrRet ) ); 193 | 194 | xRet = pdFAIL; 195 | } 196 | 197 | #if CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL 198 | 199 | /* If the digital signature peripheral is being used, get the digital 200 | * signature peripheral context from esp_secure_crt_mgr and put into 201 | * network context. */ 202 | 203 | xNetworkContext.ds_data = esp_secure_cert_get_ds_ctx(); 204 | 205 | if( xNetworkContext.ds_data == NULL ) 206 | { 207 | ESP_LOGE( TAG, "Error in getting digital signature peripheral data." ); 208 | xRet = pdFAIL; 209 | } 210 | #else /* if CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL */ 211 | xEspErrRet = esp_secure_cert_get_priv_key( &xNetworkContext.pcClientKey, 212 | &xNetworkContext.pcClientKeySize ); 213 | 214 | if( xEspErrRet == ESP_OK ) 215 | { 216 | #if CONFIG_GRI_OUTPUT_CERTS_KEYS 217 | ESP_LOGI( TAG, "\nPrivate Key: \nLength: %" PRIu32 "\n%s", 218 | xNetworkContext.pcClientKeySize, 219 | xNetworkContext.pcClientKey ); 220 | #endif /* CONFIG_GRI_OUTPUT_CERTS_KEYS */ 221 | } 222 | else 223 | { 224 | ESP_LOGE( TAG, "Error in getting private key. Error: %s", 225 | esp_err_to_name( xEspErrRet ) ); 226 | 227 | xRet = pdFAIL; 228 | } 229 | #endif /* CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL */ 230 | 231 | xNetworkContext.pxTls = NULL; 232 | xNetworkContext.xTlsContextSemaphore = xSemaphoreCreateMutex(); 233 | 234 | if( xNetworkContext.xTlsContextSemaphore == NULL ) 235 | { 236 | ESP_LOGE( TAG, "Not enough memory to create TLS semaphore for global " 237 | "network context." ); 238 | 239 | xRet = pdFAIL; 240 | } 241 | 242 | return xRet; 243 | } 244 | 245 | static void prvStartEnabledDemos( void ) 246 | { 247 | BaseType_t xResult; 248 | 249 | #if ( CONFIG_GRI_RUN_QUALIFICATION_TEST == 0 ) 250 | #if CONFIG_GRI_ENABLE_SUB_PUB_UNSUB_DEMO 251 | vStartSubscribePublishUnsubscribeDemo(); 252 | #endif /* CONFIG_GRI_ENABLE_SIMPLE_PUB_SUB_DEMO */ 253 | 254 | #if CONFIG_GRI_ENABLE_TEMPERATURE_PUB_SUB_AND_LED_CONTROL_DEMO 255 | vStartTempSubPubAndLEDControlDemo(); 256 | #endif /* CONFIG_GRI_ENABLE_TEMPERATURE_LED_PUB_SUB_DEMO */ 257 | 258 | #if CONFIG_GRI_ENABLE_OTA_DEMO 259 | #if CONFIG_GRI_OUTPUT_CERTS_KEYS 260 | ESP_LOGI( TAG, "\nCS Cert: \nLength: %zu\n%s", 261 | strlen( pcAwsCodeSigningCertPem ), 262 | pcAwsCodeSigningCertPem ); 263 | #endif /* CONFIG_GRI_OUTPUT_CERTS_KEYS */ 264 | 265 | ESP_LOGI( TAG, "Application version number: %u.%u.%u", 266 | CONFIG_GRI_OTA_DEMO_APP_VERSION_MAJOR, 267 | CONFIG_GRI_OTA_DEMO_APP_VERSION_MINOR, 268 | CONFIG_GRI_OTA_DEMO_APP_VERSION_BUILD ); 269 | 270 | if( otaPal_SetCodeSigningCertificate( pcAwsCodeSigningCertPem ) ) 271 | { 272 | vStartOTACodeSigningDemo(); 273 | } 274 | else 275 | { 276 | ESP_LOGE( TAG, 277 | "Failed to set the code signing certificate for the AWS OTA " 278 | "library. OTA demo will not be started." ); 279 | } 280 | #endif /* CONFIG_GRI_ENABLE_OTA_DEMO */ 281 | 282 | /* Initialize and start the coreMQTT-Agent network manager. This handles 283 | * establishing a TLS connection and MQTT connection to the MQTT broker. 284 | * This needs to be started before starting WiFi so it can handle WiFi 285 | * connection events. */ 286 | xResult = xCoreMqttAgentManagerStart( &xNetworkContext ); 287 | 288 | if( xResult != pdPASS ) 289 | { 290 | ESP_LOGE( TAG, "Failed to initialize and start coreMQTT-Agent network " 291 | "manager." ); 292 | 293 | configASSERT( xResult == pdPASS ); 294 | } 295 | #endif /* CONFIG_GRI_RUN_QUALIFICATION_TEST == 0 */ 296 | 297 | #if CONFIG_GRI_RUN_QUALIFICATION_TEST 298 | /* Disable some logs to avoid failure on IDT log parser. */ 299 | esp_log_level_set( "esp_ota_ops", ESP_LOG_NONE ); 300 | esp_log_level_set( "esp-tls-mbedtls", ESP_LOG_NONE ); 301 | esp_log_level_set( "AWS_OTA", ESP_LOG_NONE ); 302 | 303 | if( ( xResult = xQualificationStart() ) != pdPASS ) 304 | { 305 | ESP_LOGE( TAG, "Failed to start Qualification task: errno=%d", xResult ); 306 | } 307 | configASSERT( xResult == pdPASS ); 308 | #endif /* CONFIG_GRI_RUN_QUALIFICATION_TEST */ 309 | } 310 | 311 | /* Main function definition ***************************************************/ 312 | 313 | /** 314 | * @brief This function serves as the main entry point of this project. 315 | */ 316 | void app_main( void ) 317 | { 318 | /* This is used to store the return of initialization functions. */ 319 | BaseType_t xRet; 320 | 321 | /* This is used to store the error return of ESP-IDF functions. */ 322 | esp_err_t xEspErrRet; 323 | 324 | /* Initialize global network context. */ 325 | xRet = prvInitializeNetworkContext(); 326 | 327 | if( xRet != pdPASS ) 328 | { 329 | ESP_LOGE( TAG, "Failed to initialize global network context." ); 330 | return; 331 | } 332 | 333 | /* Initialize NVS partition. This needs to be done before initializing 334 | * WiFi. */ 335 | xEspErrRet = nvs_flash_init(); 336 | 337 | if( ( xEspErrRet == ESP_ERR_NVS_NO_FREE_PAGES ) || 338 | ( xEspErrRet == ESP_ERR_NVS_NEW_VERSION_FOUND ) ) 339 | { 340 | /* NVS partition was truncated 341 | * and needs to be erased */ 342 | ESP_ERROR_CHECK( nvs_flash_erase() ); 343 | 344 | /* Retry nvs_flash_init */ 345 | ESP_ERROR_CHECK( nvs_flash_init() ); 346 | } 347 | 348 | /* Initialize ESP-Event library default event loop. 349 | * This handles WiFi and TCP/IP events and this needs to be called before 350 | * starting WiFi and the coreMQTT-Agent network manager. */ 351 | ESP_ERROR_CHECK( esp_event_loop_create_default() ); 352 | 353 | /* Start demo tasks. This needs to be done before starting WiFi and 354 | * and the coreMQTT-Agent network manager so demos can 355 | * register their coreMQTT-Agent event handlers before events happen. */ 356 | prvStartEnabledDemos(); 357 | 358 | /* Start WiFi. */ 359 | app_wifi_init(); 360 | app_wifi_start( POP_TYPE_MAC ); 361 | } 362 | -------------------------------------------------------------------------------- /main/networking/mqtt/core_mqtt_agent_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef CORE_MQTT_AGENT_NETWORK_MANAGER_H 28 | #define CORE_MQTT_AGENT_NETWORK_MANAGER_H 29 | 30 | #include "network_transport.h" 31 | #include "freertos/FreeRTOS.h" 32 | #include "esp_event.h" 33 | 34 | /* *INDENT-OFF* */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | /* *INDENT-ON* */ 39 | 40 | /** 41 | * @brief Register an event handler with coreMQTT-Agent events. 42 | * 43 | * @param[in] xEventHandler Event handling function. 44 | * 45 | * @return pdPASS if successful, pdFAIL otherwise. 46 | */ 47 | BaseType_t xCoreMqttAgentManagerRegisterHandler( esp_event_handler_t xEventHandler ); 48 | 49 | /** 50 | * @brief Start the coreMQTT-Agent manager. 51 | * 52 | * This handles initializing the underlying coreMQTT context, initializing 53 | * coreMQTT-Agent, starting the coreMQTT-Agent task, and starting the 54 | * connection handling task. 55 | * 56 | * @param[in] pxNetworkContextIn Pointer to the network context. 57 | * 58 | * @return pdPASS if successful, pdFAIL otherwise. 59 | */ 60 | BaseType_t xCoreMqttAgentManagerStart( NetworkContext_t * pxNetworkContextIn ); 61 | 62 | /** 63 | * @brief Posts a coreMQTT-Agent event to the default event loop. 64 | * 65 | * @param[in] lEventId Event ID of the coreMQTT-Agent event to be posted. 66 | * 67 | * @return pdPASS if successful, pdFAIL otherwise. 68 | */ 69 | BaseType_t xCoreMqttAgentManagerPost( int32_t lEventId ); 70 | 71 | /* *INDENT-OFF* */ 72 | #ifdef __cplusplus 73 | } /* extern "C" */ 74 | #endif 75 | /* *INDENT-ON* */ 76 | 77 | #endif /* CORE_MQTT_AGENT_NETWORK_MANAGER_H */ 78 | -------------------------------------------------------------------------------- /main/networking/mqtt/core_mqtt_agent_manager_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef CORE_MQTT_AGENT_MANAGER_CONFIG_H 28 | #define CORE_MQTT_AGENT_MANAGER_CONFIG_H 29 | 30 | /* ESP-IDF sdkconfig include. */ 31 | #include 32 | 33 | #if CONFIG_GRI_RUN_QUALIFICATION_TEST 34 | #include "qualification_wrapper_config.h" 35 | #endif /* CONFIG_GRI_RUN_QUALIFICATION_TEST */ 36 | 37 | /* *INDENT-OFF* */ 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | /* *INDENT-ON* */ 42 | 43 | /** 44 | * @brief The thing name of the device. 45 | */ 46 | #define configCLIENT_IDENTIFIER ( CONFIG_GRI_THING_NAME ) 47 | 48 | /** 49 | * @brief The task stack size of the connection handling task. 50 | */ 51 | #define configCONNECTION_TASK_STACK_SIZE ( CONFIG_GRI_CONNECTION_TASK_STACK_SIZE ) 52 | 53 | /** 54 | * @brief The task priority of the connection handling task. 55 | */ 56 | #define configCONNECTION_TASK_PRIORITY ( CONFIG_GRI_CONNECTION_TASK_PRIORITY ) 57 | 58 | /** 59 | * @brief The maximum back-off delay (in milliseconds) for retrying failed operation 60 | * with server. 61 | */ 62 | #define configRETRY_MAX_BACKOFF_DELAY_MS ( CONFIG_GRI_RETRY_MAX_BACKOFF_DELAY_MS ) 63 | 64 | /** 65 | * @brief The base back-off delay (in milliseconds) to use for network operation retry 66 | * attempts. 67 | */ 68 | #define configRETRY_BACKOFF_BASE_MS ( CONFIG_GRI_RETRY_BACKOFF_BASE_MS ) 69 | 70 | /** 71 | * @brief Dimensions the buffer used to serialize and deserialize MQTT packets. 72 | * @note Specified in bytes. Must be large enough to hold the maximum 73 | * anticipated MQTT payload. 74 | */ 75 | #define configMQTT_AGENT_NETWORK_BUFFER_SIZE ( CONFIG_GRI_MQTT_AGENT_NETWORK_BUFFER_SIZE ) 76 | 77 | /** 78 | * @brief The length of the queue used to hold commands for the agent. 79 | */ 80 | #define configMQTT_AGENT_COMMAND_QUEUE_LENGTH ( CONFIG_GRI_MQTT_AGENT_COMMAND_QUEUE_LENGTH ) 81 | 82 | /** 83 | * @brief The maximum time interval in seconds which is allowed to elapse 84 | * between two Control Packets. 85 | * 86 | * It is the responsibility of the Client to ensure that the interval between 87 | * Control Packets being sent does not exceed the this Keep Alive value. In the 88 | * absence of sending any other Control Packets, the Client MUST send a 89 | * PINGREQ Packet. 90 | */ 91 | #define configMQTT_AGENT_KEEP_ALIVE_INTERVAL_SECONDS ( CONFIG_GRI_MQTT_AGENT_KEEP_ALIVE_INTERVAL_SECONDS ) 92 | 93 | /** 94 | * @brief Timeout for receiving CONNACK after sending an MQTT CONNECT packet. 95 | * Defined in milliseconds. 96 | */ 97 | #define configMQTT_AGENT_CONNACK_RECV_TIMEOUT_MS ( CONFIG_GRI_MQTT_AGENT_CONNACK_RECV_TIMEOUT_MS ) 98 | 99 | /** 100 | * @brief The task stack size of the coreMQTT-Agent task. 101 | */ 102 | #define configMQTT_AGENT_TASK_STACK_SIZE ( CONFIG_GRI_MQTT_AGENT_TASK_STACK_SIZE ) 103 | 104 | /** 105 | * @brief The task priority of the coreMQTT-Agent task. 106 | */ 107 | #define configMQTT_AGENT_TASK_PRIORITY ( CONFIG_GRI_MQTT_AGENT_TASK_PRIORITY ) 108 | 109 | /* *INDENT-OFF* */ 110 | #ifdef __cplusplus 111 | } /* extern "C" */ 112 | #endif 113 | /* *INDENT-ON* */ 114 | 115 | #endif /* CORE_MQTT_AGENT_MANAGER_CONFIG_H */ 116 | -------------------------------------------------------------------------------- /main/networking/mqtt/core_mqtt_agent_manager_events.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #include 28 | #include "core_mqtt_agent_manager_events.h" 29 | #include "esp_event_base.h" 30 | 31 | ESP_EVENT_DEFINE_BASE( CORE_MQTT_AGENT_EVENT ); 32 | -------------------------------------------------------------------------------- /main/networking/mqtt/core_mqtt_agent_manager_events.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 Featured FreeRTOS IoT Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef CORE_MQTT_AGENT_MANAGER_EVENTS_H 28 | #define CORE_MQTT_AGENT_MANAGER_EVENTS_H 29 | 30 | #include "esp_event.h" 31 | 32 | /* *INDENT-OFF* */ 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | /* *INDENT-ON* */ 37 | 38 | ESP_EVENT_DECLARE_BASE( CORE_MQTT_AGENT_EVENT ); 39 | 40 | enum 41 | { 42 | CORE_MQTT_AGENT_CONNECTED_EVENT, 43 | CORE_MQTT_AGENT_DISCONNECTED_EVENT, 44 | CORE_MQTT_AGENT_OTA_STARTED_EVENT, 45 | CORE_MQTT_AGENT_OTA_STOPPED_EVENT 46 | }; 47 | 48 | /* *INDENT-OFF* */ 49 | #ifdef __cplusplus 50 | } /* extern "C" */ 51 | #endif 52 | /* *INDENT-ON* */ 53 | 54 | #endif /* CORE_MQTT_AGENT_MANAGER_EVENTS_H */ 55 | -------------------------------------------------------------------------------- /main/networking/mqtt/subscription_manager.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202011.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://aws.amazon.com/freertos 24 | * 25 | */ 26 | 27 | /** 28 | * @file subscription_manager.c 29 | * @brief Functions for managing MQTT subscriptions. 30 | */ 31 | 32 | /* Standard includes. */ 33 | #include 34 | 35 | /* Subscription manager header include. */ 36 | #include "subscription_manager.h" 37 | 38 | /* Logging configuration for the Demo. */ 39 | #ifndef LIBRARY_LOG_NAME 40 | #define LIBRARY_LOG_NAME "SubManager" 41 | #endif 42 | 43 | #ifndef LIBRARY_LOG_LEVEL 44 | #define LIBRARY_LOG_LEVEL LOG_INFO 45 | #endif 46 | 47 | #include "logging_stack.h" 48 | 49 | bool addSubscription( SubscriptionElement_t * pxSubscriptionList, 50 | const char * pcTopicFilterString, 51 | uint16_t usTopicFilterLength, 52 | IncomingPubCallback_t pxIncomingPublishCallback, 53 | void * pvIncomingPublishCallbackContext ) 54 | { 55 | int32_t lIndex = 0; 56 | size_t xAvailableIndex = SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS; 57 | bool xReturnStatus = false; 58 | 59 | if( ( pxSubscriptionList == NULL ) || 60 | ( pcTopicFilterString == NULL ) || 61 | ( usTopicFilterLength == 0U ) || 62 | ( pxIncomingPublishCallback == NULL ) ) 63 | { 64 | LogError( ( "Invalid parameter. pxSubscriptionList=%p, pcTopicFilterString=%p," 65 | " usTopicFilterLength=%u, pxIncomingPublishCallback=%p.", 66 | pxSubscriptionList, 67 | pcTopicFilterString, 68 | ( unsigned int ) usTopicFilterLength, 69 | pxIncomingPublishCallback ) ); 70 | } 71 | else 72 | { 73 | /* Start at end of array, so that we will insert at the first available index. 74 | * Scans backwards to find duplicates. */ 75 | for( lIndex = ( int32_t ) SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS - 1; lIndex >= 0; lIndex-- ) 76 | { 77 | if( pxSubscriptionList[ lIndex ].usFilterStringLength == 0 ) 78 | { 79 | xAvailableIndex = lIndex; 80 | } 81 | else if( ( pxSubscriptionList[ lIndex ].usFilterStringLength == usTopicFilterLength ) && 82 | ( strncmp( pcTopicFilterString, pxSubscriptionList[ lIndex ].pcSubscriptionFilterString, ( size_t ) usTopicFilterLength ) == 0 ) ) 83 | { 84 | /* If a subscription already exists, don't do anything. */ 85 | if( ( pxSubscriptionList[ lIndex ].pxIncomingPublishCallback == pxIncomingPublishCallback ) && 86 | ( pxSubscriptionList[ lIndex ].pvIncomingPublishCallbackContext == pvIncomingPublishCallbackContext ) ) 87 | { 88 | LogWarn( ( "Subscription already exists.\n" ) ); 89 | xAvailableIndex = SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS; 90 | xReturnStatus = true; 91 | break; 92 | } 93 | } 94 | } 95 | 96 | if( xAvailableIndex < SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS ) 97 | { 98 | pxSubscriptionList[ xAvailableIndex ].pcSubscriptionFilterString = pcTopicFilterString; 99 | pxSubscriptionList[ xAvailableIndex ].usFilterStringLength = usTopicFilterLength; 100 | pxSubscriptionList[ xAvailableIndex ].pxIncomingPublishCallback = pxIncomingPublishCallback; 101 | pxSubscriptionList[ xAvailableIndex ].pvIncomingPublishCallbackContext = pvIncomingPublishCallbackContext; 102 | xReturnStatus = true; 103 | } 104 | } 105 | 106 | return xReturnStatus; 107 | } 108 | 109 | /*-----------------------------------------------------------*/ 110 | 111 | void removeSubscription( SubscriptionElement_t * pxSubscriptionList, 112 | const char * pcTopicFilterString, 113 | uint16_t usTopicFilterLength ) 114 | { 115 | uint32_t ulIndex = 0; 116 | 117 | if( ( pxSubscriptionList == NULL ) || 118 | ( pcTopicFilterString == NULL ) || 119 | ( usTopicFilterLength == 0U ) ) 120 | { 121 | LogError( ( "Invalid parameter. pxSubscriptionList=%p, pcTopicFilterString=%p," 122 | " usTopicFilterLength=%u.", 123 | pxSubscriptionList, 124 | pcTopicFilterString, 125 | ( unsigned int ) usTopicFilterLength ) ); 126 | } 127 | else 128 | { 129 | for( ulIndex = 0U; ulIndex < SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS; ulIndex++ ) 130 | { 131 | if( pxSubscriptionList[ ulIndex ].usFilterStringLength == usTopicFilterLength ) 132 | { 133 | if( strncmp( pxSubscriptionList[ ulIndex ].pcSubscriptionFilterString, pcTopicFilterString, usTopicFilterLength ) == 0 ) 134 | { 135 | memset( &( pxSubscriptionList[ ulIndex ] ), 0x00, sizeof( SubscriptionElement_t ) ); 136 | } 137 | } 138 | } 139 | } 140 | } 141 | 142 | /*-----------------------------------------------------------*/ 143 | 144 | bool handleIncomingPublishes( SubscriptionElement_t * pxSubscriptionList, 145 | MQTTPublishInfo_t * pxPublishInfo ) 146 | { 147 | uint32_t ulIndex = 0; 148 | bool isMatched = false, publishHandled = false; 149 | 150 | if( ( pxSubscriptionList == NULL ) || 151 | ( pxPublishInfo == NULL ) ) 152 | { 153 | LogError( ( "Invalid parameter. pxSubscriptionList=%p, pxPublishInfo=%p,", 154 | pxSubscriptionList, 155 | pxPublishInfo ) ); 156 | } 157 | else 158 | { 159 | for( ulIndex = 0U; ulIndex < SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS; ulIndex++ ) 160 | { 161 | if( pxSubscriptionList[ ulIndex ].usFilterStringLength > 0 ) 162 | { 163 | MQTT_MatchTopic( pxPublishInfo->pTopicName, 164 | pxPublishInfo->topicNameLength, 165 | pxSubscriptionList[ ulIndex ].pcSubscriptionFilterString, 166 | pxSubscriptionList[ ulIndex ].usFilterStringLength, 167 | &isMatched ); 168 | 169 | if( isMatched == true ) 170 | { 171 | pxSubscriptionList[ ulIndex ].pxIncomingPublishCallback( pxSubscriptionList[ ulIndex ].pvIncomingPublishCallbackContext, 172 | pxPublishInfo ); 173 | publishHandled = true; 174 | } 175 | } 176 | } 177 | } 178 | 179 | return publishHandled; 180 | } 181 | -------------------------------------------------------------------------------- /main/networking/mqtt/subscription_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202011.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://aws.amazon.com/freertos 24 | * 25 | */ 26 | 27 | /** 28 | * @file subscription_manager.h 29 | * @brief Functions for managing MQTT subscriptions. 30 | */ 31 | #ifndef SUBSCRIPTION_MANAGER_H 32 | #define SUBSCRIPTION_MANAGER_H 33 | 34 | /* core MQTT include. */ 35 | #include "core_mqtt.h" 36 | 37 | /** 38 | * @brief Maximum number of subscriptions maintained by the subscription manager 39 | * simultaneously in a list. 40 | */ 41 | #ifndef SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS 42 | #define SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS 10U 43 | #endif 44 | 45 | /* *INDENT-OFF* */ 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | /* *INDENT-ON* */ 50 | 51 | /** 52 | * @brief Callback function called when receiving a publish. 53 | * 54 | * @param[in] pvIncomingPublishCallbackContext The incoming publish callback context. 55 | * @param[in] pxPublishInfo Deserialized publish information. 56 | */ 57 | typedef void (* IncomingPubCallback_t )( void * pvIncomingPublishCallbackContext, 58 | MQTTPublishInfo_t * pxPublishInfo ); 59 | 60 | /** 61 | * @brief An element in the list of subscriptions. 62 | * 63 | * This subscription manager implementation expects that the array of the 64 | * subscription elements used for storing subscriptions to be initialized to 0. 65 | * 66 | * @note This implementation allows multiple tasks to subscribe to the same topic. 67 | * In this case, another element is added to the subscription list, differing 68 | * in the intended publish callback. Also note that the topic filters are not 69 | * copied in the subscription manager and hence the topic filter strings need to 70 | * stay in scope until unsubscribed. 71 | */ 72 | typedef struct subscriptionElement 73 | { 74 | IncomingPubCallback_t pxIncomingPublishCallback; 75 | void * pvIncomingPublishCallbackContext; 76 | uint16_t usFilterStringLength; 77 | const char * pcSubscriptionFilterString; 78 | } SubscriptionElement_t; 79 | 80 | /** 81 | * @brief Add a subscription to the subscription list. 82 | * 83 | * @note Multiple tasks can be subscribed to the same topic with different 84 | * context-callback pairs. However, a single context-callback pair may only be 85 | * associated to the same topic filter once. 86 | * 87 | * @param[in] pxSubscriptionList The pointer to the subscription list array. 88 | * @param[in] pcTopicFilterString Topic filter string of subscription. 89 | * @param[in] usTopicFilterLength Length of topic filter string. 90 | * @param[in] pxIncomingPublishCallback Callback function for the subscription. 91 | * @param[in] pvIncomingPublishCallbackContext Context for the subscription callback. 92 | * 93 | * @return `true` if subscription added or exists, `false` if insufficient memory. 94 | */ 95 | bool addSubscription( SubscriptionElement_t * pxSubscriptionList, 96 | const char * pcTopicFilterString, 97 | uint16_t usTopicFilterLength, 98 | IncomingPubCallback_t pxIncomingPublishCallback, 99 | void * pvIncomingPublishCallbackContext ); 100 | 101 | /** 102 | * @brief Remove a subscription from the subscription list. 103 | * 104 | * @note If the topic filter exists multiple times in the subscription list, 105 | * then every instance of the subscription will be removed. 106 | * 107 | * @param[in] pxSubscriptionList The pointer to the subscription list array. 108 | * @param[in] pcTopicFilterString Topic filter of subscription. 109 | * @param[in] usTopicFilterLength Length of topic filter. 110 | */ 111 | void removeSubscription( SubscriptionElement_t * pxSubscriptionList, 112 | const char * pcTopicFilterString, 113 | uint16_t usTopicFilterLength ); 114 | 115 | /** 116 | * @brief Handle incoming publishes by invoking the callbacks registered 117 | * for the incoming publish's topic filter. 118 | * 119 | * @param[in] pxSubscriptionList The pointer to the subscription list array. 120 | * @param[in] pxPublishInfo Info of incoming publish. 121 | * 122 | * @return `true` if an application callback could be invoked; 123 | * `false` otherwise. 124 | */ 125 | bool handleIncomingPublishes( SubscriptionElement_t * pxSubscriptionList, 126 | MQTTPublishInfo_t * pxPublishInfo ); 127 | 128 | /* *INDENT-OFF* */ 129 | #ifdef __cplusplus 130 | } /* extern "C" */ 131 | #endif 132 | /* *INDENT-ON* */ 133 | 134 | #endif /* SUBSCRIPTION_MANAGER_H */ 135 | -------------------------------------------------------------------------------- /main/networking/wifi/app_wifi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This example code is in the Public Domain (or CC0 licensed, at your option.) 3 | * 4 | * Unless required by applicable law or agreed to in writing, this 5 | * software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 6 | * CONDITIONS OF ANY KIND, either express or implied. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL( 4, 1, 0 ) 17 | /* Features supported in 4.1+ */ 18 | #define ESP_NETIF_SUPPORTED 19 | #endif 20 | 21 | #ifdef ESP_NETIF_SUPPORTED 22 | #include 23 | #else 24 | #include 25 | #endif 26 | 27 | #include 28 | #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE 29 | #include 30 | #else /* CONFIG_APP_WIFI_PROV_TRANSPORT_SOFTAP */ 31 | #include 32 | #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ 33 | 34 | #include 35 | #include 36 | #include 37 | #include "app_wifi.h" 38 | 39 | static const char * TAG = "app_wifi"; 40 | static const int WIFI_CONNECTED_EVENT = BIT0; 41 | static EventGroupHandle_t wifi_event_group; 42 | 43 | #define PROV_QR_VERSION "v1" 44 | 45 | #define PROV_TRANSPORT_SOFTAP "softap" 46 | #define PROV_TRANSPORT_BLE "ble" 47 | #define QRCODE_BASE_URL "https://espressif.github.io/esp-jumpstart/qrcode.html" 48 | 49 | #define CREDENTIALS_NAMESPACE "creds" 50 | #define RANDOM_NVS_KEY "random" 51 | 52 | static void app_wifi_print_qr( const char * name, 53 | const char * pop, 54 | const char * transport ) 55 | { 56 | if( !name || !pop || !transport ) 57 | { 58 | ESP_LOGW( TAG, "Cannot generate QR code payload. Data missing." ); 59 | return; 60 | } 61 | 62 | char payload[ 150 ]; 63 | snprintf( payload, sizeof( payload ), "{\"ver\":\"%s\",\"name\":\"%s\"" \ 64 | ",\"pop\":\"%s\",\"transport\":\"%s\"}", 65 | PROV_QR_VERSION, name, pop, transport ); 66 | #ifdef CONFIG_APP_WIFI_PROV_SHOW_QR 67 | ESP_LOGI( TAG, "Scan this QR code from the phone app for Provisioning." ); 68 | qrcode_display( payload ); 69 | #endif /* CONFIG_APP_WIFI_PROV_SHOW_QR */ 70 | ESP_LOGI( TAG, "If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s", QRCODE_BASE_URL, payload ); 71 | } 72 | 73 | /* Event handler for catching system events */ 74 | static void event_handler( void * arg, 75 | esp_event_base_t event_base, 76 | long int event_id, 77 | void * event_data ) 78 | { 79 | if( event_base == WIFI_PROV_EVENT ) 80 | { 81 | switch( event_id ) 82 | { 83 | case WIFI_PROV_START: 84 | ESP_LOGI( TAG, "Provisioning started" ); 85 | break; 86 | 87 | case WIFI_PROV_CRED_RECV: 88 | { 89 | wifi_sta_config_t * wifi_sta_cfg = ( wifi_sta_config_t * ) event_data; 90 | ESP_LOGI( TAG, "Received Wi-Fi credentials" 91 | "\n\tSSID : %s\n\tPassword : %s", 92 | ( const char * ) wifi_sta_cfg->ssid, 93 | ( const char * ) wifi_sta_cfg->password ); 94 | break; 95 | } 96 | 97 | case WIFI_PROV_CRED_FAIL: 98 | { 99 | wifi_prov_sta_fail_reason_t * reason = ( wifi_prov_sta_fail_reason_t * ) event_data; 100 | ESP_LOGE( TAG, "Provisioning failed!\n\tReason : %s" 101 | "\n\tPlease reset to factory and retry provisioning", 102 | ( *reason == WIFI_PROV_STA_AUTH_ERROR ) ? 103 | "Wi-Fi station authentication failed" : "Wi-Fi access-point not found" ); 104 | break; 105 | } 106 | 107 | case WIFI_PROV_CRED_SUCCESS: 108 | ESP_LOGI( TAG, "Provisioning successful" ); 109 | break; 110 | 111 | case WIFI_PROV_END: 112 | /* De-initialize manager once provisioning is finished */ 113 | wifi_prov_mgr_deinit(); 114 | break; 115 | 116 | default: 117 | break; 118 | } 119 | } 120 | else if( ( event_base == WIFI_EVENT ) && ( event_id == WIFI_EVENT_STA_START ) ) 121 | { 122 | esp_wifi_connect(); 123 | } 124 | else if( ( event_base == IP_EVENT ) && ( event_id == IP_EVENT_STA_GOT_IP ) ) 125 | { 126 | ip_event_got_ip_t * event = ( ip_event_got_ip_t * ) event_data; 127 | ESP_LOGI( TAG, "Connected with IP Address:" IPSTR, IP2STR( &event->ip_info.ip ) ); 128 | /* Signal main application to continue execution */ 129 | xEventGroupSetBits( wifi_event_group, WIFI_CONNECTED_EVENT ); 130 | } 131 | else if( ( event_base == WIFI_EVENT ) && ( event_id == WIFI_EVENT_STA_DISCONNECTED ) ) 132 | { 133 | ESP_LOGI( TAG, "Disconnected. Connecting to the AP again..." ); 134 | esp_wifi_connect(); 135 | } 136 | } 137 | 138 | static void wifi_init_sta() 139 | { 140 | ESP_ERROR_CHECK( esp_wifi_set_mode( WIFI_MODE_STA ) ); 141 | ESP_ERROR_CHECK( esp_wifi_start() ); 142 | } 143 | 144 | /* free the return value after use. */ 145 | static esp_err_t read_random_bytes_from_nvs( uint8_t ** random_bytes, 146 | size_t * len ) 147 | { 148 | nvs_handle handle; 149 | esp_err_t err; 150 | 151 | *len = 0; 152 | 153 | if( ( err = nvs_open_from_partition( "PARTITION_NAME", CREDENTIALS_NAMESPACE, 154 | NVS_READONLY, &handle ) ) != ESP_OK ) 155 | { 156 | ESP_LOGD( TAG, "NVS open for %s %s %s failed with error %d", "PARTITION_NAME", CREDENTIALS_NAMESPACE, RANDOM_NVS_KEY, err ); 157 | return ESP_FAIL; 158 | } 159 | 160 | if( ( err = nvs_get_blob( handle, RANDOM_NVS_KEY, NULL, len ) ) != ESP_OK ) 161 | { 162 | ESP_LOGD( TAG, "Error %d. Failed to read key %s.", err, RANDOM_NVS_KEY ); 163 | nvs_close( handle ); 164 | return ESP_ERR_NOT_FOUND; 165 | } 166 | 167 | *random_bytes = calloc( *len, 1 ); 168 | 169 | if( *random_bytes ) 170 | { 171 | nvs_get_blob( handle, RANDOM_NVS_KEY, *random_bytes, len ); 172 | nvs_close( handle ); 173 | return ESP_OK; 174 | } 175 | 176 | nvs_close( handle ); 177 | return ESP_ERR_NO_MEM; 178 | } 179 | 180 | static esp_err_t get_device_service_name( char * service_name, 181 | size_t max ) 182 | { 183 | uint8_t * nvs_random; 184 | const char * ssid_prefix = "PROV_"; 185 | size_t nvs_random_size = 0; 186 | 187 | if( ( read_random_bytes_from_nvs( &nvs_random, &nvs_random_size ) != ESP_OK ) || ( nvs_random_size < 3 ) ) 188 | { 189 | uint8_t eth_mac[ 6 ]; 190 | esp_wifi_get_mac( WIFI_IF_STA, eth_mac ); 191 | snprintf( service_name, max, "%s%02x%02x%02x", ssid_prefix, eth_mac[ 3 ], eth_mac[ 4 ], eth_mac[ 5 ] ); 192 | } 193 | else 194 | { 195 | snprintf( service_name, max, "%s%02x%02x%02x", ssid_prefix, nvs_random[ nvs_random_size - 3 ], 196 | nvs_random[ nvs_random_size - 2 ], nvs_random[ nvs_random_size - 1 ] ); 197 | } 198 | 199 | if( nvs_random ) 200 | { 201 | /* free(nvs_random); */ 202 | } 203 | 204 | return ESP_OK; 205 | } 206 | 207 | 208 | static esp_err_t get_device_pop( char * pop, 209 | size_t max, 210 | app_wifi_pop_type_t pop_type ) 211 | { 212 | if( !pop || !max ) 213 | { 214 | return ESP_ERR_INVALID_ARG; 215 | } 216 | 217 | if( pop_type == POP_TYPE_MAC ) 218 | { 219 | uint8_t eth_mac[ 6 ]; 220 | esp_err_t err = esp_wifi_get_mac( WIFI_IF_STA, eth_mac ); 221 | 222 | if( err == ESP_OK ) 223 | { 224 | snprintf( pop, max, "%02x%02x%02x%02x", eth_mac[ 2 ], eth_mac[ 3 ], eth_mac[ 4 ], eth_mac[ 5 ] ); 225 | return ESP_OK; 226 | } 227 | else 228 | { 229 | return err; 230 | } 231 | } 232 | else if( pop_type == POP_TYPE_RANDOM ) 233 | { 234 | uint8_t * nvs_random; 235 | size_t nvs_random_size = 0; 236 | 237 | if( ( read_random_bytes_from_nvs( &nvs_random, &nvs_random_size ) != ESP_OK ) || ( nvs_random_size < 4 ) ) 238 | { 239 | return ESP_ERR_NOT_FOUND; 240 | } 241 | else 242 | { 243 | snprintf( pop, max, "%02x%02x%02x%02x", nvs_random[ 0 ], nvs_random[ 1 ], nvs_random[ 2 ], nvs_random[ 3 ] ); 244 | free( nvs_random ); 245 | return ESP_OK; 246 | } 247 | } 248 | else 249 | { 250 | return ESP_ERR_INVALID_ARG; 251 | } 252 | } 253 | 254 | void app_wifi_init( void ) 255 | { 256 | /* Initialize TCP/IP */ 257 | #ifdef ESP_NETIF_SUPPORTED 258 | esp_netif_init(); 259 | #else 260 | tcpip_adapter_init(); 261 | #endif 262 | 263 | /* Initialize the event loop */ 264 | /*ESP_ERROR_CHECK(esp_event_loop_create_default()); */ 265 | wifi_event_group = xEventGroupCreate(); 266 | 267 | /* Register our event handler for Wi-Fi, IP and Provisioning related events */ 268 | ESP_ERROR_CHECK( esp_event_handler_register( WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL ) ); 269 | ESP_ERROR_CHECK( esp_event_handler_register( WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL ) ); 270 | ESP_ERROR_CHECK( esp_event_handler_register( IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL ) ); 271 | 272 | /* Initialize Wi-Fi including netif with default config */ 273 | #ifdef ESP_NETIF_SUPPORTED 274 | esp_netif_create_default_wifi_sta(); 275 | #endif 276 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); 277 | ESP_ERROR_CHECK( esp_wifi_init( &cfg ) ); 278 | } 279 | 280 | esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ) 281 | { 282 | /* Configuration for the provisioning manager */ 283 | wifi_prov_mgr_config_t config = 284 | { 285 | /* What is the Provisioning Scheme that we want ? 286 | * wifi_prov_scheme_softap or wifi_prov_scheme_ble */ 287 | #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE 288 | .scheme = wifi_prov_scheme_ble, 289 | #else /* CONFIG_APP_WIFI_PROV_TRANSPORT_SOFTAP */ 290 | .scheme = wifi_prov_scheme_softap, 291 | #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ 292 | 293 | /* Any default scheme specific event handler that you would 294 | * like to choose. Since our example application requires 295 | * neither BT nor BLE, we can choose to release the associated 296 | * memory once provisioning is complete, or not needed 297 | * (in case when device is already provisioned). Choosing 298 | * appropriate scheme specific event handler allows the manager 299 | * to take care of this automatically. This can be set to 300 | * WIFI_PROV_EVENT_HANDLER_NONE when using wifi_prov_scheme_softap*/ 301 | #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE 302 | .scheme_event_handler = WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM 303 | #else /* CONFIG_APP_WIFI_PROV_TRANSPORT_SOFTAP */ 304 | .scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE, 305 | #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ 306 | }; 307 | 308 | /* Initialize provisioning manager with the 309 | * configuration parameters set above */ 310 | ESP_ERROR_CHECK( wifi_prov_mgr_init( config ) ); 311 | 312 | bool provisioned = false; 313 | /* Let's find out if the device is provisioned */ 314 | ESP_ERROR_CHECK( wifi_prov_mgr_is_provisioned( &provisioned ) ); 315 | 316 | /* If device is not yet provisioned start provisioning service */ 317 | if( !provisioned ) 318 | { 319 | ESP_LOGI( TAG, "Starting provisioning" ); 320 | #ifdef ESP_NETIF_SUPPORTED 321 | esp_netif_create_default_wifi_ap(); 322 | #endif 323 | 324 | /* What is the Device Service Name that we want 325 | * This translates to : 326 | * - Wi-Fi SSID when scheme is wifi_prov_scheme_softap 327 | * - device name when scheme is wifi_prov_scheme_ble 328 | */ 329 | char service_name[ 12 ]; 330 | get_device_service_name( service_name, sizeof( service_name ) ); 331 | 332 | /* What is the security level that we want (0 or 1): 333 | * - WIFI_PROV_SECURITY_0 is simply plain text communication. 334 | * - WIFI_PROV_SECURITY_1 is secure communication which consists of secure handshake 335 | * using X25519 key exchange and proof of possession (pop) and AES-CTR 336 | * for encryption/decryption of messages. 337 | */ 338 | wifi_prov_security_t security = WIFI_PROV_SECURITY_1; 339 | 340 | /* Do we want a proof-of-possession (ignored if Security 0 is selected): 341 | * - this should be a string with length > 0 342 | * - NULL if not used 343 | */ 344 | char pop[ 9 ]; 345 | esp_err_t err = get_device_pop( pop, sizeof( pop ), pop_type ); 346 | 347 | if( err != ESP_OK ) 348 | { 349 | ESP_LOGE( TAG, "Error: %d. Failed to get PoP from NVS, Please perform Claiming.", err ); 350 | return err; 351 | } 352 | 353 | /* What is the service key (Wi-Fi password) 354 | * NULL = Open network 355 | * This is ignored when scheme is wifi_prov_scheme_ble 356 | */ 357 | const char * service_key = NULL; 358 | 359 | #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE 360 | 361 | /* This step is only useful when scheme is wifi_prov_scheme_ble. This will 362 | * set a custom 128 bit UUID which will be included in the BLE advertisement 363 | * and will correspond to the primary GATT service that provides provisioning 364 | * endpoints as GATT characteristics. Each GATT characteristic will be 365 | * formed using the primary service UUID as base, with different auto assigned 366 | * 12th and 13th bytes (assume counting starts from 0th byte). The client side 367 | * applications must identify the endpoints by reading the User Characteristic 368 | * Description descriptor (0x2901) for each characteristic, which contains the 369 | * endpoint name of the characteristic */ 370 | uint8_t custom_service_uuid[] = 371 | { 372 | /* This is a random uuid. This can be modified if you want to change the BLE uuid. */ 373 | /* 12th and 13th bit will be replaced by internal bits. */ 374 | 0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, 375 | 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02, 376 | }; 377 | err = wifi_prov_scheme_ble_set_service_uuid( custom_service_uuid ); 378 | 379 | if( err != ESP_OK ) 380 | { 381 | ESP_LOGE( TAG, "wifi_prov_scheme_ble_set_service_uuid failed %d", err ); 382 | return err; 383 | } 384 | #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ 385 | 386 | /* Start provisioning service */ 387 | ESP_ERROR_CHECK( wifi_prov_mgr_start_provisioning( security, pop, service_name, service_key ) ); 388 | /* Print QR code for provisioning */ 389 | #ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE 390 | app_wifi_print_qr( service_name, pop, PROV_TRANSPORT_BLE ); 391 | #else /* CONFIG_APP_WIFI_PROV_TRANSPORT_SOFTAP */ 392 | app_wifi_print_qr( service_name, pop, PROV_TRANSPORT_SOFTAP ); 393 | #endif /* CONFIG_APP_WIFI_PROV_TRANSPORT_BLE */ 394 | ESP_LOGI( TAG, "Provisioning Started. Name : %s, POP : %s", service_name, pop ); 395 | } 396 | else 397 | { 398 | ESP_LOGI( TAG, "Already provisioned, starting Wi-Fi STA" ); 399 | 400 | /* We don't need the manager as device is already provisioned, 401 | * so let's release it's resources */ 402 | wifi_prov_mgr_deinit(); 403 | 404 | /* Start Wi-Fi station */ 405 | wifi_init_sta(); 406 | } 407 | 408 | /* Wait for Wi-Fi connection */ 409 | vWaitOnWifiConnected(); 410 | return ESP_OK; 411 | } 412 | 413 | void vWaitOnWifiConnected( void ) 414 | { 415 | xEventGroupWaitBits( wifi_event_group, WIFI_CONNECTED_EVENT, false, true, portMAX_DELAY ); 416 | } 417 | -------------------------------------------------------------------------------- /main/networking/wifi/app_wifi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This example code is in the Public Domain (or CC0 licensed, at your option.) 3 | * 4 | * Unless required by applicable law or agreed to in writing, this 5 | * software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 6 | * CONDITIONS OF ANY KIND, either express or implied. 7 | */ 8 | #pragma once 9 | #include 10 | 11 | /* *INDENT-OFF* */ 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | /* *INDENT-ON* */ 16 | 17 | /** Types of Proof of Possession */ 18 | typedef enum 19 | { 20 | /** Use MAC address to generate PoP */ 21 | POP_TYPE_MAC, 22 | /** Use random stream generated and stored in the fctry partition during claiming process as PoP */ 23 | POP_TYPE_RANDOM 24 | } app_wifi_pop_type_t; 25 | 26 | void app_wifi_init(); 27 | esp_err_t app_wifi_start( app_wifi_pop_type_t pop_type ); 28 | 29 | esp_err_t app_wifi_connect(); 30 | bool app_wifi_is_connected(); 31 | void vWaitOnWifiConnected( void ); 32 | 33 | /* *INDENT-OFF* */ 34 | #ifdef __cplusplus 35 | } /* extern "C" */ 36 | #endif 37 | /* *INDENT-ON* */ 38 | -------------------------------------------------------------------------------- /main/qualification_app_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32-C3 FreeRTOS Reference Integration V202204.00 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /* Includes *******************************************************************/ 28 | 29 | /* Standard includes. */ 30 | #include 31 | 32 | /* FreeRTOS includes. */ 33 | #include 34 | #include 35 | #include 36 | 37 | /* ESP-IDF includes. */ 38 | #include 39 | #include 40 | #include 41 | 42 | /* coreMQTT-Agent network manager include. */ 43 | #include "core_mqtt_agent_manager.h" 44 | 45 | /* SubscribePublishUnsubscribeDemo demo includes. */ 46 | #include "sub_pub_unsub_demo.h" 47 | 48 | /* ESP Secure Certificate Manager include. */ 49 | #include "esp_secure_cert_read.h" 50 | 51 | /* Network transport include. */ 52 | #include "network_transport.h" 53 | 54 | /* Integration test includes */ 55 | #include "test_param_config.h" 56 | #include "test_execution_config.h" 57 | #include "qualification_test.h" 58 | #include "transport_interface_test.h" 59 | #include "mqtt_test.h" 60 | 61 | #define keyCLIENT_CERTIFICATE_PEM NULL 62 | #define keyCLIENT_PRIVATE_KEY_PEM NULL 63 | 64 | /* Use ROOT CA in binary. */ 65 | #ifndef ECHO_SERVER_ROOT_CA 66 | #define ECHO_SERVER_ROOT_CA NULL 67 | #endif 68 | 69 | /* Global variables ***********************************************************/ 70 | 71 | /** 72 | * @brief Logging tag for ESP-IDF logging functions. 73 | */ 74 | static const char * TAG = "qual_main"; 75 | 76 | /** 77 | * @brief The AWS RootCA1 passed in from ./certs/root_cert_auth.pem 78 | */ 79 | extern const uint8_t root_cert_auth_crt_start[] asm ( "_binary_root_cert_auth_crt_start" ); 80 | extern const uint8_t root_cert_auth_crt_end[] asm ( "_binary_root_cert_auth_crt_end" ); 81 | 82 | /** 83 | * @brief Socket send and receive timeouts to use. Specified in milliseconds. 84 | */ 85 | #define mqttexampleTRANSPORT_SEND_RECV_TIMEOUT_MS ( 750 ) 86 | 87 | #if ( MQTT_TEST_ENABLED == 1 ) || ( TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) 88 | static TransportInterface_t xTransport = { 0 }; 89 | static NetworkContext_t xSecondNetworkContext = { 0 }; 90 | #endif /* ( MQTT_TEST_ENABLED == 1 ) || ( TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) */ 91 | 92 | /** 93 | * @brief Global entry time into the application to use as a reference timestamp 94 | * in the #prvGetTimeMs function. #prvGetTimeMs will always return the difference 95 | * between the current time and the global entry time. This will reduce the chances 96 | * of overflow for the 32 bit unsigned integer used for holding the timestamp. 97 | */ 98 | static uint32_t ulGlobalEntryTimeMs; 99 | 100 | static BaseType_t prvInitializeNetworkContext( char * pcServerName, 101 | int xPort, 102 | char * pcCaCert, 103 | char * pcDeviceCert, 104 | char * pcDeviceKey ); 105 | /*-----------------------------------------------------------*/ 106 | 107 | 108 | #if ( MQTT_TEST_ENABLED == 1 ) || ( TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) 109 | static NetworkConnectStatus_t prvTransportNetworkConnect( void * pvNetworkContext, 110 | TestHostInfo_t * pxHostInfo, 111 | void * pvNetworkCredentials ) 112 | { 113 | ( void ) pvNetworkCredentials; 114 | 115 | ( ( NetworkContext_t * ) pvNetworkContext )->pcHostname = pxHostInfo->pHostName; 116 | ( ( NetworkContext_t * ) pvNetworkContext )->xPort = pxHostInfo->port; 117 | 118 | if( xTlsConnect( pvNetworkContext ) != TLS_TRANSPORT_SUCCESS ) 119 | { 120 | return NETWORK_CONNECT_FAILURE; 121 | } 122 | 123 | return NETWORK_CONNECT_SUCCESS; 124 | } 125 | #endif /* MQTT_TEST_ENABLED == 1 || TRANSPORT_INTERFACE_TEST_ENABLED == 1 */ 126 | 127 | #if ( MQTT_TEST_ENABLED == 1 ) || ( TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) 128 | static void prvTransportNetworkDisconnect( void * pNetworkContext ) 129 | { 130 | /* Disconnect the transport network. */ 131 | xTlsDisconnect( pNetworkContext ); 132 | } 133 | #endif /* MQTT_TEST_ENABLED == 1 || TRANSPORT_INTERFACE_TEST_ENABLED == 1 */ 134 | /*-----------------------------------------------------------*/ 135 | 136 | #if ( MQTT_TEST_ENABLED == 1 ) || ( TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) || \ 137 | ( DEVICE_ADVISOR_TEST_ENABLED == 1 ) 138 | static NetworkContext_t xNetworkContext = { 0 }; 139 | 140 | static BaseType_t prvInitializeNetworkContext( char * pcServerName, 141 | int xPort, 142 | char * pcCaCert, 143 | char * pcDeviceCert, 144 | char * pcDeviceKey ) 145 | { 146 | /* This is returned by this function. */ 147 | BaseType_t xRet = pdPASS; 148 | 149 | /* This is used to store the error return of ESP-IDF functions. */ 150 | esp_err_t xEspErrRet = ESP_OK; 151 | 152 | /* Verify that the MQTT endpoint and thing name have been configured by the 153 | * user. */ 154 | if( strlen( pcServerName ) == 0 ) 155 | { 156 | ESP_LOGE( TAG, "Empty endpoint for MQTT broker. Set endpoint by " 157 | "running idf.py menuconfig, then Golden Reference Integration -> " 158 | "Endpoint for MQTT Broker to use." ); 159 | xRet = pdFAIL; 160 | } 161 | 162 | /* Initialize first network context. */ 163 | xNetworkContext.pcHostname = pcServerName; 164 | xNetworkContext.xPort = xPort; 165 | 166 | /* Get the device certificate from esp_secure_crt_mgr and put into network 167 | * context. */ 168 | if( ( pcDeviceCert ) && ( strlen( pcDeviceCert ) > 0 ) ) 169 | { 170 | xNetworkContext.pcClientCert = pcDeviceCert; 171 | xNetworkContext.pcClientCertSize = strlen( pcDeviceCert ); 172 | } 173 | else 174 | { 175 | xEspErrRet = esp_secure_cert_get_device_cert( ( char ** ) &xNetworkContext.pcClientCert, 176 | &xNetworkContext.pcClientCertSize ); 177 | } 178 | 179 | if( xEspErrRet == ESP_OK ) 180 | { 181 | #if CONFIG_GRI_OUTPUT_CERTS_KEYS 182 | ESP_LOGI( TAG, "Qualification device Cert: \nLength: %d\n%s", 183 | strlen( xNetworkContext.pcClientCert ), 184 | xNetworkContext.pcClientCert ); 185 | #endif /* CONFIG_GRI_OUTPUT_CERTS_KEYS */ 186 | } 187 | else 188 | { 189 | ESP_LOGE( TAG, "Error in getting device certificate. Error: %s", 190 | esp_err_to_name( xEspErrRet ) ); 191 | 192 | xRet = pdFAIL; 193 | } 194 | 195 | /* Get the root CA certificate and put into network context. */ 196 | if( ( pcCaCert ) && ( strlen( pcCaCert ) > 0 ) ) 197 | { 198 | xNetworkContext.pcServerRootCA = pcCaCert; 199 | xNetworkContext.pcServerRootCASize = strlen( pcCaCert ); 200 | } 201 | else 202 | { 203 | xNetworkContext.pcServerRootCA = ( const char * ) root_cert_auth_crt_start; 204 | xNetworkContext.pcServerRootCASize = root_cert_auth_crt_end - root_cert_auth_crt_start; 205 | } 206 | 207 | if( xEspErrRet == ESP_OK ) 208 | { 209 | #if CONFIG_GRI_OUTPUT_CERTS_KEYS 210 | ESP_LOGI( TAG, "\nQualification CA Cert: \nLength: %d\n%s", 211 | ( int ) xNetworkContext.pcServerRootCASize, 212 | xNetworkContext.pcServerRootCA ); 213 | #endif /* CONFIG_GRI_OUTPUT_CERTS_KEYS */ 214 | } 215 | else 216 | { 217 | ESP_LOGE( TAG, "Error in getting CA certificate. Error: %s", 218 | esp_err_to_name( xEspErrRet ) ); 219 | 220 | xRet = pdFAIL; 221 | } 222 | 223 | #if CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL 224 | 225 | /* If the digital signature peripheral is being used, get the digital 226 | * signature peripheral context from esp_secure_crt_mgr and put into 227 | * network context. */ 228 | 229 | xNetworkContext.ds_data = esp_secure_cert_get_ds_ctx(); 230 | 231 | if( xNetworkContext.ds_data == NULL ) 232 | { 233 | ESP_LOGE( TAG, "Error in getting digital signature peripheral data." ); 234 | xRet = pdFAIL; 235 | } 236 | #else /* if CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL */ 237 | 238 | /* If the DS peripheral is not being used, get the device private key from 239 | * esp_secure_crt_mgr and put into network context. */ 240 | 241 | if( ( pcDeviceKey ) && ( strlen( pcDeviceKey ) > 0 ) ) 242 | { 243 | xNetworkContext.pcClientKey = pcDeviceKey; 244 | xNetworkContext.pcClientKeySize = strlen( pcDeviceKey ); 245 | } 246 | else 247 | { 248 | xEspErrRet = esp_secure_cert_get_priv_key( ( char ** ) &xNetworkContext.pcClientKey, 249 | &xNetworkContext.pcClientKeySize ); 250 | } 251 | 252 | if( xEspErrRet == ESP_OK ) 253 | { 254 | #if CONFIG_GRI_OUTPUT_CERTS_KEYS 255 | ESP_LOGI( TAG, "\nQualification private Key: \nLength: %d\n%s", 256 | ( int ) xNetworkContext.pcClientKeySize, 257 | xNetworkContext.pcClientKey ); 258 | #endif /* CONFIG_GRI_OUTPUT_CERTS_KEYS */ 259 | } 260 | else 261 | { 262 | ESP_LOGE( TAG, "Error in getting private key. Error: %s", 263 | esp_err_to_name( xEspErrRet ) ); 264 | 265 | xRet = pdFAIL; 266 | } 267 | #endif /* CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL */ 268 | 269 | xNetworkContext.pxTls = NULL; 270 | xNetworkContext.xTlsContextSemaphore = xSemaphoreCreateMutex(); 271 | 272 | if( xNetworkContext.xTlsContextSemaphore == NULL ) 273 | { 274 | ESP_LOGE( TAG, "Not enough memory to create TLS semaphore for global " 275 | "network context." ); 276 | 277 | xRet = pdFAIL; 278 | } 279 | 280 | /* Initialize second network context. */ 281 | #if ( MQTT_TEST_ENABLED == 1 ) || ( TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) 282 | xSecondNetworkContext.pcHostname = pcServerName; 283 | xSecondNetworkContext.xPort = xPort; 284 | 285 | /* Get the device certificate and put into second network context. */ 286 | if( ( pcDeviceCert ) && ( strlen( pcDeviceCert ) > 0 ) ) 287 | { 288 | xSecondNetworkContext.pcClientCert = pcDeviceCert; 289 | xSecondNetworkContext.pcClientCertSize = strlen( pcDeviceCert ); 290 | } 291 | else 292 | { 293 | xEspErrRet = esp_secure_cert_get_device_cert( ( char ** ) &xSecondNetworkContext.pcClientCert, 294 | &xSecondNetworkContext.pcClientCertSize ); 295 | } 296 | 297 | /* Get the root CA certificate and put into second network context. */ 298 | if( ( pcCaCert ) && ( strlen( pcCaCert ) > 0 ) ) 299 | { 300 | xSecondNetworkContext.pcServerRootCA = pcCaCert; 301 | xSecondNetworkContext.pcServerRootCASize = strlen( pcCaCert ); 302 | } 303 | else 304 | { 305 | xSecondNetworkContext.pcServerRootCA = ( const char * ) root_cert_auth_crt_start; 306 | xSecondNetworkContext.pcServerRootCASize = root_cert_auth_crt_end - root_cert_auth_crt_start; 307 | } 308 | 309 | #if CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL 310 | 311 | /* If the digital signature peripheral is being used, get the digital 312 | * signature peripheral context from esp_secure_crt_mgr and put into 313 | * second network context. */ 314 | 315 | xSecondNetworkContext.ds_data = esp_secure_cert_get_ds_ctx(); 316 | 317 | if( xSecondNetworkContext.ds_data == NULL ) 318 | { 319 | ESP_LOGE( TAG, "Error in getting digital signature peripheral data." ); 320 | xRet = pdFAIL; 321 | } 322 | #else /* if CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL */ 323 | 324 | /* If the DS peripheral is not being used, get the device private key from 325 | * esp_secure_crt_mgr and put into second network context. */ 326 | 327 | if( ( pcDeviceKey ) && ( strlen( pcDeviceKey ) > 0 ) ) 328 | { 329 | xSecondNetworkContext.pcClientKey = pcDeviceKey; 330 | xSecondNetworkContext.pcClientKeySize = strlen( pcDeviceKey ); 331 | } 332 | else 333 | { 334 | xEspErrRet = esp_secure_cert_get_priv_key( ( char ** ) &xSecondNetworkContext.pcClientKey, 335 | &xSecondNetworkContext.pcClientKeySize ); 336 | } 337 | 338 | if( xEspErrRet == ESP_OK ) 339 | { 340 | /* Do nothing. Private key was printed at main.c. */ 341 | } 342 | else 343 | { 344 | ESP_LOGE( TAG, "Error in getting private key. Error: %s", 345 | esp_err_to_name( xEspErrRet ) ); 346 | 347 | xRet = pdFAIL; 348 | } 349 | #endif /* CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL */ 350 | 351 | xSecondNetworkContext.pxTls = NULL; 352 | xSecondNetworkContext.xTlsContextSemaphore = xSemaphoreCreateMutex(); 353 | 354 | if( xSecondNetworkContext.xTlsContextSemaphore == NULL ) 355 | { 356 | ESP_LOGE( TAG, "Not enough memory to create TLS semaphore for global " 357 | "second network context." ); 358 | 359 | xRet = pdFAIL; 360 | } 361 | #endif /* ( MQTT_TEST_ENABLED == 1 ) || ( TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) */ 362 | 363 | return xRet; 364 | } 365 | #endif /* ( MQTT_TEST_ENABLED == 1 ) || ( TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) || 366 | * ( DEVICE_ADVISOR_TEST_ENABLED == 1 ) */ 367 | /*-----------------------------------------------------------*/ 368 | 369 | uint32_t MqttTestGetTimeMs( void ) 370 | { 371 | TickType_t xTickCount = 0; 372 | uint32_t ulTimeMs = 0UL; 373 | 374 | /* Get the current tick count. */ 375 | xTickCount = xTaskGetTickCount(); 376 | 377 | /* Convert the ticks to milliseconds. */ 378 | ulTimeMs = ( uint32_t ) ( xTickCount * 1000 / configTICK_RATE_HZ ); 379 | 380 | /* Reduce ulGlobalEntryTimeMs from obtained time so as to always return the 381 | * elapsed time in the application. */ 382 | ulTimeMs = ( uint32_t ) ( ulTimeMs - ulGlobalEntryTimeMs ); 383 | 384 | return ulTimeMs; 385 | } 386 | /*-----------------------------------------------------------*/ 387 | 388 | #if ( MQTT_TEST_ENABLED == 1 ) 389 | void SetupMqttTestParam( MqttTestParam_t * pTestParam ) 390 | { 391 | configASSERT( pTestParam != NULL ); 392 | 393 | /* Initialization of timestamp for MQTT. */ 394 | ulGlobalEntryTimeMs = MqttTestGetTimeMs(); 395 | 396 | /* Setup the transport interface. */ 397 | xTransport.send = espTlsTransportSend; 398 | xTransport.recv = espTlsTransportRecv; 399 | 400 | pTestParam->pTransport = &xTransport; 401 | pTestParam->pNetworkContext = &xNetworkContext; 402 | pTestParam->pSecondNetworkContext = &xSecondNetworkContext; 403 | pTestParam->pNetworkConnect = prvTransportNetworkConnect; 404 | pTestParam->pNetworkDisconnect = prvTransportNetworkDisconnect; 405 | pTestParam->pGetTimeMs = MqttTestGetTimeMs; 406 | } 407 | #endif /* TRANSPORT_INTERFACE_TEST_ENABLED == 1 */ 408 | /*-----------------------------------------------------------*/ 409 | 410 | #if ( TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) 411 | void SetupTransportTestParam( TransportTestParam_t * pTestParam ) 412 | { 413 | configASSERT( pTestParam != NULL ); 414 | 415 | /* Setup the transport interface. */ 416 | xTransport.send = espTlsTransportSend; 417 | xTransport.recv = espTlsTransportRecv; 418 | 419 | pTestParam->pTransport = &xTransport; 420 | pTestParam->pNetworkContext = &xNetworkContext; 421 | pTestParam->pSecondNetworkContext = &xSecondNetworkContext; 422 | pTestParam->pNetworkConnect = prvTransportNetworkConnect; 423 | pTestParam->pNetworkDisconnect = prvTransportNetworkDisconnect; 424 | } 425 | #endif /* if ( TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) */ 426 | 427 | /*-----------------------------------------------------------*/ 428 | 429 | void runQualification( void * pvArgs ) 430 | { 431 | ( void ) pvArgs; 432 | 433 | ESP_LOGI( TAG, "Run qualification test." ); 434 | 435 | RunQualificationTest(); 436 | 437 | ESP_LOGI( TAG, "End qualification test." ); 438 | 439 | for( ; ; ) 440 | { 441 | vTaskDelay( pdMS_TO_TICKS( 30000UL ) ); 442 | } 443 | 444 | vTaskDelete( NULL ); 445 | } 446 | /*-----------------------------------------------------------*/ 447 | 448 | BaseType_t xQualificationStart( void ) 449 | { 450 | BaseType_t xRet = pdPASS; 451 | 452 | ESP_LOGE( TAG, "Run xQualificationStart" ); 453 | 454 | #if ( MQTT_TEST_ENABLED == 1 ) || ( DEVICE_ADVISOR_TEST_ENABLED == 1 ) 455 | prvInitializeNetworkContext( MQTT_SERVER_ENDPOINT, MQTT_SERVER_PORT, NULL, keyCLIENT_CERTIFICATE_PEM, keyCLIENT_PRIVATE_KEY_PEM ); 456 | #endif /* ( MQTT_TEST_ENABLED == 1 ) || ( DEVICE_ADVISOR_TEST_ENABLED == 1 ) */ 457 | 458 | #if ( TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) 459 | #if defined( TRANSPORT_CLIENT_PRIVATE_KEY ) 460 | prvInitializeNetworkContext( ECHO_SERVER_ENDPOINT, ECHO_SERVER_PORT, ECHO_SERVER_ROOT_CA, TRANSPORT_CLIENT_CERTIFICATE, TRANSPORT_CLIENT_PRIVATE_KEY ); 461 | #else 462 | prvInitializeNetworkContext( ECHO_SERVER_ENDPOINT, ECHO_SERVER_PORT, ECHO_SERVER_ROOT_CA, keyCLIENT_CERTIFICATE_PEM, keyCLIENT_PRIVATE_KEY_PEM ); 463 | #endif /* defined( TRANSPORT_CLIENT_PRIVATE_KEY ) */ 464 | #endif /* TRANSPORT_INTERFACE_TEST_ENABLED == 1 ) */ 465 | 466 | #if ( DEVICE_ADVISOR_TEST_ENABLED == 1 ) 467 | if( xRet == pdPASS ) 468 | { 469 | vStartSubscribePublishUnsubscribeDemo(); 470 | } 471 | #endif /* ( DEVICE_ADVISOR_TEST_ENABLED == 1 ) */ 472 | 473 | #if ( DEVICE_ADVISOR_TEST_ENABLED == 1 ) 474 | if( xRet == pdPASS ) 475 | { 476 | xRet = xCoreMqttAgentManagerStart( &xNetworkContext ); 477 | 478 | if( xRet != pdPASS ) 479 | { 480 | ESP_LOGE( TAG, "Failed to initialize and start coreMQTT-Agent network " 481 | "manager." ); 482 | 483 | configASSERT( xRet == pdPASS ); 484 | } 485 | } 486 | #endif /* ( DEVICE_ADVISOR_TEST_ENABLED == 1 ) */ 487 | 488 | if( ( xRet = xTaskCreate( runQualification, 489 | "QualTask", 490 | 8192, 491 | NULL, 492 | 1, 493 | NULL ) ) != pdPASS ) 494 | { 495 | ESP_LOGE( TAG, "Failed to start Qualification task: errno=%d", xRet ); 496 | 497 | configASSERT( 0 ); 498 | } 499 | 500 | return xRet; 501 | } 502 | /*-----------------------------------------------------------*/ 503 | 504 | #if ( DEVICE_ADVISOR_TEST_ENABLED == 1 ) 505 | int RunDeviceAdvisorDemo( void ) 506 | { 507 | return 0; 508 | } 509 | #endif /* DEVICE_ADVISOR_TEST_ENABLED == 1 */ 510 | /*-----------------------------------------------------------*/ 511 | -------------------------------------------------------------------------------- /manifest.yml: -------------------------------------------------------------------------------- 1 | name : "FreeRTOS ESP32C3 Reference Integration" 2 | version: "202407.00" 3 | description: |- 4 | "Reference IoT integration project using the Espressif ESP32C3 and FreeRTOS LTS libraries" 5 | dependencies: 6 | - name: "FreeRTOS-Libraries-Integration-Tests" 7 | version: "202406.00" 8 | repository: 9 | type: "git" 10 | url: "https://github.com/FreeRTOS/FreeRTOS-Libraries-Integration-Tests" 11 | path: "components/FreeRTOS-Libraries-Integration-Tests/FreeRTOS-Libraries-Integration-Tests" 12 | - name: "esp-aws-iot" 13 | version: "cd1bd3b654f7cf6393bb92100bb7916cf9152c06" 14 | repository: 15 | type: "git" 16 | url: "https://github.com/espressif/esp-aws-iot.git" 17 | path: "components/esp-aws-iot" 18 | -------------------------------------------------------------------------------- /partitions.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | esp_secure_cert, 0x3F, , 0xD000, 0x2000, encrypted 4 | nvs, data, nvs, 0x13000, 0x6000, 5 | otadata, data, ota, 0x19000, 0x2000, encrypted 6 | phy_init, data, phy, 0x1b000, 0x1000, encrypted 7 | ota_0, app, ota_0, 0x20000, 0x190000, encrypted 8 | ota_1, app, ota_1, 0x1b0000, 0x190000, encrypted 9 | storage, data, nvs, , 0x10000, encrypted 10 | nvs_key, data, nvs_keys,, 0x1000, encrypted -------------------------------------------------------------------------------- /sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_IDF_TARGET=esp32c3 2 | CONFIG_PARTITION_TABLE_CUSTOM=y 3 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" 4 | CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" 5 | CONFIG_PARTITION_TABLE_OFFSET=0xb000 6 | CONFIG_APP_WIFI_PROV_SHOW_QR=y 7 | CONFIG_APP_WIFI_PROV_TRANSPORT_BLE=y 8 | CONFIG_APP_WIFI_PROV_TRANSPORT=2 9 | CONFIG_GRI_ENABLE_SIMPLE_PUB_SUB_DEMO=y 10 | CONFIG_GRI_ENABLE_TEMPERATURE_LED_PUB_SUB_DEMO=y 11 | CONFIG_GRI_ENABLE_OTA_DEMO=y 12 | CONFIG_BT_ENABLED=y 13 | CONFIG_BT_NIMBLE_ENABLED=y 14 | CONFIG_MBEDTLS_THREADING_C=y 15 | CONFIG_MBEDTLS_THREADING_ALT=n 16 | CONFIG_MBEDTLS_THREADING_PTHREAD=y 17 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 18 | CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y 19 | CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y 20 | CONFIG_OTA_DATA_OVER_HTTP=n 21 | CONFIG_OTA_DATA_OVER_MQTT=y 22 | CONFIG_OTA_DATA_OVER_MQTT_PRIMARY=y 23 | CONFIG_OTA_PRIMARY_DATA_PROTOCOL=1 24 | CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n 25 | CONFIG_ESP_SECURE_CERT_SUPPORT_LEGACY_FORMATS=y 26 | CONFIG_GRI_SUB_PUB_UNSUB_DEMO_MAX_COMMAND_SEND_BLOCK_TIME_MS=10000 27 | CONFIG_GRI_SUB_PUB_UNSUB_DEMO_DELAY_BETWEEN_SUB_PUB_UNSUB_LOOPS_MS=10000 28 | CONFIG_GRI_MQTT_AGENT_CONNACK_RECV_TIMEOUT_MS=10000 29 | 30 | # Set optimization for size 31 | CONFIG_COMPILER_OPTIMIZATION_SIZE=y 32 | 33 | # Set default FreeRTOS Stack sizes 34 | CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=1536 35 | CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024 36 | 37 | # LWIP config 38 | CONFIG_LWIP_MAX_SOCKETS=8 39 | 40 | # AWS OTA 41 | CONFIG_LOG2_FILE_BLOCK_SIZE=12 42 | CONFIG_MAX_NUM_BLOCKS_REQUEST=8 43 | CONFIG_GRI_OTA_MAX_NUM_DATA_BUFFERS=2 44 | CONFIG_ALLOW_DOWNGRADE=0 45 | CONFIG_OTA_DATA_OVER_MQTT=y 46 | # CONFIG_OTA_DATA_OVER_HTTP is not set 47 | CONFIG_OTA_DATA_OVER_MQTT_PRIMARY=y 48 | CONFIG_OTA_PRIMARY_DATA_PROTOCOL=1 49 | 50 | # MbedTLS Config Options 51 | CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=n 52 | # CONFIG_MBEDTLS_TLS_SERVER_ONLY is not set 53 | # CONFIG_MBEDTLS_TLS_CLIENT_ONLY is not set 54 | # CONFIG_MBEDTLS_TLS_DISABLED is not set 55 | CONFIG_MBEDTLS_TLS_SERVER=n 56 | CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS=n 57 | CONFIG_MBEDTLS_TLS_CLIENT=y 58 | CONFIG_MBEDTLS_TLS_ENABLED=y 59 | 60 | 61 | # 62 | # Unity unit testing library 63 | # 64 | CONFIG_UNITY_ENABLE_FIXTURE=y --------------------------------------------------------------------------------