2828MatterHumiditySensor SimulatedHumiditySensor;
2929
3030// set your board USER BUTTON pin here - decommissioning button
31- #ifdef BOOT_PIN
3231const 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
3732
3833// WiFi is manually set and started
3934const char *ssid = " your-ssid" ; // Change this to your WiFi SSID
4035const char *password = " your-password" ; // Change this to your WiFi password
4136
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+
4242// Simulate a humidity sensor - add your preferred humidity sensor library code here
4343float getSimulatedHumidity () {
4444 // The Endpoint implementation keeps an uint16_t as internal value information,
@@ -96,13 +96,17 @@ void setup() {
9696 }
9797}
9898
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-
10499void 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+ }
106110
107111 // Check if the button has been pressed
108112 if (digitalRead (buttonPin) == LOW && !button_state) {
@@ -111,19 +115,17 @@ void loop() {
111115 button_state = true ; // pressed.
112116 }
113117
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) {
117119 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) {
118125 // 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 ();
123128 }
124129
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 );
129131}
0 commit comments