Skip to content

Commit 7937b86

Browse files
authored
Merge pull request #39 from pioarduino/develop
Changes from develop
2 parents 33907b2 + 103b373 commit 7937b86

File tree

7 files changed

+54
-52
lines changed

7 files changed

+54
-52
lines changed

.github/workflows/examples.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
- "examples/arduino-rmt-blink"
1919
- "examples/arduino-usb-keyboard"
2020
- "examples/arduino-wifiscan"
21-
#- "examples/arduino-zigbee-light"
22-
#- "examples/arduino-zigbee-switch"
21+
- "examples/arduino-zigbee-light"
22+
- "examples/arduino-zigbee-switch"
2323
- "examples/espidf-arduino-h2zero-BLE_scan"
2424
#- "examples/espidf-arduino-matter-light" # Windows compile fails -> Path length limit
2525
- "examples/espidf-arduino-blink"

examples/arduino-zigbee-light/platformio.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
[env:esp32-h2-devkitm-1]
12-
platform = https://github.com/pioarduino/platform-espressif32.git#develop
12+
platform = espressif32
1313
framework = arduino
1414
board = esp32-h2-devkitm-1
1515
monitor_speed = 115200

examples/arduino-zigbee-light/src/Zigbee_On_Off_Light.ino

+20-22
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
2323
*
2424
* Please check the README.md for instructions and more detailed description.
25-
*
25+
*
2626
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
2727
*/
2828

@@ -33,57 +33,55 @@
3333
#include "ZigbeeCore.h"
3434
#include "ep/ZigbeeLight.h"
3535

36-
#define LED_PIN RGB_BUILTIN
37-
#define BUTTON_PIN 9 // C6/H2 Boot button
38-
#define ZIGBEE_LIGHT_ENDPOINT 10 /* esp light bulb device endpoint, used to process light controlling commands */
39-
40-
class MyZigbeeLight : public ZigbeeLight {
41-
public:
42-
// Constructor that passes parameters to the base class constructor
43-
MyZigbeeLight(uint8_t endpoint) : ZigbeeLight(endpoint) {}
36+
#define LED_PIN RGB_BUILTIN
37+
#define BUTTON_PIN 9 // ESP32-C6/H2 Boot button
38+
#define ZIGBEE_LIGHT_ENDPOINT 10
4439

45-
// Override the set_on_off function
46-
void setOnOff(bool value) override {
47-
rgbLedWrite(LED_PIN, 255 * value, 255 * value, 255 * value); // Toggle light
48-
}
49-
};
40+
ZigbeeLight zbLight = ZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
5041

51-
MyZigbeeLight zbLight = MyZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
42+
/********************* RGB LED functions **************************/
43+
void setLED(bool value) {
44+
digitalWrite(LED_PIN, value);
45+
}
5246

5347
/********************* Arduino functions **************************/
5448
void setup() {
55-
// Init RMT and leave light OFF
56-
rgbLedWrite(LED_PIN, 0, 0, 0);
49+
// Init LED and turn it OFF (if LED_PIN == RGB_BUILTIN, the rgbLedWrite() will be used under the hood)
50+
pinMode(LED_PIN, OUTPUT);
51+
digitalWrite(LED_PIN, LOW);
5752

5853
// Init button for factory reset
5954
pinMode(BUTTON_PIN, INPUT);
6055

6156
//Optional: set Zigbee device name and model
6257
zbLight.setManufacturerAndModel("Espressif", "ZBLightBulb");
6358

59+
// Set callback function for light change
60+
zbLight.onLightChange(setLED);
61+
6462
//Add endpoint to Zigbee Core
6563
log_d("Adding ZigbeeLight endpoint to Zigbee Core");
6664
Zigbee.addEndpoint(&zbLight);
67-
65+
6866
// When all EPs are registered, start Zigbee. By default acts as ZIGBEE_END_DEVICE
6967
log_d("Calling Zigbee.begin()");
7068
Zigbee.begin();
7169
}
7270

7371
void loop() {
74-
// Cheking button for factory reset
72+
// Checking button for factory reset
7573
if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed
7674
// Key debounce handling
7775
delay(100);
7876
int startTime = millis();
7977
while (digitalRead(BUTTON_PIN) == LOW) {
8078
delay(50);
81-
if((millis() - startTime) > 3000) {
79+
if ((millis() - startTime) > 3000) {
8280
// If key pressed for more than 3secs, factory reset Zigbee and reboot
83-
Serial.printf("Reseting Zigbee to factory settings, reboot.\n");
81+
Serial.printf("Resetting Zigbee to factory settings, reboot.\n");
8482
Zigbee.factoryReset();
8583
}
8684
}
8785
}
8886
delay(100);
89-
}
87+
}

examples/arduino-zigbee-switch/platformio.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
[env:esp32-c6-devkitc-1]
12-
platform = https://github.com/pioarduino/platform-espressif32.git#develop
12+
platform = espressif32
1313
framework = arduino
1414
board = esp32-c6-devkitc-1
1515
monitor_speed = 115200

