diff --git a/.github/scripts/install-platformio-esp32.sh b/.github/scripts/install-platformio-esp32.sh deleted file mode 100755 index 8cd6552eb..000000000 --- a/.github/scripts/install-platformio-esp32.sh +++ /dev/null @@ -1,186 +0,0 @@ -#!/bin/bash - -export PLATFORMIO_ESP32_PATH="$HOME/.platformio/packages/framework-arduinoespressif32" -PLATFORMIO_ESP32_URL="https://github.com/platformio/platform-espressif32.git" - -TOOLCHAIN_VERSION="12.2.0+20230208" -ESPTOOLPY_VERSION="~1.40501.0" -ESPRESSIF_ORGANIZATION_NAME="espressif" -SDKCONFIG_DIR="$PLATFORMIO_ESP32_PATH/tools/esp32-arduino-libs" -SCRIPTS_DIR="./.github/scripts" -COUNT_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh count" -CHECK_REQUIREMENTS="${SCRIPTS_DIR}/sketch_utils.sh check_requirements" - -echo "Installing Python Wheel ..." -pip install wheel > /dev/null 2>&1 - -echo "Installing PlatformIO ..." -pip install -U https://github.com/platformio/platformio/archive/master.zip > /dev/null 2>&1 - -echo "Installing Platform ESP32 ..." -python -m platformio platform install $PLATFORMIO_ESP32_URL > /dev/null 2>&1 - -echo "Replacing the package versions ..." -replace_script="import json; import os;" -replace_script+="fp=open(os.path.expanduser('~/.platformio/platforms/espressif32/platform.json'), 'r+');" -replace_script+="data=json.load(fp);" -# Use framework sources from the repository -replace_script+="data['packages']['framework-arduinoespressif32']['version'] = '*';" -replace_script+="del data['packages']['framework-arduinoespressif32']['owner'];" -# Use toolchain packages from the "espressif" organization -replace_script+="data['packages']['toolchain-xtensa-esp32']['owner']='$ESPRESSIF_ORGANIZATION_NAME';" -replace_script+="data['packages']['toolchain-xtensa-esp32s2']['owner']='$ESPRESSIF_ORGANIZATION_NAME';" -replace_script+="data['packages']['toolchain-riscv32-esp']['owner']='$ESPRESSIF_ORGANIZATION_NAME';" -# Update versions to use the upstream -replace_script+="data['packages']['toolchain-xtensa-esp32']['version']='$TOOLCHAIN_VERSION';" -replace_script+="data['packages']['toolchain-xtensa-esp32s2']['version']='$TOOLCHAIN_VERSION';" -replace_script+="data['packages']['toolchain-xtensa-esp32s3']['version']='$TOOLCHAIN_VERSION';" -replace_script+="data['packages']['toolchain-riscv32-esp']['version']='$TOOLCHAIN_VERSION';" -# Add new "framework-arduinoespressif32-libs" package -# Read "package_esp32_index.template.json" to extract a url to a zip package for "esp32-arduino-libs" -replace_script+="fpackage=open(os.path.join('package', 'package_esp32_index.template.json'), 'r+');" -replace_script+="package_data=json.load(fpackage);" -replace_script+="fpackage.close();" -replace_script+="libs_package_archive_url=next(next(system['url'] for system in tool['systems'] if system['host'] == 'x86_64-pc-linux-gnu') for tool in package_data['packages'][0]['tools'] if tool['name'] == 'esp32-arduino-libs');" -replace_script+="data['packages'].update({'framework-arduinoespressif32-libs':{'type':'framework','optional':False,'version':libs_package_archive_url}});" -replace_script+="data['packages']['toolchain-xtensa-esp32'].update({'optional':False});" -# esptool.py may require an upstream version (for now platformio is the owner) -replace_script+="data['packages']['tool-esptoolpy']['version']='$ESPTOOLPY_VERSION';" -# Save results -replace_script+="fp.seek(0);fp.truncate();json.dump(data, fp, indent=2);fp.close()" -python -c "$replace_script" - -if [ "$GITHUB_REPOSITORY" == "espressif/arduino-esp32" ]; then - echo "Linking Core..." - ln -s "$GITHUB_WORKSPACE" "$PLATFORMIO_ESP32_PATH" -else - echo "Cloning Core Repository ..." - git clone --recursive https://github.com/espressif/arduino-esp32.git "$PLATFORMIO_ESP32_PATH" > /dev/null 2>&1 -fi - -echo "PlatformIO for ESP32 has been installed" -echo "" - -function build_pio_sketch { # build_pio_sketch - if [ "$#" -lt 3 ]; then - echo "ERROR: Illegal number of parameters" - echo "USAGE: build_pio_sketch " - return 1 - fi - - local board="$1" - local options="$2" - local sketch="$3" - local sketch_dir - - sketch_dir=$(dirname "$sketch") - echo "" - echo "Compiling '$(basename "$sketch")' ..." - python -m platformio ci --board "$board" "$sketch_dir" --project-option="$options" -} - -function build_pio_sketches { # build_pio_sketches - if [ "$#" -lt 3 ]; then - echo "ERROR: Illegal number of parameters" - echo "USAGE: build_pio_sketches [ ]" - return 1 - fi - - local board=$1 - local options="$2" - local examples=$3 - local chunk_idex=$4 - local chunks_num=$5 - - if [ "$#" -lt 5 ]; then - chunk_idex="0" - chunks_num="1" - fi - - if [ "$chunks_num" -le 0 ]; then - echo "ERROR: Chunks count must be positive number" - return 1 - fi - if [ "$chunk_idex" -ge "$chunks_num" ]; then - echo "ERROR: Chunk index must be less than chunks count" - return 1 - fi - - set +e - ${COUNT_SKETCHES} "$examples" "esp32" - local sketchcount=$? - set -e - local sketches - sketches=$(cat sketches.txt) - rm -rf sketches.txt - - local chunk_size - local all_chunks - local start_index - local end_index - local start_num - - chunk_size=$(( sketchcount / chunks_num )) - all_chunks=$(( chunks_num * chunk_size )) - if [ "$all_chunks" -lt "$sketchcount" ]; then - chunk_size=$(( chunk_size + 1 )) - fi - - start_index=$(( chunk_idex * chunk_size )) - if [ "$sketchcount" -le "$start_index" ]; then - echo "Skipping job" - return 0 - fi - - end_index=$(( $(( chunk_idex + 1 )) * chunk_size )) - if [ "$end_index" -gt "$sketchcount" ]; then - end_index=$sketchcount - fi - - start_num=$(( start_index + 1 )) - echo "Found $sketchcount Sketches"; - echo "Chunk Count : $chunks_num" - echo "Chunk Size : $chunk_size" - echo "Start Sketch: $start_num" - echo "End Sketch : $end_index" - - local sketchnum=0 - for sketch in $sketches; do - local sketchdir - local sketchdirname - local sketchname - local is_target - local has_requirements - - sketchdir=$(dirname "$sketch") - sketchdirname=$(basename "$sketchdir") - sketchname=$(basename "$sketch") - - if [[ "$sketchdirname.ino" != "$sketchname" ]]; then - continue - elif [ -f "$sketchdir"/ci.json ]; then - # If the target is listed as false, skip the sketch. Otherwise, include it. - is_target=$(jq -r '.targets[esp32]' "$sketchdir"/ci.json) - if [[ "$is_target" == "false" ]]; then - continue - fi - - has_requirements=$(${CHECK_REQUIREMENTS} "$sketchdir" "$SDKCONFIG_DIR/esp32/sdkconfig") - if [ "$has_requirements" == "0" ]; then - continue - fi - fi - - sketchnum=$((sketchnum + 1)) - if [ "$sketchnum" -le "$start_index" ] \ - || [ "$sketchnum" -gt "$end_index" ]; then - continue - fi - build_pio_sketch "$board" "$options" "$sketch" - local result=$? - if [ $result -ne 0 ]; then - return $result - fi - done - return 0 -} diff --git a/.github/scripts/on-push.sh b/.github/scripts/on-push.sh index 5158df3cc..aafc9de05 100755 --- a/.github/scripts/on-push.sh +++ b/.github/scripts/on-push.sh @@ -55,14 +55,11 @@ CHUNK_INDEX=$1 CHUNKS_CNT=$2 BUILD_LOG=$3 SKETCHES_FILE=$4 -BUILD_PIO=0 if [ "$#" -lt 2 ] || [ "$CHUNKS_CNT" -le 0 ]; then CHUNK_INDEX=0 CHUNKS_CNT=1 elif [ "$CHUNK_INDEX" -gt "$CHUNKS_CNT" ] && [ "$CHUNKS_CNT" -ge 2 ]; then CHUNK_INDEX=$CHUNKS_CNT -elif [ "$CHUNK_INDEX" -eq "$CHUNKS_CNT" ]; then - BUILD_PIO=1 fi if [ -z "$BUILD_LOG" ] || [ "$BUILD_LOG" -le 0 ]; then @@ -73,54 +70,35 @@ fi #git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1 SCRIPTS_DIR="./.github/scripts" -if [ "$BUILD_PIO" -eq 0 ]; then - source "${SCRIPTS_DIR}/install-arduino-cli.sh" - source "${SCRIPTS_DIR}/install-arduino-core-esp32.sh" +source "${SCRIPTS_DIR}/install-arduino-cli.sh" +source "${SCRIPTS_DIR}/install-arduino-core-esp32.sh" - SKETCHES_ESP32=( - "$ARDUINO_ESP32_PATH/libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" - "$ARDUINO_ESP32_PATH/libraries/BLE/examples/Server/Server.ino" - "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" - "$ARDUINO_ESP32_PATH/libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics.ino" - ) - #create sizes_file - sizes_file="$GITHUB_WORKSPACE/cli_compile_$CHUNK_INDEX.json" +SKETCHES_ESP32=( + "$ARDUINO_ESP32_PATH/libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" + "$ARDUINO_ESP32_PATH/libraries/BLE/examples/Server/Server.ino" + "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" + "$ARDUINO_ESP32_PATH/libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics.ino" +) +#create sizes_file +sizes_file="$GITHUB_WORKSPACE/cli_compile_$CHUNK_INDEX.json" - if [ "$BUILD_LOG" -eq 1 ]; then - #create sizes_file and echo start of JSON array with "boards" key - echo "{\"boards\": [" > "$sizes_file" - fi - - #build sketches for different targets - build "esp32p4" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" - build "esp32s3" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" - build "esp32s2" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" - build "esp32c3" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" - build "esp32c6" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" - build "esp32h2" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" - build "esp32" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" - - if [ "$BUILD_LOG" -eq 1 ]; then - #remove last comma from the last JSON object - sed -i '$ s/,$//' "$sizes_file" - #echo end of JSON array - echo "]}" >> "$sizes_file" - fi -else - source "${SCRIPTS_DIR}/install-platformio-esp32.sh" - # PlatformIO ESP32 Test - BOARD="esp32dev" - OPTIONS="board_build.partitions = huge_app.csv" - build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ - build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \ - build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \ - build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/BLE/examples/Server/Server.ino" && \ - build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" - - # Basic sanity testing for other series - for board in "esp32-c3-devkitm-1" "esp32-s2-saola-1" "esp32-s3-devkitc-1"; do - python -m platformio ci --board "$board" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.partitions = huge_app.csv" - done - - #build_pio_sketches "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries" +if [ "$BUILD_LOG" -eq 1 ]; then + #create sizes_file and echo start of JSON array with "boards" key + echo "{\"boards\": [" > "$sizes_file" +fi + +#build sketches for different targets +build "esp32p4" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" +build "esp32s3" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" +build "esp32s2" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" +build "esp32c3" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" +build "esp32c6" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" +build "esp32h2" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" +build "esp32" "$CHUNK_INDEX" "$CHUNKS_CNT" "$BUILD_LOG" "$SKETCHES_FILE" "${SKETCHES_ESP32[@]}" + +if [ "$BUILD_LOG" -eq 1 ]; then + #remove last comma from the last JSON object + sed -i '$ s/,$//' "$sizes_file" + #echo end of JSON array + echo "]}" >> "$sizes_file" fi diff --git a/.github/scripts/on-release.sh b/.github/scripts/on-release.sh index 119c66e1e..242cee93d 100755 --- a/.github/scripts/on-release.sh +++ b/.github/scripts/on-release.sh @@ -239,7 +239,7 @@ cp -f "$GITHUB_WORKSPACE/tools/gen_insights_package.py" "$PKG_DIR/tools/" cp -f "$GITHUB_WORKSPACE/tools/gen_insights_package.exe" "$PKG_DIR/tools/" cp -Rf "$GITHUB_WORKSPACE/tools/partitions" "$PKG_DIR/tools/" cp -Rf "$GITHUB_WORKSPACE/tools/ide-debug" "$PKG_DIR/tools/" -cp -f "$GITHUB_WORKSPACE/tools/platformio-build.py" "$PKG_DIR/tools/" +cp -f "$GITHUB_WORKSPACE/tools/pioarduino-build.py" "$PKG_DIR/tools/" # Remove unnecessary files in the package folder echo "Cleaning up folders ..." diff --git a/.github/scripts/set_push_chunks.sh b/.github/scripts/set_push_chunks.sh index 047cae6ef..ff0af7da6 100644 --- a/.github/scripts/set_push_chunks.sh +++ b/.github/scripts/set_push_chunks.sh @@ -79,7 +79,6 @@ chunks+="]" echo "build_libraries=$BUILD_LIBRARIES" echo "build_static_sketches=$BUILD_STATIC_SKETCHES" echo "build_idf=$BUILD_IDF" - echo "build_platformio=$BUILD_PLATFORMIO" echo "chunk_count=$chunks_count" echo "chunks=$chunks" } >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 4f30bdbb8..e6f497998 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -61,7 +61,6 @@ jobs: build_libraries: ${{ steps.set-chunks.outputs.build_libraries }} build_static_sketches: ${{ steps.set-chunks.outputs.build_static_sketches }} build_idf: ${{ steps.set-chunks.outputs.build_idf }} - build_platformio: ${{ steps.set-chunks.outputs.build_platformio }} chunk_count: ${{ steps.set-chunks.outputs.chunk_count }} chunks: ${{ steps.set-chunks.outputs.chunks }} steps: @@ -77,11 +76,9 @@ jobs: files_yaml: | core: - '.github/**' - - '!.github/scripts/install-platformio-esp32.sh' - 'cores/**' - 'package/**' - 'tools/**' - - '!tools/platformio-build.py' - 'platform.txt' - 'programmers.txt' - "variants/esp32/**/*" @@ -110,10 +107,6 @@ jobs: - 'Kconfig.projbuild' - 'CMakeLists.txt' - "variants/esp32c2/**/*" - platformio: - - 'package.json' - - '.github/scripts/install-platformio-esp32.sh' - - 'tools/platformio-build.py' - name: Set chunks id: set-chunks @@ -121,7 +114,6 @@ jobs: LIB_FILES: ${{ steps.changed-files.outputs.libraries_all_changed_files }} IS_PR: ${{ github.event_name == 'pull_request' }} MAX_CHUNKS: ${{ env.MAX_CHUNKS }} - BUILD_PLATFORMIO: ${{ steps.changed-files.outputs.platformio_any_changed == 'true' }} BUILD_IDF: ${{ steps.changed-files.outputs.idf_any_changed == 'true' }} BUILD_LIBRARIES: ${{ steps.changed-files.outputs.libraries_any_changed == 'true' }} BUILD_STATIC_SKETCHES: ${{ steps.changed-files.outputs.static_sketeches_any_changed == 'true' }} @@ -212,28 +204,6 @@ jobs: - name: Build Sketches run: bash ./.github/scripts/on-push.sh - # # PlatformIO on Windows, Ubuntu and Mac - # build-platformio: - # name: PlatformIO on ${{ matrix.os }} - # needs: gen-chunks - # if: | - # needs.gen-chunks.outputs.build_all == 'true' || - # needs.gen-chunks.outputs.build_static_sketches == 'true' || - # needs.gen-chunks.outputs.build_platformio == 'true' - # runs-on: ${{ matrix.os }} - # strategy: - # fail-fast: false - # matrix: - # os: [ubuntu-latest, windows-latest, macOS-latest] - # steps: - # - uses: actions/checkout@v4 - # - uses: actions/setup-python@v5 - # with: - # python-version: "3.x" - # - name: Build Sketches - # run: bash ./.github/scripts/on-push.sh 1 1 #equal and non-zero to trigger PIO - - # ESP-IDF component build build-esp-idf-component: name: Build with ESP-IDF ${{ matrix.idf_ver }} for ${{ matrix.idf_target }} needs: gen-chunks diff --git a/CMakeLists.txt b/CMakeLists.txt index f3d889eb4..b6478aa16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,6 +178,7 @@ set(ARDUINO_LIBRARY_Matter_SRCS libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.cpp libraries/Matter/src/MatterEndpoints/MatterHumiditySensor.cpp libraries/Matter/src/MatterEndpoints/MatterContactSensor.cpp + libraries/Matter/src/MatterEndpoints/MatterPressureSensor.cpp libraries/Matter/src/Matter.cpp) set(ARDUINO_LIBRARY_PPP_SRCS diff --git a/libraries/Matter/examples/MatterPressureSensor/MatterPressureSensor.ino b/libraries/Matter/examples/MatterPressureSensor/MatterPressureSensor.ino new file mode 100644 index 000000000..aa6b28f19 --- /dev/null +++ b/libraries/Matter/examples/MatterPressureSensor/MatterPressureSensor.ino @@ -0,0 +1,131 @@ +// 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. + +/* + * This example is an example code that will create a Matter Device which can be + * commissioned and controlled from a Matter Environment APP. + * Additionally the ESP32 will send debug messages indicating the Matter activity. + * Turning DEBUG Level ON may be useful to following Matter Accessory and Controller messages. + */ + +// Matter Manager +#include +#include + +// List of Matter Endpoints for this Node +// Matter Pressure Sensor Endpoint +MatterPressureSensor SimulatedPressureSensor; + +// set your board USER BUTTON pin here - decommissioning button +const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button. + +// WiFi is manually set and started +const char *ssid = "your-ssid"; // Change this to your WiFi SSID +const char *password = "your-password"; // Change this to your WiFi password + +// Button control - decommision the Matter Node +uint32_t button_time_stamp = 0; // debouncing control +bool button_state = false; // false = released | true = pressed +const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission + +// Simulate a pressure sensor - add your preferred pressure sensor library code here +float getSimulatedPressure() { + // The Endpoint implementation keeps an uint16_t as internal value information, + // which stores data in hPa (pressure measurement unit) + static float simulatedPressureHWSensor = 950; + + // it will increase from 950 to 1100 hPa in steps of 10 hPa to simulate a pressure sensor + simulatedPressureHWSensor = simulatedPressureHWSensor + 10; + if (simulatedPressureHWSensor > 1100) { + simulatedPressureHWSensor = 950; + } + + return simulatedPressureHWSensor; +} + +void setup() { + // Initialize the USER BUTTON (Boot button) that will be used to decommission the Matter Node + pinMode(buttonPin, INPUT_PULLUP); + + Serial.begin(115200); + + // Manually connect to WiFi + WiFi.begin(ssid, password); + // Wait for connection + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(); + + // set initial pressure sensor measurement + // Simulated Sensor - it shall initially print 900hPa and then move to the 950 to 1100 hPa as pressure range + SimulatedPressureSensor.begin(900.00); + + // Matter beginning - Last step, after all EndPoints are initialized + Matter.begin(); + + // Check Matter Accessory Commissioning state, which may change during execution of loop() + if (!Matter.isDeviceCommissioned()) { + Serial.println(""); + Serial.println("Matter Node is not commissioned yet."); + Serial.println("Initiate the device discovery in your Matter environment."); + Serial.println("Commission it to your Matter hub with the manual pairing code or QR code"); + Serial.printf("Manual pairing code: %s\r\n", Matter.getManualPairingCode().c_str()); + Serial.printf("QR code URL: %s\r\n", Matter.getOnboardingQRCodeUrl().c_str()); + // waits for Matter Pressure Sensor Commissioning. + uint32_t timeCount = 0; + while (!Matter.isDeviceCommissioned()) { + delay(100); + if ((timeCount++ % 50) == 0) { // 50*100ms = 5 sec + Serial.println("Matter Node not commissioned yet. Waiting for commissioning."); + } + } + Serial.println("Matter Node is commissioned and connected to Wi-Fi. Ready for use."); + } +} + +void loop() { + static uint32_t timeCounter = 0; + + // Print the current pressure value every 5s + if (!(timeCounter++ % 10)) { // delaying for 500ms x 10 = 5s + // Print the current pressure value + Serial.printf("Current Pressure is %.02fhPa\r\n", SimulatedPressureSensor.getPressure()); + // Update Pressure from the (Simulated) Hardware Sensor + // Matter APP shall display the updated pressure percent + SimulatedPressureSensor.setPressure(getSimulatedPressure()); + } + + // Check if the button has been pressed + if (digitalRead(buttonPin) == LOW && !button_state) { + // deals with button debouncing + button_time_stamp = millis(); // record the time while the button is pressed. + button_state = true; // pressed. + } + + if (digitalRead(buttonPin) == HIGH && button_state) { + button_state = false; // released + } + + // Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node + uint32_t time_diff = millis() - button_time_stamp; + if (button_state && time_diff > decommissioningTimeout) { + // Factory reset is triggered if the button is pressed longer than 10 seconds + Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again."); + Matter.decommission(); + } + + delay(500); +} diff --git a/libraries/Matter/examples/MatterPressureSensor/ci.json b/libraries/Matter/examples/MatterPressureSensor/ci.json new file mode 100644 index 000000000..556a8a9ee --- /dev/null +++ b/libraries/Matter/examples/MatterPressureSensor/ci.json @@ -0,0 +1,7 @@ +{ + "fqbn_append": "PartitionScheme=huge_app", + "requires": [ + "CONFIG_SOC_WIFI_SUPPORTED=y", + "CONFIG_ESP_MATTER_ENABLE_DATA_MODEL=y" + ] +} diff --git a/libraries/Matter/keywords.txt b/libraries/Matter/keywords.txt index 5b04d6f91..d75e9888a 100644 --- a/libraries/Matter/keywords.txt +++ b/libraries/Matter/keywords.txt @@ -21,6 +21,7 @@ FanModeSequence_t KEYWORD1 MatterTemperatureSensor KEYWORD1 MatterHumiditySensor KEYWORD1 MatterContactSensor KEYWORD1 +MatterPressureSensor KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) @@ -71,6 +72,8 @@ setHumidity KEYWORD2 getHumidity KEYWORD2 setContact KEYWORD2 getContact KEYWORD2 +setPressure KEYWORD2 +getPressure KEYWORD2 ####################################### # Constants (LITERAL1) diff --git a/libraries/Matter/src/Matter.h b/libraries/Matter/src/Matter.h index 65483abb5..02571dbcf 100644 --- a/libraries/Matter/src/Matter.h +++ b/libraries/Matter/src/Matter.h @@ -29,6 +29,7 @@ #include #include #include +#include using namespace esp_matter; @@ -64,6 +65,7 @@ public: friend class MatterTemperatureSensor; friend class MatterHumiditySensor; friend class MatterContactSensor; + friend class MatterPressureSensor; protected: static void _init(); diff --git a/libraries/Matter/src/MatterEndpoints/MatterPressureSensor.cpp b/libraries/Matter/src/MatterEndpoints/MatterPressureSensor.cpp new file mode 100644 index 000000000..a157469c9 --- /dev/null +++ b/libraries/Matter/src/MatterEndpoints/MatterPressureSensor.cpp @@ -0,0 +1,99 @@ +// 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. + +#include +#ifdef CONFIG_ESP_MATTER_ENABLE_DATA_MODEL + +#include +#include + +using namespace esp_matter; +using namespace esp_matter::endpoint; +using namespace chip::app::Clusters; + +bool MatterPressureSensor::attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val) { + bool ret = true; + if (!started) { + log_e("Matter Pressure Sensor device has not begun."); + return false; + } + + log_d("Pressure Sensor Attr update callback: endpoint: %u, cluster: %u, attribute: %u, val: %u", endpoint_id, cluster_id, attribute_id, val->val.u32); + return ret; +} + +MatterPressureSensor::MatterPressureSensor() {} + +MatterPressureSensor::~MatterPressureSensor() { + end(); +} + +bool MatterPressureSensor::begin(int16_t _rawPressure) { + ArduinoMatter::_init(); + + pressure_sensor::config_t pressure_sensor_config; + pressure_sensor_config.pressure_measurement.pressure_measured_value = _rawPressure; + pressure_sensor_config.pressure_measurement.pressure_min_measured_value = nullptr; + pressure_sensor_config.pressure_measurement.pressure_max_measured_value = nullptr; + + // endpoint handles can be used to add/modify clusters + endpoint_t *endpoint = pressure_sensor::create(node::get(), &pressure_sensor_config, ENDPOINT_FLAG_NONE, (void *)this); + if (endpoint == nullptr) { + log_e("Failed to create Pressure Sensor endpoint"); + return false; + } + rawPressure = _rawPressure; + setEndPointId(endpoint::get_id(endpoint)); + log_i("Pressure Sensor created with endpoint_id %d", getEndPointId()); + started = true; + return true; +} + +void MatterPressureSensor::end() { + started = false; +} + +bool MatterPressureSensor::setRawPressure(int16_t _rawPressure) { + if (!started) { + log_e("Matter Pressure Sensor device has not begun."); + return false; + } + + // avoid processing the a "no-change" + if (rawPressure == _rawPressure) { + return true; + } + + esp_matter_attr_val_t pressureVal = esp_matter_invalid(NULL); + + if (!getAttributeVal(PressureMeasurement::Id, PressureMeasurement::Attributes::MeasuredValue::Id, &pressureVal)) { + log_e("Failed to get Pressure Sensor Attribute."); + return false; + } + if (pressureVal.val.i16 != _rawPressure) { + pressureVal.val.i16 = _rawPressure; + bool ret; + ret = updateAttributeVal(PressureMeasurement::Id, PressureMeasurement::Attributes::MeasuredValue::Id, &pressureVal); + if (!ret) { + log_e("Failed to update Pressure Sensor Measurement Attribute."); + return false; + } + rawPressure = _rawPressure; + } + log_v("Pressure Sensor set to %.02f Degrees", (float)_rawPressure / 100.00); + + return true; +} + +#endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */ diff --git a/libraries/Matter/src/MatterEndpoints/MatterPressureSensor.h b/libraries/Matter/src/MatterEndpoints/MatterPressureSensor.h new file mode 100644 index 000000000..9fdd90c6e --- /dev/null +++ b/libraries/Matter/src/MatterEndpoints/MatterPressureSensor.h @@ -0,0 +1,62 @@ +// 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. + +#pragma once +#include +#ifdef CONFIG_ESP_MATTER_ENABLE_DATA_MODEL + +#include +#include + +class MatterPressureSensor : public MatterEndPoint { +public: + MatterPressureSensor(); + ~MatterPressureSensor(); + // begin Matter Pressure Sensor endpoint with initial float pressure + bool begin(double pressure = 0.00) { + return begin(static_cast(pressure)); + } + // this will stop processing Pressure Sensor Matter events + void end(); + + // set the reported raw pressure in hPa + bool setPressure(double pressure) { + int16_t rawValue = static_cast(pressure); + return setRawPressure(rawValue); + } + // returns the reported float pressure in hPa + double getPressure() { + return (double)rawPressure; + } + // double conversion operator + void operator=(double pressure) { + setPressure(pressure); + } + // double conversion operator + operator double() { + return (double)getPressure(); + } + + // this function is called by Matter internal event processor. It could be overwritten by the application, if necessary. + bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val); + +protected: + bool started = false; + // implementation keeps pressure in hPa + int16_t rawPressure = 0; + // internal function to set the raw pressure value (Matter Cluster) + bool setRawPressure(int16_t _rawPressure); + bool begin(int16_t _rawPressure); +}; +#endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */ diff --git a/package/package_esp32_index.template.json b/package/package_esp32_index.template.json index 6b5a6370a..63bb10254 100644 --- a/package/package_esp32_index.template.json +++ b/package/package_esp32_index.template.json @@ -42,7 +42,7 @@ { "packager": "esp32", "name": "esp32-arduino-libs", - "version": "idf-release_v5.3-a0f798cf" + "version": "idf-release_v5.3-083aad99-v1" }, { "packager": "esp32", @@ -95,63 +95,63 @@ "tools": [ { "name": "esp32-arduino-libs", - "version": "idf-release_v5.3-a0f798cf", + "version": "idf-release_v5.3-083aad99-v1", "systems": [ { "host": "i686-mingw32", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "checksum": "SHA-256:f552d02ecef616389f1d0c973cb270718a192e6258db426656cd5965db3c6ed0", - "size": "339750940" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "checksum": "SHA-256:5aabafdd3bdc2cfc4a409efc00202aee4d8b1bcb1efaf5021c02ac2e90473603", + "size": "341111216" }, { "host": "x86_64-mingw32", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "checksum": "SHA-256:f552d02ecef616389f1d0c973cb270718a192e6258db426656cd5965db3c6ed0", - "size": "339750940" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "checksum": "SHA-256:5aabafdd3bdc2cfc4a409efc00202aee4d8b1bcb1efaf5021c02ac2e90473603", + "size": "341111216" }, { "host": "arm64-apple-darwin", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "checksum": "SHA-256:f552d02ecef616389f1d0c973cb270718a192e6258db426656cd5965db3c6ed0", - "size": "339750940" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "checksum": "SHA-256:5aabafdd3bdc2cfc4a409efc00202aee4d8b1bcb1efaf5021c02ac2e90473603", + "size": "341111216" }, { "host": "x86_64-apple-darwin", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "checksum": "SHA-256:f552d02ecef616389f1d0c973cb270718a192e6258db426656cd5965db3c6ed0", - "size": "339750940" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "checksum": "SHA-256:5aabafdd3bdc2cfc4a409efc00202aee4d8b1bcb1efaf5021c02ac2e90473603", + "size": "341111216" }, { "host": "x86_64-pc-linux-gnu", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "checksum": "SHA-256:f552d02ecef616389f1d0c973cb270718a192e6258db426656cd5965db3c6ed0", - "size": "339750940" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "checksum": "SHA-256:5aabafdd3bdc2cfc4a409efc00202aee4d8b1bcb1efaf5021c02ac2e90473603", + "size": "341111216" }, { "host": "i686-pc-linux-gnu", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "checksum": "SHA-256:f552d02ecef616389f1d0c973cb270718a192e6258db426656cd5965db3c6ed0", - "size": "339750940" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "checksum": "SHA-256:5aabafdd3bdc2cfc4a409efc00202aee4d8b1bcb1efaf5021c02ac2e90473603", + "size": "341111216" }, { "host": "aarch64-linux-gnu", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "checksum": "SHA-256:f552d02ecef616389f1d0c973cb270718a192e6258db426656cd5965db3c6ed0", - "size": "339750940" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "checksum": "SHA-256:5aabafdd3bdc2cfc4a409efc00202aee4d8b1bcb1efaf5021c02ac2e90473603", + "size": "341111216" }, { "host": "arm-linux-gnueabihf", - "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-a0f798cf.zip", - "checksum": "SHA-256:f552d02ecef616389f1d0c973cb270718a192e6258db426656cd5965db3c6ed0", - "size": "339750940" + "url": "https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.3/esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "archiveFileName": "esp32-arduino-libs-idf-release_v5.3-083aad99-v1.zip", + "checksum": "SHA-256:5aabafdd3bdc2cfc4a409efc00202aee4d8b1bcb1efaf5021c02ac2e90473603", + "size": "341111216" } ] }, diff --git a/platform.txt b/platform.txt index b075e5398..44353ab3b 100644 --- a/platform.txt +++ b/platform.txt @@ -44,7 +44,7 @@ compiler.warning_flags.more=-Wall compiler.warning_flags.all=-Wall -Wextra # Additional flags specific to Arduino (not based on IDF flags). -# Update tools/platformio-build.py when changing these flags. +# Update tools/pioarduino-build.py when changing these flags. compiler.common_werror_flags=-Werror=return-type # Compile Flags diff --git a/tests/validation/uart/ci.json b/tests/validation/uart/ci.json index dc24acbae..54da33b61 100644 --- a/tests/validation/uart/ci.json +++ b/tests/validation/uart/ci.json @@ -1,8 +1,5 @@ { "platforms": { "qemu": false - }, - "targets": { - "esp32p4": false } } diff --git a/tools/platformio-build.py b/tools/pioarduino-build.py similarity index 98% rename from tools/platformio-build.py rename to tools/pioarduino-build.py index 485879944..3335a7168 100644 --- a/tools/platformio-build.py +++ b/tools/pioarduino-build.py @@ -22,7 +22,7 @@ kinds of creative coding, interactive objects, spaces or physical experiences. http://arduino.cc/en/Reference/HomePage """ -# Extends: https://github.com/platformio/platform-espressif32/blob/develop/builder/main.py +# Extends: https://github.com/pioarduino/platform-espressif32/blob/develop/builder/main.py from os.path import abspath, basename, isdir, isfile, join from copy import deepcopy @@ -160,7 +160,7 @@ SConscript( join( FRAMEWORK_LIBS_DIR, build_mcu, - "platformio-build.py", + "pioarduino-build.py", ) )