Skip to content

Commit f1412d6

Browse files
authored
Merge branch 'master' into fix/uart_ci_test
2 parents 28564ea + 2a3de9c commit f1412d6

File tree

15 files changed

+379
-27
lines changed

15 files changed

+379
-27
lines changed

.github/scripts/sketch_utils.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
244244
build_dir="$ARDUINO_BUILD_DIR"
245245
elif [ "$len" -eq 1 ]; then
246246
# build_dir="$sketchdir/build"
247-
build_dir="$HOME/.arduino/tests/$sketchname/build.tmp"
247+
build_dir="$HOME/.arduino/tests/$target/$sketchname/build.tmp"
248248
fi
249249

250250
output_file="$HOME/.arduino/cli_compile_output.txt"
@@ -254,7 +254,7 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
254254
for i in $(seq 0 $((len - 1))); do
255255
if [ "$len" -ne 1 ]; then
256256
# build_dir="$sketchdir/build$i"
257-
build_dir="$HOME/.arduino/tests/$sketchname/build$i.tmp"
257+
build_dir="$HOME/.arduino/tests/$target/$sketchname/build$i.tmp"
258258
fi
259259
rm -rf "$build_dir"
260260
mkdir -p "$build_dir"

.github/scripts/tests_run.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ function run_test {
2727
fi
2828

2929
if [ "$len" -eq 1 ]; then
30-
sdkconfig_path="$HOME/.arduino/tests/$sketchname/build.tmp/sdkconfig"
30+
sdkconfig_path="$HOME/.arduino/tests/$target/$sketchname/build.tmp/sdkconfig"
3131
else
32-
sdkconfig_path="$HOME/.arduino/tests/$sketchname/build0.tmp/sdkconfig"
32+
sdkconfig_path="$HOME/.arduino/tests/$target/$sketchname/build0.tmp/sdkconfig"
3333
fi
3434

3535
if [ -f "$sketchdir"/ci.json ]; then
@@ -45,7 +45,7 @@ function run_test {
4545
fi
4646

4747
if [ ! -f "$sdkconfig_path" ]; then
48-
printf "\033[93mSketch %s not built\nMight be due to missing target requirements or build failure\033[0m\n" "$sketchname"
48+
printf "\033[93mSketch %s build not found in %s\nMight be due to missing target requirements or build failure\033[0m\n" "$(dirname "$sdkconfig_path")" "$sketchname"
4949
printf "\n\n\n"
5050
return 0
5151
fi
@@ -60,7 +60,7 @@ function run_test {
6060

6161
if [ "$len" -eq 1 ]; then
6262
# build_dir="$sketchdir/build"
63-
build_dir="$HOME/.arduino/tests/$sketchname/build.tmp"
63+
build_dir="$HOME/.arduino/tests/$target/$sketchname/build.tmp"
6464
report_file="$sketchdir/$target/$sketchname.xml"
6565
fi
6666

@@ -83,7 +83,7 @@ function run_test {
8383

8484
if [ "$len" -ne 1 ]; then
8585
# build_dir="$sketchdir/build$i"
86-
build_dir="$HOME/.arduino/tests/$sketchname/build$i.tmp"
86+
build_dir="$HOME/.arduino/tests/$target/$sketchname/build$i.tmp"
8787
report_file="$sketchdir/$target/$sketchname$i.xml"
8888
fi
8989

.github/workflows/tests_build.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ jobs:
2626
with:
2727
key: tests-${{ env.id }}-bin
2828
path: |
29-
~/.arduino/tests/**/build*.tmp/*.bin
30-
~/.arduino/tests/**/build*.tmp/*.elf
31-
~/.arduino/tests/**/build*.tmp/*.json
32-
~/.arduino/tests/**/build*.tmp/sdkconfig
29+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/*.bin
30+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/*.elf
31+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/*.json
32+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/sdkconfig
3333
3434
- name: Evaluate if tests should be built
3535
id: check-build
@@ -73,18 +73,18 @@ jobs:
7373
with:
7474
key: tests-${{ env.id }}-bin
7575
path: |
76-
~/.arduino/tests/**/build*.tmp/*.bin
77-
~/.arduino/tests/**/build*.tmp/*.elf
78-
~/.arduino/tests/**/build*.tmp/*.json
79-
~/.arduino/tests/**/build*.tmp/sdkconfig
76+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/*.bin
77+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/*.elf
78+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/*.json
79+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/sdkconfig
8080
8181
- name: Upload ${{ inputs.chip }} ${{ inputs.type }} binaries as artifacts
8282
uses: actions/upload-artifact@v4
8383
with:
8484
name: tests-bin-${{ inputs.chip }}-${{ inputs.type }}
8585
overwrite: true
8686
path: |
87-
~/.arduino/tests/**/build*.tmp/*.bin
88-
~/.arduino/tests/**/build*.tmp/*.elf
89-
~/.arduino/tests/**/build*.tmp/*.json
90-
~/.arduino/tests/**/build*.tmp/sdkconfig
87+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/*.bin
88+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/*.elf
89+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/*.json
90+
~/.arduino/tests/${{ inputs.chip }}/**/build*.tmp/sdkconfig

.github/workflows/tests_hw.yml

+13-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ defaults:
2222
jobs:
2323
hardware-test:
2424
name: Hardware ${{ inputs.chip }} ${{ inputs.type }} tests
25-
runs-on: [arduino, "${{ inputs.chip }}"]
25+
runs-on: ["arduino", "${{ inputs.chip }}"]
2626
env:
2727
id: ${{ github.event.pull_request.number || github.ref }}-${{ github.event.pull_request.head.sha || github.sha }}-${{ inputs.chip }}-${{ inputs.type }}
2828
container:
2929
image: python:3.10.1-bullseye
30-
options: --privileged
30+
options: --privileged --device-cgroup-rule="c 188:* rmw" --device-cgroup-rule="c 166:* rmw"
3131
steps:
32+
- name: Clean workspace
33+
run: |
34+
rm -rf ./*
35+
rm -rf ~/.arduino/tests
36+
3237
- name: Check if already passed
3338
id: cache-results
3439
if: github.event.pull_request.number != null
@@ -81,7 +86,12 @@ jobs:
8186
with:
8287
name: tests-bin-${{ inputs.chip }}-${{ inputs.type }}
8388
path: |
84-
~/.arduino/tests
89+
~/.arduino/tests/${{ inputs.chip }}
90+
91+
- name: List binaries
92+
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
93+
run: |
94+
ls -laR ~/.arduino/tests
8595
8696
- name: Run Tests
8797
if: ${{ steps.check-tests.outputs.enabled == 'true' }}

.github/workflows/tests_qemu.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
with:
118118
name: tests-bin-${{ inputs.chip }}-${{ inputs.type }}
119119
path: |
120-
~/.arduino/tests
120+
~/.arduino/tests/${{ inputs.chip }}
121121
122122
- name: Run Tests
123123
if: ${{ steps.check-tests.outputs.enabled == 'true' }}

.github/workflows/tests_wokwi.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ jobs:
276276
run-id: ${{ github.event.workflow_run.id }}
277277
name: tests-bin-${{ matrix.chip }}-${{ matrix.type }}
278278
path: |
279-
~/.arduino/tests
279+
~/.arduino/tests/${{ matrix.chip }}
280280
281281
- name: Run Tests
282282
if: ${{ steps.check-tests.outputs.enabled == 'true' }}

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS
298298
libraries/Zigbee/src/ep/ZigbeeAnalog.cpp
299299
libraries/Zigbee/src/ep/ZigbeeRangeExtender.cpp
300300
libraries/Zigbee/src/ep/ZigbeeGateway.cpp
301+
libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp
301302
)
302303

303304
set(ARDUINO_LIBRARY_BLE_SRCS

docs/en/contributing.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ ESP32-C3 target, you would run:
318318
319319
./.github/scripts/tests_build.sh -s uart -t esp32c3
320320
321-
You should see the output of the build process and the test binary should be generated in the ``~/.arduino/tests/<test_name>/build.tmp`` folder.
321+
You should see the output of the build process and the test binary should be generated in the ``~/.arduino/tests/<target_chip>/<test_name>/build.tmp`` folder.
322322

323323
Now that the test is built, you can run it in the target board. Connect the target board to your computer and run:
324324

@@ -339,7 +339,7 @@ The test will run on the target board and you should see the output of the test
339339
lucassvaz@Lucas--MacBook-Pro esp32 % ./.github/scripts/tests_run.sh -s uart -t esp32c3
340340
Sketch uart test type: validation
341341
Running test: uart -- Config: Default
342-
pytest tests --build-dir /Users/lucassvaz/.arduino/tests/uart/build.tmp -k test_uart --junit-xml=/Users/lucassvaz/Espressif/Arduino/hardware/espressif/esp32/tests/validation/uart/esp32c3/uart.xml --embedded-services esp,arduino
342+
pytest tests --build-dir /Users/lucassvaz/.arduino/tests/esp32c3/uart/build.tmp -k test_uart --junit-xml=/Users/lucassvaz/Espressif/Arduino/hardware/espressif/esp32/tests/validation/uart/esp32c3/uart.xml --embedded-services esp,arduino
343343
=============================================================================================== test session starts ================================================================================================
344344
platform darwin -- Python 3.12.3, pytest-8.2.2, pluggy-1.5.0
345345
rootdir: /Users/lucassvaz/Espressif/Arduino/hardware/espressif/esp32/tests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Zigbee Wind Speed Sensor Integration with HomeAssistant ZHA
2+
3+
This guide provides a workaround for integrating a Zigbee Wind Speed Sensor with HomeAssistant using the ZHA integration. Since the wind speed cluster is not natively supported, we will use the ZHA Toolkit from HACS to read the wind speed attribute and store it in a helper variable.
4+
## Alternative Option: Creating a Custom Quirk
5+
6+
For advanced users, a more robust solution is to create a custom quirk for your Zigbee Wind Speed Sensor. This approach involves writing a custom device handler that directly supports the wind speed cluster, providing a more seamless integration with HomeAssistant.
7+
8+
Creating a custom quirk can be complex and requires familiarity with Python and the Zigbee protocol. However, it offers greater flexibility and control over your device's behavior.
9+
10+
For more information and guidance on creating custom quirks, visit the [ZHA Device Handlers repository](https://github.com/zigpy/zha-device-handlers/).
11+
12+
## Prerequisites
13+
14+
- HomeAssistant installed and running
15+
- Zigbee Wind Speed Sensor paired with HomeAssistant ZHA
16+
- HACS (Home Assistant Community Store) installed. For more information, visit [HACS](https://hacs.xyz)
17+
18+
## Steps
19+
20+
### 1. Install ZHA Toolkit
21+
22+
1. Open HomeAssistant.
23+
2. Navigate to HACS > Integrations.
24+
3. Search for "ZHA Toolkit - Service for advanced Zigbee Usage" and install it. For more information, visit the [ZHA Toolkit repository](https://github.com/mdeweerd/zha-toolkit).
25+
4. Restart HomeAssistant to apply changes.
26+
27+
### 2. Create a Helper Variable
28+
29+
1. Go to Configuration -> Devices & Services -> Helpers.
30+
2. Click on "Add Helper" and select "Number".
31+
3. Name the helper (e.g., `wind_speed`), set the minimum and maximum values, and save it.
32+
33+
### 3. Create an Automation
34+
35+
1. Go to Configuration > Automations & Scenes.
36+
2. Click on "Add Automation" and choose "Start with an empty automation".
37+
3. Set a name for the automation (e.g., `Read Wind Speed`).
38+
4. Add a trigger:
39+
- Trigger Type: Time Pattern
40+
- Every: 30 seconds
41+
5. Add an action (Then do):
42+
- Action Type: ZHA Toolkit: Read Attribute
43+
- Setup the action:
44+
```yaml
45+
action: zha_toolkit.attr_read
46+
metadata: {}
47+
data:
48+
ieee: f0:f5:bd:ff:fe:0e:61:30 #set device IEEE address
49+
endpoint: 10 #set windspeed device endpoint
50+
cluster: 1035 #use this windspeed cluster
51+
attribute: 0 #read measurement value
52+
state_id: input_number.wind_speed #save to created helper variable
53+
state_value_template: value/100 #use correct value format (convert u16 to float)
54+
```
55+
6. Save the automation.
56+
57+
## Conclusion
58+
59+
By following these steps, you can successfully integrate your Zigbee Wind Speed Sensor with HomeAssistant using the ZHA integration and ZHA Toolkit. The wind speed readings will be updated every 30 seconds and stored in the helper variable for use in your HomeAssistant setup.
60+
The helper variable `wind_speed` is now an entity in HomeAssistant. You can use this entity to display the wind speed on your dashboard or in other automations.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @brief This example demonstrates Zigbee windspeed sensor.
17+
*
18+
* The example demonstrates how to use Zigbee library to create a end device wind speed sensor.
19+
* The wind speed sensor is a Zigbee end device, which is controlled by a Zigbee coordinator.
20+
*
21+
* Proper Zigbee mode must be selected in Tools->Zigbee mode
22+
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
23+
*
24+
* Please check the README.md for instructions and more detailed description.
25+
*
26+
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
27+
*/
28+
29+
#ifndef ZIGBEE_MODE_ED
30+
#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode"
31+
#endif
32+
33+
#include "Zigbee.h"
34+
35+
#define BUTTON_PIN 9 //Boot button for C6/H2
36+
#define WIND_SPEED_SENSOR_ENDPOINT_NUMBER 10
37+
38+
ZigbeeWindSpeedSensor zbWindSpeedSensor = ZigbeeWindSpeedSensor(WIND_SPEED_SENSOR_ENDPOINT_NUMBER);
39+
40+
/************************ WindSpeed sensor *****************************/
41+
static void windspeed_sensor_value_update(void *arg) {
42+
for (;;) {
43+
// Read wind speed sensor value (simulated now by temperature sensor)
44+
float windspeed = temperatureRead();
45+
log_v("Wind speed sensor value: %.2fm/s", windspeed);
46+
// Update windspeed value in Windspeed sensor EP
47+
zbWindSpeedSensor.setWindSpeed(windspeed);
48+
delay(1000);
49+
}
50+
}
51+
52+
/********************* Arduino functions **************************/
53+
void setup() {
54+
Serial.begin(115200);
55+
while (!Serial) {
56+
delay(10);
57+
}
58+
59+
// Init button switch
60+
pinMode(BUTTON_PIN, INPUT);
61+
62+
// Optional: set Zigbee device name and model
63+
zbWindSpeedSensor.setManufacturerAndModel("Espressif", "ZigbeeWindSpeedSensor");
64+
65+
// Set minimum and maximum windspeed measurement value in m/s
66+
zbWindSpeedSensor.setMinMaxValue(0, 50);
67+
68+
// Set tolerance for windspeed measurement in m/s (lowest possible value is 0.01 m/s)
69+
zbWindSpeedSensor.setTolerance(1);
70+
71+
// Add endpoint to Zigbee Core
72+
Zigbee.addEndpoint(&zbWindSpeedSensor);
73+
74+
Serial.println("Starting Zigbee...");
75+
// When all EPs are registered, start Zigbee in End Device mode
76+
if (!Zigbee.begin()) {
77+
Serial.println("Zigbee failed to start!");
78+
Serial.println("Rebooting...");
79+
ESP.restart();
80+
} else {
81+
Serial.println("Zigbee started successfully!");
82+
}
83+
Serial.println("Connecting to network");
84+
while (!Zigbee.connected()) {
85+
Serial.print(".");
86+
delay(100);
87+
}
88+
Serial.println();
89+
90+
// Start Wind speed sensor reading task
91+
xTaskCreate(windspeed_sensor_value_update, "wind_speed_sensor_update", 2048, NULL, 10, NULL);
92+
93+
// Set reporting interval for windspeed measurement in seconds, must be called after Zigbee.begin()
94+
// min_interval and max_interval in seconds, delta (WindSpeed change in m/s)
95+
// if min = 1 and max = 0, reporting is sent only when windspeed changes by delta
96+
// if min = 0 and max = 10, reporting is sent every 10 seconds or windspeed changes by delta
97+
// if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of windspeed change
98+
zbWindSpeedSensor.setReporting(1, 0, 1);
99+
}
100+
101+
void loop() {
102+
// Checking button for factory reset
103+
if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed
104+
// Key debounce handling
105+
delay(100);
106+
int startTime = millis();
107+
while (digitalRead(BUTTON_PIN) == LOW) {
108+
delay(50);
109+
if ((millis() - startTime) > 3000) {
110+
// If key pressed for more than 3secs, factory reset Zigbee and reboot
111+
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
112+
delay(1000);
113+
Zigbee.factoryReset();
114+
}
115+
}
116+
zbWindSpeedSensor.reportWindSpeed();
117+
}
118+
delay(100);
119+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"fqbn_append": "PartitionScheme=zigbee,ZigbeeMode=ed",
3+
"requires": [
4+
"CONFIG_SOC_IEEE802154_SUPPORTED=y",
5+
"CONFIG_ZB_ENABLED=y"
6+
]
7+
}

libraries/Zigbee/src/Zigbee.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
#include "ep/ZigbeeVibrationSensor.h"
2626
#include "ep/ZigbeeRangeExtender.h"
2727
#include "ep/ZigbeeGateway.h"
28+
#include "ep/ZigbeeWindSpeedSensor.h"

0 commit comments

Comments
 (0)