Skip to content

Commit bec4ac0

Browse files
authored
Update Zigbee_On_Off_Switch.ino
1 parent 09badeb commit bec4ac0

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

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

Lines changed: 22 additions & 25 deletions
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)) {

0 commit comments

Comments
 (0)