28
28
MatterHumiditySensor SimulatedHumiditySensor;
29
29
30
30
// set your board USER BUTTON pin here - decommissioning button
31
- #ifdef BOOT_PIN
32
31
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
33
- #else
34
- const uint8_t buttonPin = 0 ; // Set your button pin here.
35
- #warning "Do not forget to set the USER BUTTON pin"
36
- #endif
37
32
38
33
// WiFi is manually set and started
39
34
const char *ssid = " your-ssid" ; // Change this to your WiFi SSID
40
35
const char *password = " your-password" ; // Change this to your WiFi password
41
36
37
+ // Button control - decommision the Matter Node
38
+ uint32_t button_time_stamp = 0 ; // debouncing control
39
+ bool button_state = false ; // false = released | true = pressed
40
+ const uint32_t decommissioningTimeout = 5000 ; // keep the button pressed for 5s, or longer, to decommission
41
+
42
42
// Simulate a humidity sensor - add your preferred humidity sensor library code here
43
43
float getSimulatedHumidity () {
44
44
// The Endpoint implementation keeps an uint16_t as internal value information,
@@ -96,13 +96,17 @@ void setup() {
96
96
}
97
97
}
98
98
99
- // Button control - decommision the Matter Node
100
- uint32_t button_time_stamp = 0 ; // debouncing control
101
- bool button_state = false ; // false = released | true = pressed
102
- const uint32_t decommissioningTimeout = 10000 ; // keep the button pressed for 10s to decommission
103
-
104
99
void loop () {
105
- Serial.printf (" Current Humidity is %.02f%%\r\n " , SimulatedHumiditySensor.getHumidityPercent ());
100
+ static uint32_t timeCounter = 0 ;
101
+
102
+ // Print the current humidity value every 5s
103
+ if (!(timeCounter++ % 10 )) { // delaying for 500ms x 10 = 5s
104
+ // Print the current humidity value
105
+ Serial.printf (" Current Humidity is %.02f%%\r\n " , SimulatedHumiditySensor.getHumidity ());
106
+ // Update Humidity from the (Simulated) Hardware Sensor
107
+ // Matter APP shall display the updated humidity percent
108
+ SimulatedHumiditySensor.setHumidity (getSimulatedHumidity ());
109
+ }
106
110
107
111
// Check if the button has been pressed
108
112
if (digitalRead (buttonPin) == LOW && !button_state) {
@@ -111,19 +115,17 @@ void loop() {
111
115
button_state = true ; // pressed.
112
116
}
113
117
114
- // Onboard User Button is used to decommission matter node
115
- uint32_t time_diff = millis () - button_time_stamp;
116
- if (button_state && time_diff > decommissioningTimeout && digitalRead (buttonPin) == HIGH) {
118
+ if (digitalRead (buttonPin) == HIGH && button_state) {
117
119
button_state = false ; // released
120
+ }
121
+
122
+ // Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
123
+ uint32_t time_diff = millis () - button_time_stamp;
124
+ if (button_state && time_diff > decommissioningTimeout) {
118
125
// Factory reset is triggered if the button is pressed longer than 10 seconds
119
- if (time_diff > decommissioningTimeout) {
120
- Serial.println (" Decommissioning the Light Matter Accessory. It shall be commissioned again." );
121
- Matter.decommission ();
122
- }
126
+ Serial.println (" Decommissioning the Light Matter Accessory. It shall be commissioned again." );
127
+ Matter.decommission ();
123
128
}
124
129
125
- // update the humidity sensor value every 5 seconds
126
- delay (5000 );
127
- // Matter APP shall display the updated humidity percent
128
- SimulatedHumiditySensor.setHumidityPercent (getSimulatedHumidity ());
130
+ delay (500 );
129
131
}
0 commit comments