diff --git a/.github/workflows/hil.yml b/.github/workflows/hil.yml index 4f3d3ac4df9..9d864b2c67e 100644 --- a/.github/workflows/hil.yml +++ b/.github/workflows/hil.yml @@ -270,15 +270,10 @@ jobs: event_file: name: "Event File" - if: | - contains(github.event.pull_request.labels.*.name, 'hil_test') || - contains(github.event.pull_request.labels.*.name, 'perf_test') || - github.event_name == 'schedule' - needs: hardware-test runs-on: ubuntu-latest steps: - name: Upload uses: actions/upload-artifact@v4 with: - name: Event File + name: event_file path: ${{github.event_path}} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 026c9d59094..4a9937fa8f2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -33,6 +33,6 @@ jobs: uses: EnricoMi/publish-unit-test-result-action@v1 with: commit: ${{ github.event.workflow_run.head_sha }} - event_file: artifacts/Event File/event.json + event_file: artifacts/event_file/event.json event_name: ${{ github.event.workflow_run.event }} files: "artifacts/**/*.xml" diff --git a/.github/workflows/wokwi.yml b/.github/workflows/wokwi.yml index 22252352382..1f55235dd39 100644 --- a/.github/workflows/wokwi.yml +++ b/.github/workflows/wokwi.yml @@ -15,17 +15,37 @@ env: WOKWI_CLI_TOKEN: ${{ secrets.WOKWI_CLI_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -concurrency: - group: wokwi-${{github.event.pull_request.number || github.ref}} - cancel-in-progress: true - jobs: + get_event_file: + name: Get event file + runs-on: ubuntu-latest + outputs: + ref: ${{ steps.get-ref.outputs.ref }} + steps: + - name: Download event file + uses: actions/download-artifact@v4 + with: + run-id: ${{github.event.workflow_run.id}} + github-token: ${{env.GITHUB_TOKEN}} + name: event_file + + - name: Get ref + id: get-ref + run: | + PR_NUMBER=$(jq -r '.number' event.json) + echo "PR_NUMBER = $PR_NUMBER" + echo "ref=$PR_NUMBER" >> $GITHUB_OUTPUT + gen_chunks: if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' name: Generate Chunks matrix runs-on: ubuntu-latest + needs: get_event_file outputs: chunks: ${{ steps.gen-chunks.outputs.chunks }} + concurrency: + group: wokwi-${{ needs.get_event_file.outputs.ref || github.ref }} + cancel-in-progress: true steps: - name: Checkout Repository uses: actions/checkout@v4 @@ -47,8 +67,11 @@ jobs: echo "chunks=${CHUNKS}" >>$GITHUB_OUTPUT wokwi-test: - needs: [gen_chunks] + needs: [get_event_file, gen_chunks] name: ${{matrix.chip}}-Wokwi_Test#${{matrix.chunks}} + concurrency: + group: wokwi-${{ needs.get_event_file.outputs.ref || github.ref }}-${{matrix.chip}}-${{matrix.chunks}} + cancel-in-progress: true strategy: fail-fast: false matrix: @@ -101,7 +124,10 @@ jobs: report-result: name: Report wokwi test result runs-on: ubuntu-latest - needs: wokwi-test + needs: [get_event_file, wokwi-test] + concurrency: + group: wokwi-${{ needs.get_event_file.outputs.ref || github.ref }} + cancel-in-progress: true if: always() && github.event.workflow_run.event == 'pull_request' steps: - name: Report result @@ -127,4 +153,4 @@ jobs: target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' })).data; core.info(`${name} is ${state}`); - + diff --git a/.gitignore b/.gitignore index 67ae15c2bf9..1519de52764 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,7 @@ libraries/Insights/examples/*/*.ino.zip !.vale/styles/Vocab/ .vale/styles/Vocab/* !.vale/styles/Vocab/Espressif/ + +# Ignore Lib Builder Docker run scripts +/run.sh +/run.ps1 diff --git a/README.md b/README.md index 940a9b7102b..6f4f9b1ba16 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,10 @@ Here are the ESP32 series supported by the Arduino-ESP32 project: | ESP32-C6 | No | Yes | [ESP32-C6](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf) | | ESP32-H2 | No | Yes | [ESP32-H2](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf) | +> [!NOTE] +> ESP32-C2 is also supported by Arduino-ESP32 but requires rebuilding the static libraries. This is not trivial and requires a good understanding of the ESP-IDF +> build system. For more information, see the [Lib Builder documentation](https://docs.espressif.com/projects/arduino-esp32/en/latest/lib_builder.html). + For more details visit the [supported chips](https://docs.espressif.com/projects/arduino-esp32/en/latest/getting_started.html#supported-soc-s) documentation page. ### Decoding exceptions diff --git a/boards.txt b/boards.txt index ec96b8ad34c..a1126b16f23 100644 --- a/boards.txt +++ b/boards.txt @@ -317,10 +317,10 @@ esp32h2.menu.ZigbeeMode.default.build.zigbee_mode= esp32h2.menu.ZigbeeMode.default.build.zigbee_libs= esp32h2.menu.ZigbeeMode.ed=Zigbee ED (end device) esp32h2.menu.ZigbeeMode.ed.build.zigbee_mode=-DZIGBEE_MODE_ED -esp32h2.menu.ZigbeeMode.ed.build.zigbee_libs=-lesp_zb_api_ed -lesp_zb_cli_command -lzboss_stack.ed.trace -lzboss_stack.ed -lzboss_port +esp32h2.menu.ZigbeeMode.ed.build.zigbee_libs=-lesp_zb_api_ed -lesp_zb_cli_command -lzboss_stack.ed -lzboss_port esp32h2.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) esp32h2.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -esp32h2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +esp32h2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port esp32h2.menu.ZigbeeMode.rcp=Zigbee RCP (radio co-processor) esp32h2.menu.ZigbeeMode.rcp.build.zigbee_mode=-DZIGBEE_MODE_RCP esp32h2.menu.ZigbeeMode.rcp.build.zigbee_libs=-lesp_zb_api_rcp -lesp_zb_cli_command -lzboss_stack.rcp -lzboss_port @@ -504,10 +504,10 @@ esp32c6.menu.ZigbeeMode.default.build.zigbee_mode= esp32c6.menu.ZigbeeMode.default.build.zigbee_libs= esp32c6.menu.ZigbeeMode.ed=Zigbee ED (end device) esp32c6.menu.ZigbeeMode.ed.build.zigbee_mode=-DZIGBEE_MODE_ED -esp32c6.menu.ZigbeeMode.ed.build.zigbee_libs=-lesp_zb_api_ed -lesp_zb_cli_command -lzboss_stack.ed.trace -lzboss_stack.ed -lzboss_port +esp32c6.menu.ZigbeeMode.ed.build.zigbee_libs=-lesp_zb_api_ed -lesp_zb_cli_command -lzboss_stack.ed -lzboss_port esp32c6.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) esp32c6.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -esp32c6.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +esp32c6.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port esp32c6.menu.ZigbeeMode.rcp=Zigbee RCP (radio co-processor) esp32c6.menu.ZigbeeMode.rcp.build.zigbee_mode=-DZIGBEE_MODE_RCP esp32c6.menu.ZigbeeMode.rcp.build.zigbee_libs=-lesp_zb_api_rcp -lesp_zb_cli_command -lzboss_stack.rcp -lzboss_port @@ -756,7 +756,7 @@ esp32s3.menu.ZigbeeMode.default.build.zigbee_mode= esp32s3.menu.ZigbeeMode.default.build.zigbee_libs= esp32s3.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) esp32s3.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -esp32s3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +esp32s3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## @@ -931,7 +931,8 @@ esp32c3.menu.ZigbeeMode.default.build.zigbee_mode= esp32c3.menu.ZigbeeMode.default.build.zigbee_libs= esp32c3.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) esp32c3.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -esp32c3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +esp32c3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port + ############################################################## esp32s2.name=ESP32S2 Dev Module @@ -1128,7 +1129,7 @@ esp32s2.menu.ZigbeeMode.default.build.zigbee_mode= esp32s2.menu.ZigbeeMode.default.build.zigbee_libs= esp32s2.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) esp32s2.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## @@ -1315,7 +1316,7 @@ esp32.menu.ZigbeeMode.default.build.zigbee_mode= esp32.menu.ZigbeeMode.default.build.zigbee_libs= esp32.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) esp32.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -esp32.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +esp32.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## @@ -10630,7 +10631,7 @@ adafruit_metro_esp32s2.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_metro_esp32s2.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_metro_esp32s2.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_metro_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_metro_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_metro_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit Metro ESP32-S3 @@ -10827,7 +10828,7 @@ adafruit_metro_esp32s3.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_metro_esp32s3.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_metro_esp32s3.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_metro_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_metro_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_metro_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit MagTag 2.9" @@ -11004,7 +11005,7 @@ adafruit_magtag29_esp32s2.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_magtag29_esp32s2.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_magtag29_esp32s2.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_magtag29_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_magtag29_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_magtag29_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit FunHouse @@ -11181,7 +11182,7 @@ adafruit_funhouse_esp32s2.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_funhouse_esp32s2.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_funhouse_esp32s2.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_funhouse_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_funhouse_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_funhouse_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit ESP32 Feather @@ -11315,7 +11316,7 @@ featheresp32.menu.ZigbeeMode.default.build.zigbee_mode= featheresp32.menu.ZigbeeMode.default.build.zigbee_libs= featheresp32.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) featheresp32.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -featheresp32.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +featheresp32.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit Feather ESP32 V2 @@ -11433,7 +11434,7 @@ adafruit_feather_esp32_v2.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_feather_esp32_v2.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_feather_esp32_v2.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_feather_esp32_v2.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_feather_esp32_v2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_feather_esp32_v2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit Feather ESP32-S2 @@ -11610,7 +11611,7 @@ adafruit_feather_esp32s2.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_feather_esp32s2.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_feather_esp32s2.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_feather_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_feather_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_feather_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit Feather ESP32-S2 TFT @@ -11787,7 +11788,7 @@ adafruit_feather_esp32s2_tft.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_feather_esp32s2_tft.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_feather_esp32s2_tft.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_feather_esp32s2_tft.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_feather_esp32s2_tft.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_feather_esp32s2_tft.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit Feather ESP32-S2 Reverse TFT @@ -11964,7 +11965,7 @@ adafruit_feather_esp32s2_reversetft.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_feather_esp32s2_reversetft.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_feather_esp32s2_reversetft.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_feather_esp32s2_reversetft.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_feather_esp32s2_reversetft.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_feather_esp32s2_reversetft.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit Feather ESP32-S3 2MB PSRAM @@ -12176,7 +12177,7 @@ adafruit_feather_esp32s3.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_feather_esp32s3.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_feather_esp32s3.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_feather_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_feather_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_feather_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit Feather ESP32-S3 No PSRAM @@ -12357,7 +12358,7 @@ adafruit_feather_esp32s3_nopsram.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_feather_esp32s3_nopsram.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_feather_esp32s3_nopsram.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_feather_esp32s3_nopsram.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_feather_esp32s3_nopsram.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_feather_esp32s3_nopsram.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit Feather ESP32-S3 TFT @@ -12569,7 +12570,7 @@ adafruit_feather_esp32s3_tft.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_feather_esp32s3_tft.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_feather_esp32s3_tft.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_feather_esp32s3_tft.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_feather_esp32s3_tft.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_feather_esp32s3_tft.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit Feather ESP32-S3 Reverse TFT @@ -12781,7 +12782,7 @@ adafruit_feather_esp32s3_reversetft.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_feather_esp32s3_reversetft.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_feather_esp32s3_reversetft.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_feather_esp32s3_reversetft.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_feather_esp32s3_reversetft.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_feather_esp32s3_reversetft.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit QT Py ESP32 @@ -12899,7 +12900,7 @@ adafruit_qtpy_esp32_pico.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_qtpy_esp32_pico.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_qtpy_esp32_pico.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_qtpy_esp32_pico.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_qtpy_esp32_pico.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_qtpy_esp32_pico.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit QT Py ESP32-C3 @@ -13036,7 +13037,7 @@ adafruit_qtpy_esp32c3.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_qtpy_esp32c3.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_qtpy_esp32c3.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_qtpy_esp32c3.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_qtpy_esp32c3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_qtpy_esp32c3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit QT Py ESP32-S2 @@ -13213,7 +13214,7 @@ adafruit_qtpy_esp32s2.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_qtpy_esp32s2.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_qtpy_esp32s2.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_qtpy_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_qtpy_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_qtpy_esp32s2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit QT Py ESP32-S3 No PSRAM @@ -13394,7 +13395,7 @@ adafruit_qtpy_esp32s3_nopsram.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_qtpy_esp32s3_nopsram.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_qtpy_esp32s3_nopsram.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_qtpy_esp32s3_nopsram.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_qtpy_esp32s3_nopsram.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_qtpy_esp32s3_nopsram.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit QT Py ESP32-S3 (4M Flash 2M PSRAM) @@ -13606,7 +13607,7 @@ adafruit_qtpy_esp32s3_n4r2.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_qtpy_esp32s3_n4r2.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_qtpy_esp32s3_n4r2.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_qtpy_esp32s3_n4r2.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_qtpy_esp32s3_n4r2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_qtpy_esp32s3_n4r2.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit ItsyBitsy ESP32 @@ -13724,7 +13725,7 @@ adafruit_itsybitsy_esp32.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_itsybitsy_esp32.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_itsybitsy_esp32.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_itsybitsy_esp32.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_itsybitsy_esp32.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_itsybitsy_esp32.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit MatrixPortal ESP32-S3 @@ -13915,7 +13916,7 @@ adafruit_matrixportal_esp32s3.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_matrixportal_esp32s3.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_matrixportal_esp32s3.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_matrixportal_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_matrixportal_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_matrixportal_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit pyCamera S3 @@ -14127,7 +14128,7 @@ adafruit_camera_esp32s3.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_camera_esp32s3.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_camera_esp32s3.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_camera_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_camera_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_camera_esp32s3.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## # Adafruit Qualia ESP32-S3 RGB666 @@ -14324,7 +14325,7 @@ adafruit_qualia_s3_rgb666.menu.ZigbeeMode.default.build.zigbee_mode= adafruit_qualia_s3_rgb666.menu.ZigbeeMode.default.build.zigbee_libs= adafruit_qualia_s3_rgb666.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) adafruit_qualia_s3_rgb666.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -adafruit_qualia_s3_rgb666.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +adafruit_qualia_s3_rgb666.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## @@ -14777,7 +14778,7 @@ nologo_esp32s3_pico.menu.ZigbeeMode.default.build.zigbee_mode= nologo_esp32s3_pico.menu.ZigbeeMode.default.build.zigbee_libs= nologo_esp32s3_pico.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) nologo_esp32s3_pico.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -nologo_esp32s3_pico.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +nologo_esp32s3_pico.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## @@ -16816,10 +16817,10 @@ esp32h2-devkitlipo.menu.ZigbeeMode.default.build.zigbee_mode= esp32h2-devkitlipo.menu.ZigbeeMode.default.build.zigbee_libs= esp32h2-devkitlipo.menu.ZigbeeMode.ed=Zigbee ED (end device) esp32h2-devkitlipo.menu.ZigbeeMode.ed.build.zigbee_mode=-DZIGBEE_MODE_ED -esp32h2-devkitlipo.menu.ZigbeeMode.ed.build.zigbee_libs=-lesp_zb_api_ed -lesp_zb_cli_command -lzboss_stack.ed.trace -lzboss_stack.ed -lzboss_port +esp32h2-devkitlipo.menu.ZigbeeMode.ed.build.zigbee_libs=-lesp_zb_api_ed -lesp_zb_cli_command -lzboss_stack.ed -lzboss_port esp32h2-devkitlipo.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) esp32h2-devkitlipo.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -esp32h2-devkitlipo.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +esp32h2-devkitlipo.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port esp32h2-devkitlipo.menu.ZigbeeMode.rcp=Zigbee RCP (radio co-processor) esp32h2-devkitlipo.menu.ZigbeeMode.rcp.build.zigbee_mode=-DZIGBEE_MODE_RCP esp32h2-devkitlipo.menu.ZigbeeMode.rcp.build.zigbee_libs=-lesp_zb_api_rcp -lesp_zb_cli_command -lzboss_stack.rcp -lzboss_port @@ -17009,7 +17010,7 @@ esp32-sbc-fabgl.menu.ZigbeeMode.default.build.zigbee_mode= esp32-sbc-fabgl.menu.ZigbeeMode.default.build.zigbee_libs= esp32-sbc-fabgl.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) esp32-sbc-fabgl.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -esp32-sbc-fabgl.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +esp32-sbc-fabgl.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port ############################################################## @@ -30830,10 +30831,10 @@ XIAO_ESP32C6.menu.ZigbeeMode.default.build.zigbee_mode= XIAO_ESP32C6.menu.ZigbeeMode.default.build.zigbee_libs= XIAO_ESP32C6.menu.ZigbeeMode.ed=Zigbee ED (end device) XIAO_ESP32C6.menu.ZigbeeMode.ed.build.zigbee_mode=-DZIGBEE_MODE_ED -XIAO_ESP32C6.menu.ZigbeeMode.ed.build.zigbee_libs=-lesp_zb_api_ed -lesp_zb_cli_command -lzboss_stack.ed.trace -lzboss_stack.ed -lzboss_port +XIAO_ESP32C6.menu.ZigbeeMode.ed.build.zigbee_libs=-lesp_zb_api_ed -lesp_zb_cli_command -lzboss_stack.ed -lzboss_port XIAO_ESP32C6.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) XIAO_ESP32C6.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -XIAO_ESP32C6.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +XIAO_ESP32C6.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port XIAO_ESP32C6.menu.ZigbeeMode.rcp=Zigbee RCP (radio co-processor) XIAO_ESP32C6.menu.ZigbeeMode.rcp.build.zigbee_mode=-DZIGBEE_MODE_RCP XIAO_ESP32C6.menu.ZigbeeMode.rcp.build.zigbee_libs=-lesp_zb_api_rcp -lesp_zb_cli_command -lzboss_stack.rcp -lzboss_port @@ -35981,10 +35982,10 @@ epulse_feather_c6.menu.ZigbeeMode.default.build.zigbee_mode= epulse_feather_c6.menu.ZigbeeMode.default.build.zigbee_libs= epulse_feather_c6.menu.ZigbeeMode.ed=Zigbee ED (end device) epulse_feather_c6.menu.ZigbeeMode.ed.build.zigbee_mode=-DZIGBEE_MODE_ED -epulse_feather_c6.menu.ZigbeeMode.ed.build.zigbee_libs=-lesp_zb_api_ed -lesp_zb_cli_command -lzboss_stack.ed.trace -lzboss_stack.ed -lzboss_port +epulse_feather_c6.menu.ZigbeeMode.ed.build.zigbee_libs=-lesp_zb_api_ed -lesp_zb_cli_command -lzboss_stack.ed -lzboss_port epulse_feather_c6.menu.ZigbeeMode.zczr=Zigbee ZCZR (coordinator) epulse_feather_c6.menu.ZigbeeMode.zczr.build.zigbee_mode=-DZIGBEE_MODE_ZCZR -epulse_feather_c6.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr.trace -lzboss_stack.zczr -lzboss_port +epulse_feather_c6.menu.ZigbeeMode.zczr.build.zigbee_libs=-lesp_zb_api_zczr -lesp_zb_cli_command -lzboss_stack.zczr -lzboss_port epulse_feather_c6.menu.ZigbeeMode.rcp=Zigbee RCP (radio co-processor) epulse_feather_c6.menu.ZigbeeMode.rcp.build.zigbee_mode=-DZIGBEE_MODE_RCP epulse_feather_c6.menu.ZigbeeMode.rcp.build.zigbee_libs=-lesp_zb_api_rcp -lesp_zb_cli_command -lzboss_stack.rcp -lzboss_port diff --git a/cores/esp32/HWCDC.cpp b/cores/esp32/HWCDC.cpp index cd6ce46db55..b0f653e889e 100644 --- a/cores/esp32/HWCDC.cpp +++ b/cores/esp32/HWCDC.cpp @@ -39,8 +39,9 @@ static intr_handle_t intr_handle = NULL; static SemaphoreHandle_t tx_lock = NULL; static volatile bool connected = false; -static volatile unsigned long lastSOF_ms; -static volatile uint8_t SOF_TIMEOUT; +// SOF in ISR causes problems for uploading firmware +//static volatile unsigned long lastSOF_ms; +//static volatile uint8_t SOF_TIMEOUT; // timeout has no effect when USB CDC is unplugged static uint32_t tx_timeout_ms = 100; @@ -90,7 +91,7 @@ static void hw_cdc_isr_handler(void *arg) { if (tx_ring_buf != NULL && usb_serial_jtag_ll_txfifo_writable() == 1) { // We disable the interrupt here so that the interrupt won't be triggered if there is no data to send. usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); - size_t queued_size; + size_t queued_size = 0; uint8_t *queued_buff = (uint8_t *)xRingbufferReceiveUpToFromISR(tx_ring_buf, &queued_size, 64); // If the hardware fifo is available, write in it. Otherwise, do nothing. if (queued_buff != NULL) { //Although tx_queued_bytes may be larger than 0. We may have interrupt before xRingbufferSend() was called. @@ -134,19 +135,23 @@ static void hw_cdc_isr_handler(void *arg) { connected = false; } - if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_SOF) { - usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SOF); - lastSOF_ms = millis(); - } + // SOF ISR is causing esptool to be unable to upload firmware to the board + // if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_SOF) { + // usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SOF); + // lastSOF_ms = millis(); + // } if (xTaskWoken == pdTRUE) { portYIELD_FROM_ISR(); } } -inline bool HWCDC::isPlugged(void) { - return (lastSOF_ms + SOF_TIMEOUT) >= millis(); -} +// Moved to header file as inline function. Kept just as future reference. +//inline bool HWCDC::isPlugged(void) { +// SOF ISR is causing esptool to be unable to upload firmware to the board +// Timer test for SOF seems to work when uploading firmware +// return usb_serial_jtag_is_connected();//(lastSOF_ms + SOF_TIMEOUT) >= millis(); +//} bool HWCDC::isCDC_Connected() { static bool running = false; @@ -155,11 +160,13 @@ bool HWCDC::isCDC_Connected() { if (!isPlugged()) { connected = false; running = false; - SOF_TIMEOUT = 5; // SOF timeout when unplugged + // SOF in ISR causes problems for uploading firmware + //SOF_TIMEOUT = 5; // SOF timeout when unplugged return false; - } else { - SOF_TIMEOUT = 50; // SOF timeout when plugged } + //else { + // SOF_TIMEOUT = 50; // SOF timeout when plugged + //} if (connected) { running = false; @@ -242,13 +249,15 @@ static void ARDUINO_ISR_ATTR cdc0_write_char(char c) { xRingbufferSend(tx_ring_buf, (void *)(&c), 1, tx_timeout_ms / portTICK_PERIOD_MS); } usb_serial_jtag_ll_txfifo_flush(); + usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); } HWCDC::HWCDC() { perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DM, HWCDC::deinit); perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DP, HWCDC::deinit); - lastSOF_ms = 0; - SOF_TIMEOUT = 5; + // SOF in ISR causes problems for uploading firmware + // lastSOF_ms = 0; + // SOF_TIMEOUT = 5; } HWCDC::~HWCDC() { @@ -309,8 +318,9 @@ void HWCDC::begin(unsigned long baud) { } // the HW Serial pins needs to be first deinited in order to allow `if(Serial)` to work :-( - deinit(NULL); - delay(10); // USB Host has to enumerate it again + // But this is also causing terminal to hang, so they are disabled + // deinit(NULL); + // delay(10); // USB Host has to enumerate it again // Peripheral Manager setting for USB D+ D- pins uint8_t pin = USB_DM_GPIO_NUM; @@ -332,9 +342,11 @@ void HWCDC::begin(unsigned long baud) { // Enable USB pad function USB_SERIAL_JTAG.conf0.usb_pad_enable = 1; usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); - usb_serial_jtag_ll_ena_intr_mask( - USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET | USB_SERIAL_JTAG_INTR_SOF - ); + usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET); + // SOF ISR is causing esptool to be unable to upload firmware to the board + // usb_serial_jtag_ll_ena_intr_mask( + // USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET | USB_SERIAL_JTAG_INTR_SOF + // ); if (!intr_handle && esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_isr_handler, NULL, &intr_handle) != ESP_OK) { isr_log_e("HW USB CDC failed to init interrupts"); end(); @@ -587,9 +599,9 @@ size_t HWCDC::read(uint8_t *buffer, size_t size) { void HWCDC::setDebugOutput(bool en) { if (en) { uartSetDebug(NULL); - ets_install_putc1((void (*)(char)) & cdc0_write_char); + ets_install_putc2((void (*)(char)) & cdc0_write_char); } else { - ets_install_putc1(NULL); + ets_install_putc2(NULL); } } diff --git a/cores/esp32/HWCDC.h b/cores/esp32/HWCDC.h index ebfbf7c4d60..29caae34062 100644 --- a/cores/esp32/HWCDC.h +++ b/cores/esp32/HWCDC.h @@ -21,6 +21,7 @@ #include #include "esp_event.h" #include "Stream.h" +#include "driver/usb_serial_jtag.h" ESP_EVENT_DECLARE_BASE(ARDUINO_HW_CDC_EVENTS); @@ -69,7 +70,12 @@ class HWCDC : public Stream { size_t write(const uint8_t *buffer, size_t size); void flush(void); - static bool isPlugged(void); + inline static bool isPlugged(void) { + // SOF ISR is causing esptool to be unable to upload firmware to the board + // Using IDF 5.1 helper function because it is based on Timer check instead of ISR + return usb_serial_jtag_is_connected(); + } + inline static bool isConnected(void) { return isCDC_Connected(); } diff --git a/cores/esp32/IPAddress.h b/cores/esp32/IPAddress.h index a24271cd580..b88aeed3026 100644 --- a/cores/esp32/IPAddress.h +++ b/cores/esp32/IPAddress.h @@ -124,6 +124,9 @@ class IPAddress : public Printable { friend class UDP; friend class Client; friend class Server; + friend class EthernetClass; + friend class DhcpClass; + friend class DNSClient; protected: bool fromString4(const char *address); diff --git a/cores/esp32/USBCDC.cpp b/cores/esp32/USBCDC.cpp index 6252b8c1d7b..2689086013a 100644 --- a/cores/esp32/USBCDC.cpp +++ b/cores/esp32/USBCDC.cpp @@ -417,9 +417,9 @@ uint32_t USBCDC::baudRate() { void USBCDC::setDebugOutput(bool en) { if (en) { uartSetDebug(NULL); - ets_install_putc1((void (*)(char)) & cdc0_write_char); + ets_install_putc2((void (*)(char)) & cdc0_write_char); } else { - ets_install_putc1(NULL); + ets_install_putc2(NULL); } } diff --git a/cores/esp32/esp32-hal-ledc.c b/cores/esp32/esp32-hal-ledc.c index de164c9a4b9..8c9454c996f 100644 --- a/cores/esp32/esp32-hal-ledc.c +++ b/cores/esp32/esp32-hal-ledc.c @@ -92,7 +92,7 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c return false; } - uint32_t duty = ledc_get_duty(group, channel); + uint32_t duty = ledc_get_duty(group, (channel % 8)); ledc_channel_config_t ledc_channel = { .speed_mode = group, .channel = (channel % 8), .timer_sel = timer, .intr_type = LEDC_INTR_DISABLE, .gpio_num = pin, .duty = duty, .hpoint = 0 diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 0aa5090b6bd..68a600b51c5 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -536,9 +536,9 @@ uart_t *uartBegin( retCode &= uartSetPins(uart_nr, rxPin, txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); } if (!retCode) { + log_e("UART%d initialization error.", uart->num); uartEnd(uart_nr); uart = NULL; - log_e("UART%d initialization error.", uart->num); } else { uartFlush(uart); log_v("UART%d initialization done.", uart->num); @@ -828,6 +828,7 @@ void uart_install_putc() { #endif default: ets_install_putc1(NULL); break; } + ets_install_putc2(NULL); } // Routines that take care of UART mode in the HardwareSerial Class code @@ -878,7 +879,7 @@ int log_printfv(const char *format, va_list arg) { } #endif */ -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || ((CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C6) && ARDUINO_USB_CDC_ON_BOOT) vsnprintf(temp, len + 1, format, arg); ets_printf("%s", temp); #else diff --git a/docs/en/getting_started.rst b/docs/en/getting_started.rst index a4b69696787..3b3a7e5b988 100644 --- a/docs/en/getting_started.rst +++ b/docs/en/getting_started.rst @@ -45,6 +45,11 @@ ESP32-C6 No Yes `ESP32-C6`_ ESP32-H2 No Yes `ESP32-H2`_ ======== ====== =========== =================================== +.. note:: + ESP32-C2 is also supported by Arduino-ESP32 but requires rebuilding the static libraries. + This is not trivial and requires a good understanding of the ESP-IDF build system. + For more information, see the `Lib Builder documentation `_. + See `Boards `_ for more details about ESP32 development boards. Arduino Core Reference diff --git a/docs/en/lib_builder.rst b/docs/en/lib_builder.rst index 5c62aafe55d..fb1a9b189ee 100644 --- a/docs/en/lib_builder.rst +++ b/docs/en/lib_builder.rst @@ -152,8 +152,11 @@ This build command will build for the ESP32-S3 target. You can specify other tar * esp32 * esp32s2 -* esp32c3 * esp32s3 +* esp32c2 +* esp32c3 +* esp32c6 +* esp32h2 Set Build Type ^^^^^^^^^^^^^^ @@ -169,7 +172,7 @@ Set the build type. ex. 'build' to build the project and prepare for uploading t Additional Configuration ^^^^^^^^^^^^^^^^^^^^^^^^ -Specify additional configs to be applied. ex. 'qio 80m' to compile for QIO Flash@80MHz. Requires -b +Specify additional configs to be applied. ex. 'qio 80m' to compile for QIO Flash@80MHz. .. note:: This command requires the ``-b`` to work properly. @@ -177,3 +180,122 @@ Specify additional configs to be applied. ex. 'qio 80m' to compile for QIO Flash .. code-block:: bash ./build.sh -t esp32 -b idf_libs qio 80m + +Docker Image +------------ + +You can use a docker image for building the static libraries of ESP-IDF components for use in Arduino projects. +This image contains a copy of the ``esp32-arduino-lib-builder`` repository and already includes or will obtain all the required tools and dependencies to build the Arduino static libraries. + +The current supported architectures by the Docker image are: + +* ``amd64`` +* ``arm64`` + +.. note:: + Building the libraries using the Docker image is much slower than building them natively on the host machine. + It is recommended to use the Docker image only when the host machine does not meet the requirements for building the libraries. + +Tags +**** + +Multiple tags of this image are maintained: + +- ``latest``: tracks ``master`` branch of the Lib Builder +- ``release-vX.Y``: tracks ``release/vX.Y`` branch of the Lib Builder + +.. note:: + Versions of Lib Builder released before this feature was introduced do not have corresponding Docker image versions. + You can check the up-to-date list of available tags at https://hub.docker.com/r/espressif/esp32-arduino-lib-builder/tags. + +Usage +***** + +Before using the ``espressif/esp32-arduino-lib-builder`` Docker image locally, make sure you have Docker installed. +Follow the instructions at https://docs.docker.com/install/, if it is not installed yet. + +If using the image in a CI environment, consult the documentation of your CI service on how to specify the image used for the build process. + +Building the Libraries +^^^^^^^^^^^^^^^^^^^^^^ + +You have two options to run the Docker image to build the libraries. Manually or using the provided run script. + +To run the Docker image manually, use the following command from the root of the ``arduino-esp32`` repository: + +.. code-block:: bash + + docker run --rm -it -v $PWD:/arduino-esp32 -e TERM=xterm-256color espressif/esp32-arduino-lib-builder + +This will start the Lib Builder UI for compiling the libraries. The above command explained: + +- ``docker run``: Runs a command in a container; +- ``--rm``: Optional. Automatically removes the container when it exits. Remove this flag if you plan to use the container multiple times; +- ``-i`` Run the container in interactive mode; +- ``-t`` Allocate a pseudo-TTY; +- ``-e TERM=xterm-256color``: Optional. Sets the terminal type to ``xterm-256color`` to display colors correctly; +- ``-v $PWD:/arduino-esp32``: Optional. Mounts the current folder at ``/arduino-esp32`` inside the container. If not provided, the container will not copy the compiled libraries to the host machine; +- ``espressif/esp32-arduino-lib-builder``: uses Docker image ``espressif/esp32-arduino-lib-builder`` with tag ``latest``. The ``latest`` tag is implicitly added by Docker when no tag is specified. + +.. warning:: + The ``-v`` option is used to mount a folder from the host machine to the container. Make sure the folder already exists on the host machine before running the command. + Otherwise, the folder will be created with root permissions and files generated inside the container might cause permission issues and compilation errors. + +.. note:: + When the mounted directory ``/arduino-esp32`` contains a git repository owned by a different user (``UID``) than the one running the Docker container, + git commands executed within ``/arduino-esp32`` might fail, displaying an error message ``fatal: detected dubious ownership in repository at '/arduino-esp32'``. + To resolve this issue, you can designate the ``/arduino-esp32`` directory as safe by setting the ``LIBBUILDER_GIT_SAFE_DIR`` environment variable during the Docker container startup. + For instance, you can achieve this by including ``-e LIBBUILDER_GIT_SAFE_DIR='/arduino-esp32'`` as a parameter. Additionally, multiple directories can be specified by using a ``:`` separator. + To entirely disable this git security check, ``*`` can be used. + +After running the above command, you will be inside the container and the libraries can be built using the user interface. + +By default the docker container will run the user interface script. If you want to run a specific command, you can pass it as an argument to the ``docker run`` command. +For example, to run a terminal inside the container, you can run: + +.. code-block:: bash + + docker run -it espressif/esp32-arduino-lib-builder:latest /bin/bash + +Running the Docker image using the provided run script will depend on the host OS. +Use the following command from the root of the ``arduino-esp32`` repository to execute the image in a Linux or macOS environment: + +.. code-block:: bash + + curl -LJO https://raw.githubusercontent.com/espressif/esp32-arduino-lib-builder/master/tools/docker/run.sh + chmod +x run.sh + ./run.sh $PWD + +For Windows, use the following command in PowerShell from the root of the ``arduino-esp32`` repository: + +.. code-block:: powershell + + Invoke-WebRequest -Uri "https://raw.githubusercontent.com/espressif/esp32-arduino-lib-builder/master/tools/docker/run.ps1" -OutFile "run.ps1" + .\run.ps1 $pwd + +.. warning:: + It is always a good practice to understand what the script does before running it. + Make sure to analyze the content of the script to ensure it is safe to run and won't cause any harm to your system. + +Building Custom Images +********************** + +To build a custom Docker image, you need to clone the Lib Builder repository and use the provided Dockerfile in the Lib Builder repository. The Dockerfile is located in the ``tools/docker`` directory. + +The `Docker file in the Lib Builder repository `_ provides several build arguments which can be used to customize the Docker image: + +- ``LIBBUILDER_CLONE_URL``: URL of the repository to clone Lib Builder from. Can be set to a custom URL when working with a fork of Lib Builder. The default is ``https://github.com/espressif/esp32-arduino-lib-builder.git``; +- ``LIBBUILDER_CLONE_BRANCH_OR_TAG``: Name of a git branch or tag used when cloning Lib Builder. This value is passed to the ``git clone`` command using the ``--branch`` argument. The default is ``master``; +- ``LIBBUILDER_CHECKOUT_REF``: If this argument is set to a non-empty value, ``git checkout $LIBBUILDER_CHECKOUT_REF`` command performs after cloning. This argument can be set to the SHA of the specific commit to check out, for example, if some specific commit on a release branch is desired; +- ``LIBBUILDER_CLONE_SHALLOW``: If this argument is set to a non-empty value, ``--depth=1 --shallow-submodules`` arguments are used when performing ``git clone``. Depth can be customized using ``LIBBUILDER_CLONE_SHALLOW_DEPTH``. Doing a shallow clone significantly reduces the amount of data downloaded and the size of the resulting Docker image. However, if switching to a different branch in such a "shallow" repository is necessary, an additional ``git fetch origin `` command must be executed first; +- ``LIBBUILDER_CLONE_SHALLOW_DEPTH``: This argument specifies the depth value to use when doing a shallow clone. If not set, ``--depth=1`` will be used. This argument has effect only if ``LIBBUILDER_CLONE_SHALLOW`` is used. Use this argument if you are building a Docker image for a branch, and the image has to contain the latest tag on that branch. To determine the required depth, run ``git describe`` for the given branch and note the offset number. Increment it by 1, then use it as the value of this argument. The resulting image will contain the latest tag on the branch, and consequently ``git describe`` command inside the Docker image will work as expected; + +To use these arguments, pass them via the ``--build-arg`` command line option. For example, the following command builds a Docker image with a shallow clone of Lib Builder from a specific repository and branch: + +.. code-block:: bash + + docker buildx build -t lib-builder-custom:master \ + --build-arg LIBBUILDER_CLONE_BRANCH_OR_TAG=master \ + --build-arg LIBBUILDER_CLONE_SHALLOW=1 \ + --build-arg LIBBUILDER_CLONE_URL=https://github.com/espressif/esp32-arduino-lib-builder \ + tools/docker diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/README.md b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/README.md index a475cde214d..cccc97aec98 100644 --- a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/README.md +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/README.md @@ -1,6 +1,6 @@ # Arduino-ESP32 Zigbee Light Bulb Example -This example shows how to configure the Zigbee end device and use it as a HA on/off light bulb. +This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) on/off light bulb. **This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_on_off_light.** @@ -39,6 +39,9 @@ You can do the following: * In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled` * In the sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function. +By default, the coordinator network is open for 180s after rebooting or flashing new firmware. After that, the network is closed for adding new devices. +You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function. + ***Important: Make sure you are using a good quality USB cable and that you have a reliable power source*** * **LED not blinking:** Check the wiring connection and the IO selection. diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/Zigbee_Light_Bulb.ino b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/Zigbee_Light_Bulb.ino index 19d04a0d1c7..67b9123c937 100644 --- a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/Zigbee_Light_Bulb.ino +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/Zigbee_Light_Bulb.ino @@ -49,10 +49,10 @@ } #define ESP_ZB_DEFAULT_RADIO_CONFIG() \ - { .radio_mode = RADIO_MODE_NATIVE, } + { .radio_mode = ZB_RADIO_MODE_NATIVE, } #define ESP_ZB_DEFAULT_HOST_CONFIG() \ - { .host_connection_mode = HOST_CONNECTION_MODE_NONE, } + { .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, } /* Zigbee configuration */ #define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ @@ -78,8 +78,13 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { - log_i("Start network steering"); - esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); + log_i("Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + if (esp_zb_bdb_is_factory_new()) { + log_i("Start network formation"); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); + } else { + log_i("Device rebooted"); + } } else { /* commissioning failed */ log_w("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); @@ -122,7 +127,7 @@ static void esp_zb_task(void *pvParameters) { esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK); //Erase NVRAM before creating connection to new Coordinator - //esp_zb_nvram_erase_at_start(true); //Comment out this line to erase NVRAM data if you are conneting to new Coordinator + esp_zb_nvram_erase_at_start(true); //Comment out this line to erase NVRAM data if you are conneting to new Coordinator ESP_ERROR_CHECK(esp_zb_start(false)); esp_zb_main_loop_iteration(); diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/README.md b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/README.md index d296c41e093..81f9354a6a0 100644 --- a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/README.md +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/README.md @@ -1,6 +1,6 @@ # Arduino-ESP32 Zigbee Light Switch Example -This example shows how to configure Zigbee Coordinator and use it as an HA on/off light switch. +This example shows how to configure Zigbee Coordinator and use it as a Home Automation (HA) on/off light switch. **This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_on_off_switch.** @@ -39,6 +39,9 @@ You can do the following: * In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`. * In the `Zigbee_Light_Bulb` example sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function. +By default, the coordinator network is open for 180s after rebooting or flashing new firmware. After that, the network is closed for adding new devices. +You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function. + ***Important: Make sure you are using a good quality USB cable and that you have a reliable power source*** * **LED not blinking:** Check the wiring connection and the IO selection. diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/Zigbee_Light_Switch.ino b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/Zigbee_Light_Switch.ino index cdb5ec9f70e..6c19b145f35 100644 --- a/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/Zigbee_Light_Switch.ino +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/Zigbee_Light_Switch.ino @@ -75,10 +75,10 @@ static switch_func_pair_t button_func_pair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SW } #define ESP_ZB_DEFAULT_RADIO_CONFIG() \ - { .radio_mode = RADIO_MODE_NATIVE, } + { .radio_mode = ZB_RADIO_MODE_NATIVE, } #define ESP_ZB_DEFAULT_HOST_CONFIG() \ - { .host_connection_mode = HOST_CONNECTION_MODE_NONE, } + { .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, } typedef struct light_bulb_device_params_s { esp_zb_ieee_addr_t ieee_addr; @@ -92,7 +92,7 @@ typedef struct light_bulb_device_params_s { #define HA_ONOFF_SWITCH_ENDPOINT 1 /* esp light switch device endpoint */ #define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */ -/********************* Define functions **************************/ +/********************* Zigbee functions **************************/ static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair) { if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) { /* implemented light switch toggle functionality */ @@ -153,8 +153,15 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { - log_i("Start network formation"); - esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); + log_i("Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + if (esp_zb_bdb_is_factory_new()) { + log_i("Start network formation"); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); + } else { + log_i("Device rebooted"); + log_i("Openning network for joining for %d seconds", 180); + esp_zb_bdb_open_network(180); + } } else { log_e("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); } @@ -187,6 +194,15 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { cmd_req.addr_of_interest = dev_annce_params->device_short_addr; esp_zb_zdo_find_on_off_light(&cmd_req, user_find_cb, NULL); break; + case ESP_ZB_NWK_SIGNAL_PERMIT_JOIN_STATUS: + if (err_status == ESP_OK) { + if (*(uint8_t *)esp_zb_app_signal_get_params(p_sg_p)) { + log_i("Network(0x%04hx) is open for %d seconds", esp_zb_get_pan_id(), *(uint8_t *)esp_zb_app_signal_get_params(p_sg_p)); + } else { + log_w("Network(0x%04hx) closed, devices joining not allowed.", esp_zb_get_pan_id()); + } + } + break; default: log_i("ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type, esp_err_to_name(err_status)); break; } } diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32 b/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32c3 b/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32c3 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32c6 b/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32c6 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32h2 b/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32h2 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32s2 b/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32s2 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32s3 b/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/.skip.esp32s3 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/README.md b/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/README.md new file mode 100644 index 00000000000..c7c2489970c --- /dev/null +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/README.md @@ -0,0 +1,83 @@ +# Arduino-ESP32 Zigbee Temperature Sensor Example + +This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) temperature sensor. + +**This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_temperature_sensor.** + +# Supported Targets + +Currently, this example supports the following targets. + +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +## Temperature Sensor Functions + +Note: + * This board means the board (e.g. ESP32-H2) loaded with `Zigbee_Temperature_Sensor` example. + * The remote board means the board (e.g. ESP32-H2) loaded with `Zigbee_Thermostat` example. + +Functions: + * After this board first starts up, it would be configured locally to report the temperature on 1 degree change and no periodic reporting to the remote board. + * By clicking the switch button (BOOT) on this board, this board will immediately send a report of the current measured temperature to the remote board. + +## Hardware Required + +* One development board (ESP32-H2 or ESP32-C6) acting as Zigbee coordinator (loaded with `Zigbee_Thermostat` example) +* A USB cable for power supply and programming +* Choose another board (ESP32-H2 or ESP32-C6) as Zigbee end device (loaded with `Zigbee_Temperature_Sensor` example) + +### Configure the Project + +In this example, the internal temperature sensor task is reading the chip temperature. +Set the Button Switch GPIO by changing the `GPIO_INPUT_IO_TOGGLE_SWITCH` definition. By default, it's the `GPIO_NUM_9` (BOOT button on ESP32-C6 and ESP32-H2). + +#### Using Arduino IDE + +To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits). + +* Before Compile/Verify, select the correct board: `Tools -> Board`. +* Select the End device Zigbee mode: `Tools -> Zigbee mode: Zigbee ED (end device)` +* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs` +* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port. + +## Troubleshooting + +If the End device flashed with this example is not connecting to the coordinator, erase the flash before flashing it to the board. It is recommended to do this if you did changes to the coordinator. +You can do the following: + +* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled` +* In the sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function. + +By default, the coordinator network is open for 180s after rebooting or flashing new firmware. After that, the network is closed for adding new devices. +You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function. + +***Important: Make sure you are using a good quality USB cable and that you have a reliable power source*** + +* **LED not blinking:** Check the wiring connection and the IO selection. +* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed. +* **COM port not detected:** Check the USB cable and the USB to Serial driver installation. + +If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute). + +## Contribute + +To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst) + +If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome! + +Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else. + +## Resources + +The ESP Zigbee SDK provides more examples: +* ESP Zigbee SDK Docs: [Link](https://docs.espressif.com/projects/esp-zigbee-sdk) +* ESP Zigbee SDK Repo: [Link](https://github.com/espressif/esp-zigbee-sdk) + +* Official ESP32 Forum: [Link](https://esp32.com) +* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) +* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf) +* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf) +* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) +* ESP32-S3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf) +* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com) diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/Zigbee_Temperature_Sensor.ino b/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/Zigbee_Temperature_Sensor.ino new file mode 100644 index 00000000000..ed966fa86b5 --- /dev/null +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Temperature_Sensor/Zigbee_Temperature_Sensor.ino @@ -0,0 +1,349 @@ +// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @brief This example demonstrates simple Zigbee temperature sensor. + * + * The example demonstrates how to use ESP Zigbee stack to create a end device temperatu sensor. + * The temperature sensor is a Zigbee end device, which is controlled by a Zigbee coordinator. + * + * Proper Zigbee mode must be selected in Tools->Zigbee mode + * and also the correct partition scheme must be selected in Tools->Partition Scheme. + * + * Please check the README.md for instructions and more detailed description. + */ + +#ifndef ZIGBEE_MODE_ED +#error "Zigbee end device mode is not selected in Tools->Zigbee mode" +#endif + +#include "esp_zigbee_core.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "ha/esp_zigbee_ha_standard.h" + +/* Switch configuration */ +#define GPIO_INPUT_IO_TOGGLE_SWITCH GPIO_NUM_9 +#define PAIR_SIZE(TYPE_STR_PAIR) (sizeof(TYPE_STR_PAIR) / sizeof(TYPE_STR_PAIR[0])) + +typedef enum { + SWITCH_ON_CONTROL, + SWITCH_OFF_CONTROL, + SWITCH_ONOFF_TOGGLE_CONTROL, + SWITCH_LEVEL_UP_CONTROL, + SWITCH_LEVEL_DOWN_CONTROL, + SWITCH_LEVEL_CYCLE_CONTROL, + SWITCH_COLOR_CONTROL, +} switch_func_t; + +typedef struct { + uint8_t pin; + switch_func_t func; +} switch_func_pair_t; + +typedef enum { + SWITCH_IDLE, + SWITCH_PRESS_ARMED, + SWITCH_PRESS_DETECTED, + SWITCH_PRESSED, + SWITCH_RELEASE_DETECTED, +} switch_state_t; + +static switch_func_pair_t button_func_pair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ONOFF_TOGGLE_CONTROL}}; + +/* Default End Device config */ +#define ESP_ZB_ZED_CONFIG() \ + { \ + .esp_zb_role = ESP_ZB_DEVICE_TYPE_ED, .install_code_policy = INSTALLCODE_POLICY_ENABLE, \ + .nwk_cfg = { \ + .zed_cfg = \ + { \ + .ed_timeout = ED_AGING_TIMEOUT, \ + .keep_alive = ED_KEEP_ALIVE, \ + }, \ + }, \ + } + +#define ESP_ZB_DEFAULT_RADIO_CONFIG() \ + { .radio_mode = ZB_RADIO_MODE_NATIVE, } + +#define ESP_ZB_DEFAULT_HOST_CONFIG() \ + { .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, } + +/* Zigbee configuration */ +#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ +#define ED_AGING_TIMEOUT ESP_ZB_ED_AGING_TIMEOUT_64MIN +#define ED_KEEP_ALIVE 3000 /* 3000 millisecond */ +#define HA_ESP_SENSOR_ENDPOINT 10 /* esp temperature sensor device endpoint, used for temperature measurement */ +#define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */ + +/* Temperature sensor configuration */ +#define ESP_TEMP_SENSOR_UPDATE_INTERVAL (1) /* Local sensor update interval (second) */ +#define ESP_TEMP_SENSOR_MIN_VALUE (10) /* Local sensor min measured value (degree Celsius) */ +#define ESP_TEMP_SENSOR_MAX_VALUE (50) /* Local sensor max measured value (degree Celsius) */ + +/* Attribute values in ZCL string format + * The string should be started with the length of its own. + */ +#define MANUFACTURER_NAME \ + "\x0B" \ + "ESPRESSIF" +#define MODEL_IDENTIFIER "\x09" CONFIG_IDF_TARGET + +/********************* Zigbee functions **************************/ +static int16_t zb_temperature_to_s16(float temp) { + return (int16_t)(temp * 100); +} + +static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair) { + if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) { + /* Send report attributes command */ + esp_zb_zcl_report_attr_cmd_t report_attr_cmd; + report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; + report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID; + report_attr_cmd.cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE; + report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + report_attr_cmd.zcl_basic_cmd.src_endpoint = HA_ESP_SENSOR_ENDPOINT; + + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_report_attr_cmd_req(&report_attr_cmd); + esp_zb_lock_release(); + log_i("Send 'report attributes' command"); + } +} + +static void esp_app_temp_sensor_handler(float temperature) { + int16_t measured_value = zb_temperature_to_s16(temperature); + Serial.println("Updating temperature sensor value..."); + Serial.println(measured_value); + /* Update temperature sensor measured value */ + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_set_attribute_val( + HA_ESP_SENSOR_ENDPOINT, ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, &measured_value, + false + ); + esp_zb_lock_release(); +} + +static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) { + ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); +} + +void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { + uint32_t *p_sg_p = signal_struct->p_app_signal; + esp_err_t err_status = signal_struct->esp_err_status; + esp_zb_app_signal_type_t sig_type = (esp_zb_app_signal_type_t)*p_sg_p; + switch (sig_type) { + case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: + log_i("Zigbee stack initialized"); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); + break; + case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: + case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: + if (err_status == ESP_OK) { + log_i("Start network steering"); + log_i("Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + // Start Temperature sensor reading task + xTaskCreate(temp_sensor_value_update, "temp_sensor_update", 2048, NULL, 10, NULL); + if (esp_zb_bdb_is_factory_new()) { + log_i("Start network steering"); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); + } else { + log_i("Device rebooted"); + } + } else { + /* commissioning failed */ + log_w("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + } + break; + case ESP_ZB_BDB_SIGNAL_STEERING: + if (err_status == ESP_OK) { + esp_zb_ieee_addr_t extended_pan_id; + esp_zb_get_extended_pan_id(extended_pan_id); + log_i( + "Joined network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d, Short Address: 0x%04hx)", + extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4], extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], + extended_pan_id[0], esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address() + ); + } else { + log_i("Network steering was not successful (status: %s)", esp_err_to_name(err_status)); + esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000); + } + break; + default: log_i("ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type, esp_err_to_name(err_status)); break; + } +} + +static esp_zb_cluster_list_t *custom_temperature_sensor_clusters_create(esp_zb_temperature_sensor_cfg_t *temperature_sensor) { + esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create(); + esp_zb_attribute_list_t *basic_cluster = esp_zb_basic_cluster_create(&(temperature_sensor->basic_cfg)); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, (void *)MANUFACTURER_NAME)); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, (void *)MODEL_IDENTIFIER)); + ESP_ERROR_CHECK(esp_zb_cluster_list_add_basic_cluster(cluster_list, basic_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE)); + ESP_ERROR_CHECK( + esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_identify_cluster_create(&(temperature_sensor->identify_cfg)), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE) + ); + ESP_ERROR_CHECK( + esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_IDENTIFY), ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE) + ); + ESP_ERROR_CHECK(esp_zb_cluster_list_add_temperature_meas_cluster( + cluster_list, esp_zb_temperature_meas_cluster_create(&(temperature_sensor->temp_meas_cfg)), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE + )); + return cluster_list; +} + +static esp_zb_ep_list_t *custom_temperature_sensor_ep_create(uint8_t endpoint_id, esp_zb_temperature_sensor_cfg_t *temperature_sensor) { + esp_zb_ep_list_t *ep_list = esp_zb_ep_list_create(); + esp_zb_endpoint_config_t endpoint_config = { + .endpoint = endpoint_id, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_TEMPERATURE_SENSOR_DEVICE_ID, .app_device_version = 0 + }; + esp_zb_ep_list_add_ep(ep_list, custom_temperature_sensor_clusters_create(temperature_sensor), endpoint_config); + return ep_list; +} + +static void esp_zb_task(void *pvParameters) { + esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZED_CONFIG(); + esp_zb_init(&zb_nwk_cfg); + /* Create customized temperature sensor endpoint */ + esp_zb_temperature_sensor_cfg_t sensor_cfg = ESP_ZB_DEFAULT_TEMPERATURE_SENSOR_CONFIG(); + /* Set (Min|Max)MeasuredValure */ + sensor_cfg.temp_meas_cfg.min_value = zb_temperature_to_s16(ESP_TEMP_SENSOR_MIN_VALUE); + sensor_cfg.temp_meas_cfg.max_value = zb_temperature_to_s16(ESP_TEMP_SENSOR_MAX_VALUE); + esp_zb_ep_list_t *esp_zb_sensor_ep = custom_temperature_sensor_ep_create(HA_ESP_SENSOR_ENDPOINT, &sensor_cfg); + /* Register the device */ + esp_zb_device_register(esp_zb_sensor_ep); + + /* Config the reporting info */ + esp_zb_zcl_reporting_info_t reporting_info = { + .direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV, + .ep = HA_ESP_SENSOR_ENDPOINT, + .cluster_id = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, + .cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, + .attr_id = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, + .u = + { + .send_info = + { + .min_interval = 1, + .max_interval = 0, + .delta = + { + .u16 = 100, + }, + .def_min_interval = 1, + .def_max_interval = 0, + }, + }, + .dst = + { + .profile_id = ESP_ZB_AF_HA_PROFILE_ID, + }, + .manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC, + }; + esp_zb_zcl_update_reporting_info(&reporting_info); + esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK); + + //Erase NVRAM before creating connection to new Coordinator + //esp_zb_nvram_erase_at_start(true); //Comment out this line to erase NVRAM data if you are conneting to new Coordinator + + ESP_ERROR_CHECK(esp_zb_start(false)); + esp_zb_main_loop_iteration(); +} + +/********************* GPIO functions **************************/ +static QueueHandle_t gpio_evt_queue = NULL; + +static void IRAM_ATTR gpio_isr_handler(void *arg) { + xQueueSendFromISR(gpio_evt_queue, (switch_func_pair_t *)arg, NULL); +} + +static void switch_gpios_intr_enabled(bool enabled) { + for (int i = 0; i < PAIR_SIZE(button_func_pair); ++i) { + if (enabled) { + enableInterrupt((button_func_pair[i]).pin); + } else { + disableInterrupt((button_func_pair[i]).pin); + } + } +} + +/************************ Temp sensor *****************************/ +static void temp_sensor_value_update(void *arg) { + for (;;) { + float tsens_value = temperatureRead(); + esp_app_temp_sensor_handler(tsens_value); + delay(1000); + } +} + +/********************* Arduino functions **************************/ +void setup() { + Serial.begin(115200); + // Init Zigbee + esp_zb_platform_config_t config = { + .radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_ZB_DEFAULT_HOST_CONFIG(), + }; + ESP_ERROR_CHECK(esp_zb_platform_config(&config)); + + // Init button switch + for (int i = 0; i < PAIR_SIZE(button_func_pair); i++) { + pinMode(button_func_pair[i].pin, INPUT_PULLUP); + /* create a queue to handle gpio event from isr */ + gpio_evt_queue = xQueueCreate(10, sizeof(switch_func_pair_t)); + if (gpio_evt_queue == 0) { + log_e("Queue was not created and must not be used"); + while (1); + } + attachInterruptArg(button_func_pair[i].pin, gpio_isr_handler, (void *)(button_func_pair + i), FALLING); + } + + // Start Zigbee task + xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL); +} + +void loop() { + // Handle button switch in loop() + uint8_t pin = 0; + switch_func_pair_t button_func_pair; + static switch_state_t switch_state = SWITCH_IDLE; + bool evt_flag = false; + float temperature; + + /* check if there is any queue received, if yes read out the button_func_pair */ + if (xQueueReceive(gpio_evt_queue, &button_func_pair, portMAX_DELAY)) { + pin = button_func_pair.pin; + switch_gpios_intr_enabled(false); + evt_flag = true; + } + while (evt_flag) { + bool value = digitalRead(pin); + switch (switch_state) { + case SWITCH_IDLE: switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_IDLE; break; + case SWITCH_PRESS_DETECTED: switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_RELEASE_DETECTED; break; + case SWITCH_RELEASE_DETECTED: + switch_state = SWITCH_IDLE; + /* callback to button_handler */ + (*esp_zb_buttons_handler)(&button_func_pair); + break; + default: break; + } + if (switch_state == SWITCH_IDLE) { + switch_gpios_intr_enabled(true); + evt_flag = false; + break; + } + delay(10); + } +} diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32 b/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32c3 b/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32c3 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32c6 b/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32c6 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32h2 b/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32h2 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32s2 b/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32s2 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32s3 b/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/.skip.esp32s3 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/README.md b/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/README.md new file mode 100644 index 00000000000..dc2a70782f8 --- /dev/null +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/README.md @@ -0,0 +1,82 @@ +# Arduino-ESP32 Zigbee Thermostat Example + +This example shows how to configure Zigbee Coordinator and use it as a Home Automation (HA) thermostat. + +**This example is based on ESP-Zigbee-SDK example esp_zigbee_HA_sample/HA_thermostat.** + +# Supported Targets + +Currently, this example supports the following targets. + +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +## Thermostat Functions + +Note: + * This board means the board (e.g. ESP32-H2) loaded with `Zigbee_Thermostat` example. + * The remote board means the board (e.g. ESP32-H2) loaded with `Zigbee_Temperature_Sensor` example. + +Functions: + * By clicking the switch button (BOOT) on this board, this board will read temperature value, temperature measurement range and temperature tolerance from the remote board. Also, this board will configure the remote board to report the measured temperature value every 10 seconds or every 2 degree changes. + +## Hardware Required + +* One development board (ESP32-H2 or ESP32-C6) acting as Zigbee end device (loaded with Zigbee_Temperature_Sensor example). +* A USB cable for power supply and programming. +* Choose another board (ESP32-H2 or ESP32-C6) as Zigbee coordinator (loaded with Zigbee_Thermostat example). + +### Configure the Project + +Set the Button Switch GPIO by changing the `GPIO_INPUT_IO_TOGGLE_SWITCH` definition. By default, it's the `GPIO_NUM_9` (BOOT button on ESP32-C6 and ESP32-H2). + +#### Using Arduino IDE + +To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits). + +* Before Compile/Verify, select the correct board: `Tools -> Board`. +* Select the Coordinator Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator)`. +* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee 4MB with spiffs`. +* Select the COM port: `Tools -> Port: xxx where the `xxx` is the detected COM port. +* Optional: Set debug level to info to see logs from Zigbee stack: `Tools -> Core Debug Level: Info`. + +## Troubleshooting + +If the End device flashed with the example `Zigbee_Temperature_Sensor` is not connecting to the coordinator, erase the flash of the End device before flashing the example to the board. It is recommended to do this if you re-flash the coordinator. +You can do the following: + +* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`. +* In the `Zigbee_Temperature_Sensor` example sketch uncomment function `esp_zb_nvram_erase_at_start(true);` located in `esp_zb_task` function. + +By default, the coordinator network is open for 180s after rebooting or flashing new firmware. After that, the network is closed for adding new devices. +You can change it by editing `esp_zb_bdb_open_network(180);` in `esp_zb_app_signal_handler` function. + +***Important: Make sure you are using a good quality USB cable and that you have a reliable power source*** + +* **LED not blinking:** Check the wiring connection and the IO selection. +* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed. +* **COM port not detected:** Check the USB cable and the USB to Serial driver installation. + +If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute). + +## Contribute + +To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst) + +If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome! + +Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else. + +## Resources + +The ESP Zigbee SDK provides more examples: +* ESP Zigbee SDK Docs: [Link](https://docs.espressif.com/projects/esp-zigbee-sdk) +* ESP Zigbee SDK Repo: [Link](https://github.com/espressif/esp-zigbee-sdk) + +* Official ESP32 Forum: [Link](https://esp32.com) +* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) +* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf) +* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf) +* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) +* ESP32-S3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf) +* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com) diff --git a/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/Zigbee_Thermostat.ino b/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/Zigbee_Thermostat.ino new file mode 100644 index 00000000000..1ace7d866e1 --- /dev/null +++ b/libraries/ESP32/examples/Zigbee/Zigbee_Thermostat/Zigbee_Thermostat.ino @@ -0,0 +1,565 @@ +// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @brief This example demonstrates simple Zigbee thermostat. + * + * The example demonstrates how to use ESP Zigbee stack to get data from temperature + * sensor end device and act as an thermostat. + * The temperature sensor is a Zigbee end device, which is controlled by a Zigbee coordinator (thermostat). + * Button switch and Zigbee runs in separate tasks. + * + * Proper Zigbee mode must be selected in Tools->Zigbee mode + * and also the correct partition scheme must be selected in Tools->Partition Scheme. + * + * Please check the README.md for instructions and more detailed description. + */ + +#ifndef ZIGBEE_MODE_ZCZR +#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode" +#endif + +#include "esp_zigbee_core.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "ha/esp_zigbee_ha_standard.h" + +#define ARRAY_LENTH(arr) (sizeof(arr) / sizeof(arr[0])) + +/* Switch configuration */ +#define GPIO_INPUT_IO_TOGGLE_SWITCH GPIO_NUM_9 +#define PAIR_SIZE(TYPE_STR_PAIR) (sizeof(TYPE_STR_PAIR) / sizeof(TYPE_STR_PAIR[0])) + +typedef enum { + SWITCH_ON_CONTROL, + SWITCH_OFF_CONTROL, + SWITCH_ONOFF_TOGGLE_CONTROL, + SWITCH_LEVEL_UP_CONTROL, + SWITCH_LEVEL_DOWN_CONTROL, + SWITCH_LEVEL_CYCLE_CONTROL, + SWITCH_COLOR_CONTROL, +} switch_func_t; + +typedef struct { + uint8_t pin; + switch_func_t func; +} switch_func_pair_t; + +typedef enum { + SWITCH_IDLE, + SWITCH_PRESS_ARMED, + SWITCH_PRESS_DETECTED, + SWITCH_PRESSED, + SWITCH_RELEASE_DETECTED, +} switch_state_t; + +static switch_func_pair_t button_func_pair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ONOFF_TOGGLE_CONTROL}}; + +/* Default Coordinator config */ +#define ESP_ZB_ZC_CONFIG() \ + { \ + .esp_zb_role = ESP_ZB_DEVICE_TYPE_COORDINATOR, .install_code_policy = INSTALLCODE_POLICY_ENABLE, .nwk_cfg = { \ + .zczr_cfg = \ + { \ + .max_children = MAX_CHILDREN, \ + }, \ + } \ + } + +#define ESP_ZB_DEFAULT_RADIO_CONFIG() \ + { .radio_mode = ZB_RADIO_MODE_NATIVE, } + +#define ESP_ZB_DEFAULT_HOST_CONFIG() \ + { .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, } + +/* Temperature sensor device parameters */ +typedef struct temp_sensor_device_params_s { + esp_zb_ieee_addr_t ieee_addr; + uint8_t endpoint; + uint16_t short_addr; +} temp_sensor_device_params_t; + +typedef struct zbstring_s { + uint8_t len; + char data[]; +} ESP_ZB_PACKED_STRUCT zbstring_t; + +static temp_sensor_device_params_t temp_sensor; + +/* Zigbee configuration */ +#define MAX_CHILDREN 10 /* the max amount of connected devices */ +#define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ +#define HA_THERMOSTAT_ENDPOINT 1 /* esp light switch device endpoint */ +#define ESP_ZB_PRIMARY_CHANNEL_MASK ESP_ZB_TRANSCEIVER_ALL_CHANNELS_MASK /* Zigbee primary channel mask use in the example */ + +/* Attribute values in ZCL string format + * The string should be started with the length of its own. + */ +#define MANUFACTURER_NAME \ + "\x0B" \ + "ESPRESSIF" +#define MODEL_IDENTIFIER "\x09" CONFIG_IDF_TARGET + +/********************* Zigbee functions **************************/ +static float zb_s16_to_temperature(int16_t value) { + return 1.0 * value / 100; +} + +static void esp_zb_buttons_handler(switch_func_pair_t *button_func_pair) { + if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) { + /* Send "read attributes" command to the bound sensor */ + esp_zb_zcl_read_attr_cmd_t read_req; + read_req.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; + read_req.zcl_basic_cmd.src_endpoint = HA_THERMOSTAT_ENDPOINT; + read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + + uint16_t attributes[] = { + ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID, + ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID + }; + read_req.attr_number = ARRAY_LENTH(attributes); + read_req.attr_field = attributes; + + /* Send "configure report attribute" command to the bound sensor */ + esp_zb_zcl_config_report_cmd_t report_cmd; + report_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT; + report_cmd.zcl_basic_cmd.src_endpoint = HA_THERMOSTAT_ENDPOINT; + report_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + + int16_t report_change = 200; /* report on each 2 degree changes */ + esp_zb_zcl_config_report_record_t records[] = { + { + .direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV, + .attributeID = ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, + .attrType = ESP_ZB_ZCL_ATTR_TYPE_S16, + .min_interval = 0, + .max_interval = 10, + .reportable_change = &report_change, + }, + }; + report_cmd.record_number = ARRAY_LENTH(records); + report_cmd.record_field = records; + + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_config_report_cmd_req(&report_cmd); + esp_zb_lock_release(); + log_i("Send 'configure reporting' command"); + + esp_zb_lock_acquire(portMAX_DELAY); + esp_zb_zcl_read_attr_cmd_req(&read_req); + esp_zb_lock_release(); + log_i("Send 'read attributes' command"); + } +} + +static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) { + ESP_ERROR_CHECK(esp_zb_bdb_start_top_level_commissioning(mode_mask)); +} + +static void bind_cb(esp_zb_zdp_status_t zdo_status, void *user_ctx) { + esp_zb_zdo_bind_req_param_t *bind_req = (esp_zb_zdo_bind_req_param_t *)user_ctx; + + if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { + /* Local binding succeeds */ + if (bind_req->req_dst_addr == esp_zb_get_short_address()) { + log_i("Successfully bind the temperature sensor from address(0x%x) on endpoint(%d)", temp_sensor.short_addr, temp_sensor.endpoint); + + /* Read peer Manufacture Name & Model Identifier */ + esp_zb_zcl_read_attr_cmd_t read_req; + read_req.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT; + read_req.zcl_basic_cmd.src_endpoint = HA_THERMOSTAT_ENDPOINT; + read_req.zcl_basic_cmd.dst_endpoint = temp_sensor.endpoint; + read_req.zcl_basic_cmd.dst_addr_u.addr_short = temp_sensor.short_addr; + read_req.clusterID = ESP_ZB_ZCL_CLUSTER_ID_BASIC; + + uint16_t attributes[] = { + ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, + ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, + }; + read_req.attr_number = ARRAY_LENTH(attributes); + read_req.attr_field = attributes; + + esp_zb_zcl_read_attr_cmd_req(&read_req); + } + if (bind_req->req_dst_addr == temp_sensor.short_addr) { + log_i("The temperature sensor from address(0x%x) on endpoint(%d) successfully binds us", temp_sensor.short_addr, temp_sensor.endpoint); + } + free(bind_req); + } else { + /* Bind failed, maybe retry the binding ? */ + + // esp_zb_zdo_device_bind_req(bind_req, bind_cb, bind_req); + } +} + +static void user_find_cb(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) { + if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) { + log_i("Found temperature sensor"); + /* Store the information of the remote device */ + temp_sensor_device_params_t *sensor = (temp_sensor_device_params_t *)user_ctx; + sensor->endpoint = endpoint; + sensor->short_addr = addr; + esp_zb_ieee_address_by_short(sensor->short_addr, sensor->ieee_addr); + log_d("Temperature sensor found: short address(0x%x), endpoint(%d)", sensor->short_addr, sensor->endpoint); + + /* 1. Send binding request to the sensor */ + esp_zb_zdo_bind_req_param_t *bind_req = (esp_zb_zdo_bind_req_param_t *)calloc(sizeof(esp_zb_zdo_bind_req_param_t), 1); + bind_req->req_dst_addr = addr; + log_d("Request temperature sensor to bind us"); + + /* populate the src information of the binding */ + memcpy(bind_req->src_address, sensor->ieee_addr, sizeof(esp_zb_ieee_addr_t)); + bind_req->src_endp = endpoint; + bind_req->cluster_id = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + log_d("Bind temperature sensor"); + + /* populate the dst information of the binding */ + bind_req->dst_addr_mode = ESP_ZB_ZDO_BIND_DST_ADDR_MODE_64_BIT_EXTENDED; + esp_zb_get_long_address(bind_req->dst_address_u.addr_long); + bind_req->dst_endp = HA_THERMOSTAT_ENDPOINT; + + log_i("Request temperature sensor to bind us"); + esp_zb_zdo_device_bind_req(bind_req, bind_cb, bind_req); + + /* 2. Send binding request to self */ + bind_req = (esp_zb_zdo_bind_req_param_t *)calloc(sizeof(esp_zb_zdo_bind_req_param_t), 1); + bind_req->req_dst_addr = esp_zb_get_short_address(); + + /* populate the src information of the binding */ + esp_zb_get_long_address(bind_req->src_address); + bind_req->src_endp = HA_THERMOSTAT_ENDPOINT; + bind_req->cluster_id = ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT; + + /* populate the dst information of the binding */ + bind_req->dst_addr_mode = ESP_ZB_ZDO_BIND_DST_ADDR_MODE_64_BIT_EXTENDED; + memcpy(bind_req->dst_address_u.addr_long, sensor->ieee_addr, sizeof(esp_zb_ieee_addr_t)); + bind_req->dst_endp = endpoint; + + log_i("Bind temperature sensor"); + esp_zb_zdo_device_bind_req(bind_req, bind_cb, bind_req); + } +} + +static void find_temperature_sensor(esp_zb_zdo_match_desc_req_param_t *param, esp_zb_zdo_match_desc_callback_t user_cb, void *user_ctx) { + uint16_t cluster_list[] = {ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT}; + param->profile_id = ESP_ZB_AF_HA_PROFILE_ID; + param->num_in_clusters = 1; + param->num_out_clusters = 0; + param->cluster_list = cluster_list; + esp_zb_zdo_match_cluster(param, user_cb, (void *)&temp_sensor); +} + +void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { + uint32_t *p_sg_p = signal_struct->p_app_signal; + esp_err_t err_status = signal_struct->esp_err_status; + esp_zb_app_signal_type_t sig_type = (esp_zb_app_signal_type_t)*p_sg_p; + esp_zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL; + switch (sig_type) { + case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP: + log_i("Zigbee stack initialized"); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); + break; + case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: + case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: + if (err_status == ESP_OK) { + log_i("Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + if (esp_zb_bdb_is_factory_new()) { + log_i("Start network formation"); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); + } else { + log_i("Device rebooted"); + log_i("Openning network for joining for %d seconds", 180); + esp_zb_bdb_open_network(180); + } + } else { + log_e("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + } + break; + case ESP_ZB_BDB_SIGNAL_FORMATION: + if (err_status == ESP_OK) { + esp_zb_ieee_addr_t extended_pan_id; + esp_zb_get_extended_pan_id(extended_pan_id); + log_i( + "Formed network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d, Short Address: 0x%04hx)", + extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4], extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], + extended_pan_id[0], esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address() + ); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); + } else { + log_i("Restart network formation (status: %s)", esp_err_to_name(err_status)); + esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_FORMATION, 1000); + } + break; + case ESP_ZB_BDB_SIGNAL_STEERING: + if (err_status == ESP_OK) { + log_i("Network steering started"); + } + break; + case ESP_ZB_ZDO_SIGNAL_DEVICE_ANNCE: + dev_annce_params = (esp_zb_zdo_signal_device_annce_params_t *)esp_zb_app_signal_get_params(p_sg_p); + log_i("New device commissioned or rejoined (short: 0x%04hx)", dev_annce_params->device_short_addr); + esp_zb_zdo_match_desc_req_param_t cmd_req; + cmd_req.dst_nwk_addr = dev_annce_params->device_short_addr; + cmd_req.addr_of_interest = dev_annce_params->device_short_addr; + find_temperature_sensor(&cmd_req, user_find_cb, NULL); + break; + case ESP_ZB_NWK_SIGNAL_PERMIT_JOIN_STATUS: + if (err_status == ESP_OK) { + if (*(uint8_t *)esp_zb_app_signal_get_params(p_sg_p)) { + log_i("Network(0x%04hx) is open for %d seconds", esp_zb_get_pan_id(), *(uint8_t *)esp_zb_app_signal_get_params(p_sg_p)); + } else { + log_w("Network(0x%04hx) closed, devices joining not allowed.", esp_zb_get_pan_id()); + } + } + break; + default: log_i("ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type, esp_err_to_name(err_status)); break; + } +} + +static void esp_app_zb_attribute_handler(uint16_t cluster_id, const esp_zb_zcl_attribute_t *attribute) { + /* Basic cluster attributes */ + if (cluster_id == ESP_ZB_ZCL_CLUSTER_ID_BASIC) { + if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data.value) { + zbstring_t *zbstr = (zbstring_t *)attribute->data.value; + char *string = (char *)malloc(zbstr->len + 1); + memcpy(string, zbstr->data, zbstr->len); + string[zbstr->len] = '\0'; + log_i("Peer Manufacturer is \"%s\"", string); + free(string); + } + if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data.value) { + zbstring_t *zbstr = (zbstring_t *)attribute->data.value; + char *string = (char *)malloc(zbstr->len + 1); + memcpy(string, zbstr->data, zbstr->len); + string[zbstr->len] = '\0'; + log_i("Peer Model is \"%s\"", string); + free(string); + } + } + + /* Temperature Measurement cluster attributes */ + if (cluster_id == ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT) { + if (attribute->id == ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_S16) { + int16_t value = attribute->data.value ? *(int16_t *)attribute->data.value : 0; + log_i("Measured Value is %.2f degrees Celsius", zb_s16_to_temperature(value)); + } + if (attribute->id == ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_S16) { + int16_t min_value = attribute->data.value ? *(int16_t *)attribute->data.value : 0; + log_i("Min Measured Value is %.2f degrees Celsius", zb_s16_to_temperature(min_value)); + } + if (attribute->id == ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_S16) { + int16_t max_value = attribute->data.value ? *(int16_t *)attribute->data.value : 0; + log_i("Max Measured Value is %.2f degrees Celsius", zb_s16_to_temperature(max_value)); + } + if (attribute->id == ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_U16) { + uint16_t tolerance = attribute->data.value ? *(uint16_t *)attribute->data.value : 0; + log_i("Tolerance is %.2f degrees Celsius", 1.0 * tolerance / 100); + } + } +} + +static esp_err_t zb_attribute_reporting_handler(const esp_zb_zcl_report_attr_message_t *message) { + if (!message) { + log_e("Empty message"); + } + if (message->status != ESP_ZB_ZCL_STATUS_SUCCESS) { + log_e("Received message: error status(%d)", message->status); + } + log_i( + "Received report from address(0x%x) src endpoint(%d) to dst endpoint(%d) cluster(0x%x)", message->src_address.u.short_addr, message->src_endpoint, + message->dst_endpoint, message->cluster + ); + esp_app_zb_attribute_handler(message->cluster, &message->attribute); + return ESP_OK; +} + +static esp_err_t zb_read_attr_resp_handler(const esp_zb_zcl_cmd_read_attr_resp_message_t *message) { + if (!message) { + log_e("Empty message"); + } + if (message->info.status != ESP_ZB_ZCL_STATUS_SUCCESS) { + log_e("Received message: error status(%d)", message->info.status); + } + log_i( + "Read attribute response: from address(0x%x) src endpoint(%d) to dst endpoint(%d) cluster(0x%x)", message->info.src_address.u.short_addr, + message->info.src_endpoint, message->info.dst_endpoint, message->info.cluster + ); + + esp_zb_zcl_read_attr_resp_variable_t *variable = message->variables; + while (variable) { + log_i( + "Read attribute response: status(%d), cluster(0x%x), attribute(0x%x), type(0x%x), value(%d)", variable->status, message->info.cluster, + variable->attribute.id, variable->attribute.data.type, variable->attribute.data.value ? *(uint8_t *)variable->attribute.data.value : 0 + ); + if (variable->status == ESP_ZB_ZCL_STATUS_SUCCESS) { + esp_app_zb_attribute_handler(message->info.cluster, &variable->attribute); + } + + variable = variable->next; + } + + return ESP_OK; +} + +static esp_err_t zb_configure_report_resp_handler(const esp_zb_zcl_cmd_config_report_resp_message_t *message) { + if (!message) { + log_e("Empty message"); + } + if (message->info.status != ESP_ZB_ZCL_STATUS_SUCCESS) { + log_e("Received message: error status(%d)", message->info.status); + } + esp_zb_zcl_config_report_resp_variable_t *variable = message->variables; + while (variable) { + log_i( + "Configure report response: status(%d), cluster(0x%x), direction(0x%x), attribute(0x%x)", variable->status, message->info.cluster, variable->direction, + variable->attribute_id + ); + variable = variable->next; + } + + return ESP_OK; +} + +static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, const void *message) { + esp_err_t ret = ESP_OK; + switch (callback_id) { + case ESP_ZB_CORE_REPORT_ATTR_CB_ID: ret = zb_attribute_reporting_handler((esp_zb_zcl_report_attr_message_t *)message); break; + case ESP_ZB_CORE_CMD_READ_ATTR_RESP_CB_ID: ret = zb_read_attr_resp_handler((esp_zb_zcl_cmd_read_attr_resp_message_t *)message); break; + case ESP_ZB_CORE_CMD_REPORT_CONFIG_RESP_CB_ID: ret = zb_configure_report_resp_handler((esp_zb_zcl_cmd_config_report_resp_message_t *)message); break; + default: log_w("Receive Zigbee action(0x%x) callback", callback_id); break; + } + return ret; +} + +static esp_zb_cluster_list_t *custom_thermostat_clusters_create(esp_zb_thermostat_cfg_t *thermostat) { + esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create(); + esp_zb_attribute_list_t *basic_cluster = esp_zb_basic_cluster_create(&(thermostat->basic_cfg)); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, (void *)MANUFACTURER_NAME)); + ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, (void *)MODEL_IDENTIFIER)); + ESP_ERROR_CHECK(esp_zb_cluster_list_add_basic_cluster(cluster_list, basic_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE)); + ESP_ERROR_CHECK( + esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_identify_cluster_create(&(thermostat->identify_cfg)), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE) + ); + ESP_ERROR_CHECK( + esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_IDENTIFY), ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE) + ); + ESP_ERROR_CHECK( + esp_zb_cluster_list_add_thermostat_cluster(cluster_list, esp_zb_thermostat_cluster_create(&(thermostat->thermostat_cfg)), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE) + ); + /* Add temperature measurement cluster for attribute reporting */ + ESP_ERROR_CHECK(esp_zb_cluster_list_add_temperature_meas_cluster(cluster_list, esp_zb_temperature_meas_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE)); + return cluster_list; +} + +static esp_zb_ep_list_t *custom_thermostat_ep_create(uint8_t endpoint_id, esp_zb_thermostat_cfg_t *thermostat) { + esp_zb_ep_list_t *ep_list = esp_zb_ep_list_create(); + esp_zb_endpoint_config_t endpoint_config = { + .endpoint = endpoint_id, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_THERMOSTAT_DEVICE_ID, .app_device_version = 0 + }; + esp_zb_ep_list_add_ep(ep_list, custom_thermostat_clusters_create(thermostat), endpoint_config); + return ep_list; +} + +static void esp_zb_task(void *pvParameters) { + /* Initialize Zigbee stack */ + esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZC_CONFIG(); + esp_zb_init(&zb_nwk_cfg); + /* Create customized thermostat endpoint */ + esp_zb_thermostat_cfg_t thermostat_cfg = ESP_ZB_DEFAULT_THERMOSTAT_CONFIG(); + esp_zb_ep_list_t *esp_zb_thermostat_ep = custom_thermostat_ep_create(HA_THERMOSTAT_ENDPOINT, &thermostat_cfg); + /* Register the device */ + esp_zb_device_register(esp_zb_thermostat_ep); + + esp_zb_core_action_handler_register(zb_action_handler); + esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK); + ESP_ERROR_CHECK(esp_zb_start(false)); + esp_zb_main_loop_iteration(); +} + +/********************* GPIO functions **************************/ +static QueueHandle_t gpio_evt_queue = NULL; + +static void IRAM_ATTR gpio_isr_handler(void *arg) { + xQueueSendFromISR(gpio_evt_queue, (switch_func_pair_t *)arg, NULL); +} + +static void switch_gpios_intr_enabled(bool enabled) { + for (int i = 0; i < PAIR_SIZE(button_func_pair); ++i) { + if (enabled) { + enableInterrupt((button_func_pair[i]).pin); + } else { + disableInterrupt((button_func_pair[i]).pin); + } + } +} + +/********************* Arduino functions **************************/ +void setup() { + // Init Zigbee + esp_zb_platform_config_t config = { + .radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_ZB_DEFAULT_HOST_CONFIG(), + }; + + ESP_ERROR_CHECK(esp_zb_platform_config(&config)); + + // Init button switch + for (int i = 0; i < PAIR_SIZE(button_func_pair); i++) { + pinMode(button_func_pair[i].pin, INPUT_PULLUP); + /* create a queue to handle gpio event from isr */ + gpio_evt_queue = xQueueCreate(10, sizeof(switch_func_pair_t)); + if (gpio_evt_queue == 0) { + log_e("Queue was not created and must not be used"); + while (1); + } + attachInterruptArg(button_func_pair[i].pin, gpio_isr_handler, (void *)(button_func_pair + i), FALLING); + } + + // Start Zigbee task + xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL); +} + +void loop() { + // Handle button switch in loop() + uint8_t pin = 0; + switch_func_pair_t button_func_pair; + static switch_state_t switch_state = SWITCH_IDLE; + bool evt_flag = false; + + /* check if there is any queue received, if yes read out the button_func_pair */ + if (xQueueReceive(gpio_evt_queue, &button_func_pair, portMAX_DELAY)) { + pin = button_func_pair.pin; + switch_gpios_intr_enabled(false); + evt_flag = true; + } + while (evt_flag) { + bool value = digitalRead(pin); + switch (switch_state) { + case SWITCH_IDLE: switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_IDLE; break; + case SWITCH_PRESS_DETECTED: switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_RELEASE_DETECTED; break; + case SWITCH_RELEASE_DETECTED: + switch_state = SWITCH_IDLE; + /* callback to button_handler */ + (*esp_zb_buttons_handler)(&button_func_pair); + break; + default: break; + } + if (switch_state == SWITCH_IDLE) { + switch_gpios_intr_enabled(true); + evt_flag = false; + break; + } + delay(10); + } +} diff --git a/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp b/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp index 1dc2e75bbce..1ef03f29dff 100644 --- a/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp +++ b/libraries/NetworkClientSecure/src/NetworkClientSecure.cpp @@ -83,7 +83,7 @@ void NetworkClientSecure::stop() { stop_ssl_socket(sslclient.get()); _connected = false; - _peek = -1; + sslclient->peek_buf = -1; _lastReadTimeout = 0; _lastWriteTimeout = 0; } @@ -134,7 +134,7 @@ int NetworkClientSecure::connect(IPAddress ip, uint16_t port, const char *host, log_i("Actual TLS start postponed."); } - _lastError = ret; + sslclient->last_error = ret; if (ret < 0) { log_e("start_ssl_client: connect failed: %d", ret); @@ -175,7 +175,7 @@ int NetworkClientSecure::connect(const char *host, uint16_t port, const char *ps } int ret = start_ssl_client(sslclient.get(), address, port, host, _timeout, NULL, false, NULL, NULL, pskIdent, psKey, _use_insecure, _alpn_protos); - _lastError = ret; + sslclient->last_error = ret; if (ret < 0) { log_e("start_ssl_client: connect failed %d", ret); stop(); @@ -186,11 +186,11 @@ int NetworkClientSecure::connect(const char *host, uint16_t port, const char *ps } int NetworkClientSecure::peek() { - if (_peek >= 0) { - return _peek; + if (sslclient->peek_buf >= 0) { + return sslclient->peek_buf; } - _peek = timedRead(); - return _peek; + sslclient->peek_buf = timedRead(); + return sslclient->peek_buf; } size_t NetworkClientSecure::write(uint8_t data) { @@ -253,9 +253,9 @@ int NetworkClientSecure::read(uint8_t *buf, size_t size) { if (!size) { return 0; } - if (_peek >= 0) { - buf[0] = _peek; - _peek = -1; + if (sslclient->peek_buf >= 0) { + buf[0] = sslclient->peek_buf; + sslclient->peek_buf = -1; size--; avail--; if (!size || !avail) { @@ -279,7 +279,7 @@ int NetworkClientSecure::available() { return peek_net_receive(sslclient.get(), 0); } - int peeked = (_peek >= 0), res = -1; + int peeked = (sslclient->peek_buf >= 0), res = -1; if (!_connected) { return peeked; } @@ -399,11 +399,9 @@ bool NetworkClientSecure::loadPrivateKey(Stream &stream, size_t size) { } int NetworkClientSecure::lastError(char *buf, const size_t size) { - if (!_lastError) { - return 0; - } - mbedtls_strerror(_lastError, buf, size); - return _lastError; + int lastError = sslclient->last_error; + mbedtls_strerror(lastError, buf, size); + return lastError; } void NetworkClientSecure::setHandshakeTimeout(unsigned long handshake_timeout) { diff --git a/libraries/NetworkClientSecure/src/NetworkClientSecure.h b/libraries/NetworkClientSecure/src/NetworkClientSecure.h index 50520e072ef..e7831a68839 100644 --- a/libraries/NetworkClientSecure/src/NetworkClientSecure.h +++ b/libraries/NetworkClientSecure/src/NetworkClientSecure.h @@ -30,9 +30,6 @@ class NetworkClientSecure : public NetworkClient { protected: std::shared_ptr sslclient; - int _lastError = 0; - int _peek = -1; - int _timeout; bool _use_insecure; bool _stillinPlainStart = false; const char *_CA_cert; diff --git a/libraries/NetworkClientSecure/src/ssl_client.cpp b/libraries/NetworkClientSecure/src/ssl_client.cpp index b33782b71f2..41e79ee3803 100644 --- a/libraries/NetworkClientSecure/src/ssl_client.cpp +++ b/libraries/NetworkClientSecure/src/ssl_client.cpp @@ -48,6 +48,7 @@ void ssl_init(sslclient_context *ssl_client) { mbedtls_ssl_init(&ssl_client->ssl_ctx); mbedtls_ssl_config_init(&ssl_client->ssl_conf); mbedtls_ctr_drbg_init(&ssl_client->drbg_ctx); + ssl_client->peek_buf = -1; } int start_ssl_client( @@ -368,12 +369,15 @@ void stop_ssl_socket(sslclient_context *ssl_client) { // save only interesting fields int handshake_timeout = ssl_client->handshake_timeout; int socket_timeout = ssl_client->socket_timeout; + int last_err = ssl_client->last_error; // reset embedded pointers to zero memset(ssl_client, 0, sizeof(sslclient_context)); ssl_client->handshake_timeout = handshake_timeout; ssl_client->socket_timeout = socket_timeout; + ssl_client->last_error = last_err; + ssl_client->peek_buf = -1; } int data_to_read(sslclient_context *ssl_client) { diff --git a/libraries/NetworkClientSecure/src/ssl_client.h b/libraries/NetworkClientSecure/src/ssl_client.h index 2309996bb14..3e07bf6bc2c 100644 --- a/libraries/NetworkClientSecure/src/ssl_client.h +++ b/libraries/NetworkClientSecure/src/ssl_client.h @@ -26,6 +26,10 @@ typedef struct sslclient_context { unsigned long socket_timeout; unsigned long handshake_timeout; + + int last_error; + int peek_buf; + } sslclient_context; void ssl_init(sslclient_context *ssl_client); diff --git a/libraries/USB/examples/MIDI/MidiController/MidiController.ino b/libraries/USB/examples/MIDI/MidiController/MidiController.ino index 65381fc2d7e..2871d3b1a52 100644 --- a/libraries/USB/examples/MIDI/MidiController/MidiController.ino +++ b/libraries/USB/examples/MIDI/MidiController/MidiController.ino @@ -22,7 +22,7 @@ void loop() {} #include "USBMIDI.h" USBMIDI MIDI; -#define MIDI_NOTE_C4 64 +#define MIDI_NOTE_C4 60 #define MIDI_CC_CUTOFF 74 @@ -69,7 +69,7 @@ void setup() { Serial.begin(115200); MIDI.begin(); USB.begin(); - + pinMode(BUTTON_PIN, INPUT_PULLUP); primeControllerInputValue(); } diff --git a/libraries/USB/src/USBHIDMouse.h b/libraries/USB/src/USBHIDMouse.h index c1c11c9cbc0..9b9e348bb14 100644 --- a/libraries/USB/src/USBHIDMouse.h +++ b/libraries/USB/src/USBHIDMouse.h @@ -34,8 +34,6 @@ #define MOUSE_FORWARD 0x10 #define MOUSE_ALL 0x1F -#include "./tusb_hid_mouse.h" - enum MousePositioning_t { HID_MOUSE_RELATIVE, HID_MOUSE_ABSOLUTE diff --git a/libraries/USB/src/tusb_hid_mouse.h b/libraries/USB/src/tusb_hid_mouse.h deleted file mode 100644 index 4c7cc52e348..00000000000 --- a/libraries/USB/src/tusb_hid_mouse.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include "class/hid/hid_device.h" - -#if !defined TUD_HID_REPORT_DESC_ABSMOUSE -// This version of arduino-esp32 does not handle absolute mouse natively. -// Let's throw a minimalistic implementation of absmouse driver. -// See: https://github.com/hathach/tinyusb/pull/1363 -// Also see: https://github.com/espressif/arduino-esp32/pull/6331 - -extern "C" { - -// Absolute Mouse data struct is a copy of the relative mouse struct -// with int16_t instead of int8_t for X and Y coordinates. -typedef struct TU_ATTR_PACKED { - uint8_t buttons = 0; - int16_t x = 0; - int16_t y = 0; - int8_t wheel = 0; - int8_t pan = 0; -} hid_abs_mouse_report_t; - -// Absolute Mouse Report Descriptor Template applies those datatype changes too -#define TUD_HID_REPORT_DESC_ABSMOUSE(...) \ - HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), HID_USAGE(HID_USAGE_DESKTOP_MOUSE), HID_COLLECTION(HID_COLLECTION_APPLICATION), /* Report ID if any */ \ - __VA_ARGS__ HID_USAGE(HID_USAGE_DESKTOP_POINTER), HID_COLLECTION(HID_COLLECTION_PHYSICAL), HID_USAGE_PAGE(HID_USAGE_PAGE_BUTTON), HID_USAGE_MIN(1), \ - HID_USAGE_MAX(5), HID_LOGICAL_MIN(0), HID_LOGICAL_MAX(1), /* Left, Right, Middle, Backward, Forward buttons */ \ - HID_REPORT_COUNT(5), HID_REPORT_SIZE(1), HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), /* 3 bit padding */ \ - HID_REPORT_COUNT(1), HID_REPORT_SIZE(3), HID_INPUT(HID_CONSTANT), HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), /* X, Y absolute position [0, 32767] */ \ - HID_USAGE(HID_USAGE_DESKTOP_X), HID_USAGE(HID_USAGE_DESKTOP_Y), HID_LOGICAL_MIN(0x00), HID_LOGICAL_MAX_N(0x7FFF, 2), HID_REPORT_SIZE(16), \ - HID_REPORT_COUNT(2), HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), /* Vertical wheel scroll [-127, 127] */ \ - HID_USAGE(HID_USAGE_DESKTOP_WHEEL), HID_LOGICAL_MIN(0x81), HID_LOGICAL_MAX(0x7f), HID_REPORT_COUNT(1), HID_REPORT_SIZE(8), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_RELATIVE), HID_USAGE_PAGE(HID_USAGE_PAGE_CONSUMER), /* Horizontal wheel scroll [-127, 127] */ \ - HID_USAGE_N(HID_USAGE_CONSUMER_AC_PAN, 2), HID_LOGICAL_MIN(0x81), HID_LOGICAL_MAX(0x7f), HID_REPORT_COUNT(1), HID_REPORT_SIZE(8), \ - HID_INPUT(HID_DATA | HID_VARIABLE | HID_RELATIVE), HID_COLLECTION_END, HID_COLLECTION_END - -static inline bool tud_hid_n_abs_mouse_report(uint8_t instance, uint8_t report_id, uint8_t buttons, int16_t x, int16_t y, int8_t vertical, int8_t horizontal) { - hid_abs_mouse_report_t report = {.buttons = buttons, .x = x, .y = y, .wheel = vertical, .pan = horizontal}; - return tud_hid_n_report(instance, report_id, &report, sizeof(report)); -} - -static inline bool tud_hid_abs_mouse_report(uint8_t report_id, uint8_t buttons, int16_t x, int16_t y, int8_t vertical, int8_t horizontal) { - return tud_hid_n_abs_mouse_report(0, report_id, buttons, x, y, vertical, horizontal); -} - -} // end extern "C" - -#else -#pragma message "This file is now safe to delete along with its include from USBHIDMouse.h" -#endif diff --git a/libraries/WiFi/src/STA.cpp b/libraries/WiFi/src/STA.cpp index c3fbe9c52c9..8fb25ba86cb 100644 --- a/libraries/WiFi/src/STA.cpp +++ b/libraries/WiFi/src/STA.cpp @@ -433,7 +433,7 @@ bool STAClass::connect(const char *ssid, const char *passphrase, int32_t channel */ bool STAClass::connect( const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity, const char *wpa2_username, const char *wpa2_password, const char *ca_pem, - const char *client_crt, const char *client_key, int32_t channel, const uint8_t *bssid, bool tryConnect + const char *client_crt, const char *client_key, int ttls_phase2_type, int32_t channel, const uint8_t *bssid, bool tryConnect ) { if (_esp_netif == NULL) { log_e("STA not started! You must call begin() first."); @@ -467,6 +467,14 @@ bool STAClass::connect( return false; } + if (ttls_phase2_type >= 0) { +#if __has_include("esp_eap_client.h") + esp_eap_client_set_ttls_phase2_method((esp_eap_ttls_phase2_types)ttls_phase2_type); +#else + esp_wifi_sta_wpa2_ent_set_ttls_phase2_method((esp_eap_ttls_phase2_types)ttls_phase2_type); +#endif + } + if (ca_pem) { #if __has_include("esp_eap_client.h") esp_eap_client_set_ca_cert((uint8_t *)ca_pem, strlen(ca_pem)); @@ -503,7 +511,7 @@ bool STAClass::connect( esp_wifi_sta_wpa2_ent_enable(); //set config settings to enable function #endif - return connect(wpa2_ssid, NULL, 0, NULL, tryConnect); //connect to wifi + return connect(wpa2_ssid, NULL, channel, bssid, tryConnect); //connect to wifi } bool STAClass::disconnect(bool eraseap, unsigned long timeout) { diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index 470db1a5675..1c1ce42c12f 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -65,13 +65,13 @@ wl_status_t WiFiSTAClass::status() { wl_status_t WiFiSTAClass::begin( const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity, const char *wpa2_username, const char *wpa2_password, const char *ca_pem, - const char *client_crt, const char *client_key, int32_t channel, const uint8_t *bssid, bool connect + const char *client_crt, const char *client_key, int ttls_phase2_type, int32_t channel, const uint8_t *bssid, bool connect ) { if (!STA.begin()) { return WL_CONNECT_FAILED; } - if (!STA.connect(wpa2_ssid, method, wpa2_identity, wpa2_username, wpa2_password, ca_pem, client_crt, client_key, channel, bssid, connect)) { + if (!STA.connect(wpa2_ssid, method, wpa2_identity, wpa2_username, wpa2_password, ca_pem, client_crt, client_key, ttls_phase2_type, channel, bssid, connect)) { return WL_CONNECT_FAILED; } diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index d5c5d377d3b..2c046c4c4b9 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -55,7 +55,8 @@ class STAClass : public NetworkInterface { bool connect(const char *ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t *bssid = NULL, bool connect = true); bool connect( const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity = NULL, const char *wpa2_username = NULL, const char *wpa2_password = NULL, - const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true + const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int ttls_phase2_type = -1, int32_t channel = 0, + const uint8_t *bssid = 0, bool connect = true ); bool disconnect(bool eraseap = false, unsigned long timeout = 0); bool reconnect(); @@ -109,16 +110,17 @@ class WiFiSTAClass { wl_status_t begin( const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity = NULL, const char *wpa2_username = NULL, const char *wpa2_password = NULL, - const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true + const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int ttls_phase2_type = -1, int32_t channel = 0, + const uint8_t *bssid = 0, bool connect = true ); wl_status_t begin( const String &wpa2_ssid, wpa2_auth_method_t method, const String &wpa2_identity = (const char *)NULL, const String &wpa2_username = (const char *)NULL, const String &wpa2_password = (const char *)NULL, const String &ca_pem = (const char *)NULL, const String &client_crt = (const char *)NULL, - const String &client_key = (const char *)NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true + const String &client_key = (const char *)NULL, int ttls_phase2_type = -1, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true ) { return begin( wpa2_ssid.c_str(), method, wpa2_identity.c_str(), wpa2_username.c_str(), wpa2_password.c_str(), ca_pem.c_str(), client_crt.c_str(), client_key.c_str(), - channel, bssid, connect + ttls_phase2_type, channel, bssid, connect ); } wl_status_t begin(const char *ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t *bssid = NULL, bool connect = true);