examples/arduino-zigbee-switch/src/Zigbee_On_Off_Switch.ino

+22-25
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
2424
*
2525
* Please check the README.md for instructions and more detailed description.
26-
*
26+
*
2727
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
2828
*/
2929

@@ -65,24 +65,7 @@ typedef enum {
6565

6666
static SwitchData buttonFunctionPair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ONOFF_TOGGLE_CONTROL}};
6767

68-
/* Zigbee switch */
69-
class MyZigbeeSwitch : public ZigbeeSwitch {
70-
public:
71-
// Constructor that passes parameters to the base class constructor
72-
MyZigbeeSwitch(uint8_t endpoint) : ZigbeeSwitch(endpoint) {}
73-
74-
// Override the set_on_off function
75-
void readManufacturer(char* manufacturer) override {
76-
//Do what you want with the manufacturer string
77-
Serial.printf("Manufacturer: %s\n", manufacturer);
78-
}
79-
void readModel(char* model) override {
80-
//Do what you want with the model string
81-
Serial.printf("Model: %s\n", model);
82-
}
83-
};
84-
85-
MyZigbeeSwitch zbSwitch = MyZigbeeSwitch(SWITCH_ENDPOINT_NUMBER);
68+
ZigbeeSwitch zbSwitch = ZigbeeSwitch(SWITCH_ENDPOINT_NUMBER);
8669

8770
/********************* Zigbee functions **************************/
8871
static void onZbButton(SwitchData *button_func_pair) {
@@ -111,8 +94,11 @@ static void enableGpioInterrupt(bool enabled) {
11194

11295
/********************* Arduino functions **************************/
11396
void setup() {
114-
97+
11598
Serial.begin(115200);
99+
while (!Serial) {
100+
delay(10);
101+
}
116102

117103
//Optional: set Zigbee device name and model
118104
zbSwitch.setManufacturerAndModel("Espressif", "ZigbeeSwitch");
@@ -126,7 +112,6 @@ void setup() {
126112

127113
//Open network for 180 seconds after boot
128114
Zigbee.setRebootOpenNetwork(180);
129-
130115

131116
// Init button switch
132117
for (int i = 0; i < PAIR_SIZE(buttonFunctionPair); i++) {
@@ -143,14 +128,27 @@ void setup() {
143128
// When all EPs are registered, start Zigbee with ZIGBEE_COORDINATOR mode
144129
log_d("Calling Zigbee.begin()");
145130
Zigbee.begin(ZIGBEE_COORDINATOR);
146-
131+
147132
Serial.println("Waiting for Light to bound to the switch");
148133
//Wait for switch to bound to a light:
149-
while(!zbSwitch.isBound())
150-
{
134+
while (!zbSwitch.isBound()) {
151135
Serial.printf(".");
152136
delay(500);
153137
}
138+
139+
// Optional: read manufacturer and model name from the bound light
140+
std::list<zb_device_params_t *> boundLights = zbSwitch.getBoundDevices();
141+
//List all bound lights
142+
for (const auto &device : boundLights) {
143+
Serial.printf("Device on endpoint %d, short address: 0x%x\n", device->endpoint, device->short_addr);
144+
Serial.printf(
145+
"IEEE Address: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", device->ieee_addr[0], device->ieee_addr[1], device->ieee_addr[2], device->ieee_addr[3],
146+
device->ieee_addr[4], device->ieee_addr[5], device->ieee_addr[6], device->ieee_addr[7]
147+
);
148+
Serial.printf("Light manufacturer: %s", zbSwitch.readManufacturer(device->endpoint, device->short_addr));
149+
Serial.printf("Light model: %s", zbSwitch.readModel(device->endpoint, device->short_addr));
150+
}
151+
154152
Serial.println();
155153
}
156154

@@ -160,7 +158,6 @@ void loop() {
160158
SwitchData buttonSwitch;
161159
static SwitchState buttonState = SWITCH_IDLE;
162160
bool eventFlag = false;
163-
164161

165162
/* check if there is any queue received, if yes read out the buttonSwitch */
166163
if (xQueueReceive(gpio_evt_queue, &buttonSwitch, portMAX_DELAY)) {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
dependencies:
22
espressif/esp_matter:
3-
version: "^1.3.0"
3+
version: "^1.3.0"
4+
espressif/cmake_utilities:
5+
version: "0.*"
6+
rules:
7+
- if: "target in [esp32c2]"

platform.py

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def configure_default_packages(self, variables, targets):
3939
mcu = variables.get("board_build.mcu", board_config.get("build.mcu", "esp32"))
4040
frameworks = variables.get("pioframework", [])
4141

42+
if variables.get("custom_sdkconfig") is not None:
43+
frameworks.append("espidf")
44+
4245
if "arduino" in frameworks:
4346
self.packages["framework-arduinoespressif32"]["optional"] = False
4447
self.packages["framework-arduinoespressif32-libs"]["optional"] = False

0 commit comments

Comments
 (0)