@@ -27,12 +27,12 @@ const char *ssid = "your-ssid"; // Change this to your WiFi SSID
27
27
const char *password = " your-password" ; // Change this to your WiFi password
28
28
29
29
// set your board USER BUTTON pin here - USED to decommission the Matter Node
30
- #ifdef BOOT_PIN
31
30
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
32
- #else
33
- const uint8_t buttonPin = 0 ; // Set your button pin here.
34
- #warning "Do not forget to set the USER BUTTON pin"
35
- #endif
31
+
32
+ // Button control
33
+ uint32_t button_time_stamp = 0 ; // debouncing control
34
+ bool button_state = false ; // false = released | true = pressed
35
+ const uint32_t decommissioningTimeout = 5000 ; // keep the button pressed for 5s, or longer, to decommission
36
36
37
37
// Matter Protocol Endpoint Callback for each Light Accessory
38
38
bool setLightOnOff1 (bool state) {
@@ -89,12 +89,9 @@ void setup() {
89
89
Matter.begin ();
90
90
}
91
91
92
- // Button control
93
- uint32_t button_time_stamp = 0 ; // debouncing control
94
- bool button_state = false ; // false = released | true = pressed
95
- const uint32_t decommissioningTimeout = 10000 ; // keep the button pressed for 10s to decommission the light
96
-
97
92
void loop () {
93
+ static uint32_t timeCounter = 0 ;
94
+
98
95
// Check Matter Light Commissioning state
99
96
if (!Matter.isDeviceCommissioned ()) {
100
97
Serial.println (" " );
@@ -115,10 +112,12 @@ void loop() {
115
112
}
116
113
117
114
// displays the Light state every 5 seconds
118
- Serial.println (" ======================" );
119
- Serial.printf (" Matter Light #1 is %s\r\n " , Light1.getOnOff () ? " ON" : " OFF" );
120
- Serial.printf (" Matter Light #2 is %s\r\n " , Light2.getOnOff () ? " ON" : " OFF" );
121
- Serial.printf (" Matter Light #3 is %s\r\n " , Light3.getOnOff () ? " ON" : " OFF" );
115
+ if (!(timeCounter++ % 10 )) { // delaying for 500ms x 10 = 5s
116
+ Serial.println (" ======================" );
117
+ Serial.printf (" Matter Light #1 is %s\r\n " , Light1.getOnOff () ? " ON" : " OFF" );
118
+ Serial.printf (" Matter Light #2 is %s\r\n " , Light2.getOnOff () ? " ON" : " OFF" );
119
+ Serial.printf (" Matter Light #3 is %s\r\n " , Light3.getOnOff () ? " ON" : " OFF" );
120
+ }
122
121
123
122
// Check if the button has been pressed
124
123
if (digitalRead (buttonPin) == LOW && !button_state) {
@@ -127,16 +126,17 @@ void loop() {
127
126
button_state = true ; // pressed.
128
127
}
129
128
130
- // Onboard User Button is used to decommission matter fabric
131
- uint32_t time_diff = millis () - button_time_stamp;
132
- if (button_state && time_diff > decommissioningTimeout && digitalRead (buttonPin) == HIGH) {
129
+ if (digitalRead (buttonPin) == HIGH && button_state) {
133
130
button_state = false ; // released
134
- // Factory reset is triggered if the button is pressed longer than 10 seconds
135
- if (time_diff > decommissioningTimeout) {
136
- Serial.println (" Decommissioning the Light Matter Accessory. It shall be commissioned again." );
137
- Matter.decommission ();
138
- }
139
131
}
140
132
141
- delay (5000 );
133
+ // Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
134
+ uint32_t time_diff = millis () - button_time_stamp;
135
+ if (button_state && time_diff > decommissioningTimeout) {
136
+ Serial.println (" Decommissioning the Light Matter Accessory. It shall be commissioned again." );
137
+ Matter.decommission ();
138
+ button_time_stamp = millis (); // avoid running decommissining again, reboot takes a second or so
139
+ }
140
+
141
+ delay (500 );
142
142
}
0 commit comments