23
23
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
24
24
*
25
25
* Please check the README.md for instructions and more detailed description.
26
- *
26
+ *
27
27
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
28
28
*/
29
29
@@ -65,24 +65,7 @@ typedef enum {
65
65
66
66
static SwitchData buttonFunctionPair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ONOFF_TOGGLE_CONTROL}};
67
67
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);
86
69
87
70
/* ******************** Zigbee functions **************************/
88
71
static void onZbButton (SwitchData *button_func_pair) {
@@ -111,8 +94,11 @@ static void enableGpioInterrupt(bool enabled) {
111
94
112
95
/* ******************** Arduino functions **************************/
113
96
void setup () {
114
-
97
+
115
98
Serial.begin (115200 );
99
+ while (!Serial) {
100
+ delay (10 );
101
+ }
116
102
117
103
// Optional: set Zigbee device name and model
118
104
zbSwitch.setManufacturerAndModel (" Espressif" , " ZigbeeSwitch" );
@@ -126,7 +112,6 @@ void setup() {
126
112
127
113
// Open network for 180 seconds after boot
128
114
Zigbee.setRebootOpenNetwork (180 );
129
-
130
115
131
116
// Init button switch
132
117
for (int i = 0 ; i < PAIR_SIZE (buttonFunctionPair); i++) {
@@ -143,14 +128,27 @@ void setup() {
143
128
// When all EPs are registered, start Zigbee with ZIGBEE_COORDINATOR mode
144
129
log_d (" Calling Zigbee.begin()" );
145
130
Zigbee.begin (ZIGBEE_COORDINATOR);
146
-
131
+
147
132
Serial.println (" Waiting for Light to bound to the switch" );
148
133
// Wait for switch to bound to a light:
149
- while (!zbSwitch.isBound ())
150
- {
134
+ while (!zbSwitch.isBound ()) {
151
135
Serial.printf (" ." );
152
136
delay (500 );
153
137
}
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
+
154
152
Serial.println ();
155
153
}
156
154
@@ -160,7 +158,6 @@ void loop() {
160
158
SwitchData buttonSwitch;
161
159
static SwitchState buttonState = SWITCH_IDLE;
162
160
bool eventFlag = false ;
163
-
164
161
165
162
/* check if there is any queue received, if yes read out the buttonSwitch */
166
163
if (xQueueReceive (gpio_evt_queue, &buttonSwitch, portMAX_DELAY)) {
0 commit comments