feat(matter_examples): apply boot button change to all examples (#10702)
* feat(matter_examples): apply boot button change to all examples
This commit is contained in:
parent
5a8cba88c7
commit
de4824fc24
13 changed files with 260 additions and 115 deletions
|
|
@ -35,7 +35,13 @@ const uint8_t ledPin = 2; // Set your pin here if your board has not defined LE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// set your board USER BUTTON pin here
|
// set your board USER BUTTON pin here
|
||||||
const uint8_t buttonPin = 0; // Set your pin here. Using BOOT Button. C6/C3 use GPIO9.
|
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
|
||||||
|
|
||||||
|
// Button control
|
||||||
|
uint32_t button_time_stamp = 0; // debouncing control
|
||||||
|
bool button_state = false; // false = released | true = pressed
|
||||||
|
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
||||||
|
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
|
||||||
|
|
||||||
// WiFi is manually set and started
|
// WiFi is manually set and started
|
||||||
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
||||||
|
|
@ -125,11 +131,6 @@ void setup() {
|
||||||
ColorLight.updateAccessory();
|
ColorLight.updateAccessory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Button control
|
|
||||||
uint32_t button_time_stamp = 0; // debouncing control
|
|
||||||
bool button_state = false; // false = released | true = pressed
|
|
||||||
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
|
||||||
const uint32_t decommissioningTimeout = 10000; // keep the button pressed for 10s to decommission the light
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Check Matter Light Commissioning state, which may change during execution of loop()
|
// Check Matter Light Commissioning state, which may change during execution of loop()
|
||||||
|
|
@ -167,17 +168,18 @@ void loop() {
|
||||||
|
|
||||||
// Onboard User Button is used as a Light toggle switch or to decommission it
|
// Onboard User Button is used as a Light toggle switch or to decommission it
|
||||||
uint32_t time_diff = millis() - button_time_stamp;
|
uint32_t time_diff = millis() - button_time_stamp;
|
||||||
if (button_state && time_diff > debouceTime && digitalRead(buttonPin) == HIGH) {
|
if (digitalRead(buttonPin) == HIGH && button_state && time_diff > debouceTime) {
|
||||||
button_state = false; // released
|
|
||||||
// Toggle button is released - toggle the light
|
// Toggle button is released - toggle the light
|
||||||
Serial.println("User button released. Toggling Light!");
|
Serial.println("User button released. Toggling Light!");
|
||||||
ColorLight.toggle(); // Matter Controller also can see the change
|
ColorLight.toggle(); // Matter Controller also can see the change
|
||||||
|
button_state = false; // released
|
||||||
|
}
|
||||||
|
|
||||||
// Factory reset is triggered if the button is pressed longer than 10 seconds
|
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
|
||||||
if (time_diff > decommissioningTimeout) {
|
if (button_state && time_diff > decommissioningTimeout) {
|
||||||
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
||||||
ColorLight = false; // turn the light off
|
ColorLight = false; // turn the light off
|
||||||
Matter.decommission();
|
Matter.decommission();
|
||||||
}
|
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,31 +18,42 @@
|
||||||
|
|
||||||
// List of Matter Endpoints for this Node
|
// List of Matter Endpoints for this Node
|
||||||
// There will be 3 On/Off Light Endpoints in the same Node
|
// There will be 3 On/Off Light Endpoints in the same Node
|
||||||
MatterOnOffLight OnOffLight1;
|
MatterOnOffLight Light1;
|
||||||
MatterOnOffLight OnOffLight2;
|
MatterDimmableLight Light2;
|
||||||
MatterOnOffLight OnOffLight3;
|
MatterColorLight Light3;
|
||||||
|
|
||||||
// WiFi is manually set and started
|
// WiFi is manually set and started
|
||||||
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
||||||
const char *password = "your-password"; // Change this to your WiFi password
|
const char *password = "your-password"; // Change this to your WiFi password
|
||||||
|
|
||||||
|
// set your board USER BUTTON pin here - USED to decommission the Matter Node
|
||||||
|
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
|
||||||
|
|
||||||
|
// Button control
|
||||||
|
uint32_t button_time_stamp = 0; // debouncing control
|
||||||
|
bool button_state = false; // false = released | true = pressed
|
||||||
|
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
|
||||||
|
|
||||||
// Matter Protocol Endpoint Callback for each Light Accessory
|
// Matter Protocol Endpoint Callback for each Light Accessory
|
||||||
bool setLightOnOff1(bool state) {
|
bool setLightOnOff1(bool state) {
|
||||||
Serial.printf("CB-Light1 changed state to: %s\r\n", state ? "ON" : "OFF");
|
Serial.printf("Light1 changed state to: %s\r\n", state ? "ON" : "OFF");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool setLightOnOff2(bool state) {
|
bool setLightOnOff2(bool state) {
|
||||||
Serial.printf("CB-Light2 changed state to: %s\r\n", state ? "ON" : "OFF");
|
Serial.printf("Light2 changed state to: %s\r\n", state ? "ON" : "OFF");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool setLightOnOff3(bool state) {
|
bool setLightOnOff3(bool state) {
|
||||||
Serial.printf("CB-Light3 changed state to: %s\r\n", state ? "ON" : "OFF");
|
Serial.printf("Light3 changed state to: %s\r\n", state ? "ON" : "OFF");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// Initialize the USER BUTTON (Boot button) that will be used to decommission the Matter Node
|
||||||
|
pinMode(buttonPin, INPUT_PULLUP);
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial) {
|
while (!Serial) {
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
@ -60,24 +71,27 @@ void setup() {
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
}
|
}
|
||||||
Serial.println("\r\nWiFi connected");
|
Serial.println();
|
||||||
|
Serial.println("WiFi connected");
|
||||||
Serial.println("IP address: ");
|
Serial.println("IP address: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
// Initialize all 3 Matter EndPoints
|
// Initialize all 3 Matter EndPoints
|
||||||
OnOffLight1.begin();
|
Light1.begin();
|
||||||
OnOffLight2.begin();
|
Light2.begin();
|
||||||
OnOffLight3.begin();
|
Light3.begin();
|
||||||
OnOffLight1.onChange(setLightOnOff1);
|
Light1.onChangeOnOff(setLightOnOff1);
|
||||||
OnOffLight2.onChange(setLightOnOff2);
|
Light2.onChangeOnOff(setLightOnOff2);
|
||||||
OnOffLight3.onChange(setLightOnOff3);
|
Light3.onChangeOnOff(setLightOnOff3);
|
||||||
|
|
||||||
// Matter beginning - Last step, after all EndPoints are initialized
|
// Matter beginning - Last step, after all EndPoints are initialized
|
||||||
Matter.begin();
|
Matter.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
static uint32_t timeCounter = 0;
|
||||||
|
|
||||||
// Check Matter Light Commissioning state
|
// Check Matter Light Commissioning state
|
||||||
if (!Matter.isDeviceCommissioned()) {
|
if (!Matter.isDeviceCommissioned()) {
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
|
|
@ -97,10 +111,32 @@ void loop() {
|
||||||
Serial.println("Matter Node is commissioned and connected to Wi-Fi. Ready for use.");
|
Serial.println("Matter Node is commissioned and connected to Wi-Fi. Ready for use.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//displays the Light state every 3 seconds
|
//displays the Light state every 5 seconds
|
||||||
Serial.println("======================");
|
if (!(timeCounter++ % 10)) { // delaying for 500ms x 10 = 5s
|
||||||
Serial.printf("Matter Light #1 is %s\r\n", OnOffLight1.getOnOff() ? "ON" : "OFF");
|
Serial.println("======================");
|
||||||
Serial.printf("Matter Light #2 is %s\r\n", OnOffLight2.getOnOff() ? "ON" : "OFF");
|
Serial.printf("Matter Light #1 is %s\r\n", Light1.getOnOff() ? "ON" : "OFF");
|
||||||
Serial.printf("Matter Light #3 is %s\r\n", OnOffLight3.getOnOff() ? "ON" : "OFF");
|
Serial.printf("Matter Light #2 is %s\r\n", Light2.getOnOff() ? "ON" : "OFF");
|
||||||
delay(3000);
|
Serial.printf("Matter Light #3 is %s\r\n", Light3.getOnOff() ? "ON" : "OFF");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the button has been pressed
|
||||||
|
if (digitalRead(buttonPin) == LOW && !button_state) {
|
||||||
|
// deals with button debouncing
|
||||||
|
button_time_stamp = millis(); // record the time while the button is pressed.
|
||||||
|
button_state = true; // pressed.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digitalRead(buttonPin) == HIGH && button_state) {
|
||||||
|
button_state = false; // released
|
||||||
|
}
|
||||||
|
|
||||||
|
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
|
||||||
|
uint32_t time_diff = millis() - button_time_stamp;
|
||||||
|
if (button_state && time_diff > decommissioningTimeout) {
|
||||||
|
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
||||||
|
Matter.decommission();
|
||||||
|
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(500);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,13 @@ const uint8_t ledPin = 2; // Set your pin here if your board has not defined LE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// set your board USER BUTTON pin here
|
// set your board USER BUTTON pin here
|
||||||
const uint8_t buttonPin = 0; // Set your pin here. Using BOOT Button. C6/C3 use GPIO9.
|
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
|
||||||
|
|
||||||
|
// Button control
|
||||||
|
uint32_t button_time_stamp = 0; // debouncing control
|
||||||
|
bool button_state = false; // false = released | true = pressed
|
||||||
|
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
||||||
|
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
|
||||||
|
|
||||||
// WiFi is manually set and started
|
// WiFi is manually set and started
|
||||||
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
||||||
|
|
@ -117,11 +123,6 @@ void setup() {
|
||||||
DimmableLight.updateAccessory();
|
DimmableLight.updateAccessory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Button control
|
|
||||||
uint32_t button_time_stamp = 0; // debouncing control
|
|
||||||
bool button_state = false; // false = released | true = pressed
|
|
||||||
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
|
||||||
const uint32_t decommissioningTimeout = 10000; // keep the button pressed for 10s to decommission the light
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Check Matter Light Commissioning state, which may change during execution of loop()
|
// Check Matter Light Commissioning state, which may change during execution of loop()
|
||||||
|
|
@ -156,17 +157,18 @@ void loop() {
|
||||||
|
|
||||||
// Onboard User Button is used as a Light toggle switch or to decommission it
|
// Onboard User Button is used as a Light toggle switch or to decommission it
|
||||||
uint32_t time_diff = millis() - button_time_stamp;
|
uint32_t time_diff = millis() - button_time_stamp;
|
||||||
if (button_state && time_diff > debouceTime && digitalRead(buttonPin) == HIGH) {
|
if (digitalRead(buttonPin) == HIGH && button_state && time_diff > debouceTime) {
|
||||||
button_state = false; // released
|
|
||||||
// Toggle button is released - toggle the light
|
// Toggle button is released - toggle the light
|
||||||
Serial.println("User button released. Toggling Light!");
|
Serial.println("User button released. Toggling Light!");
|
||||||
DimmableLight.toggle(); // Matter Controller also can see the change
|
DimmableLight.toggle(); // Matter Controller also can see the change
|
||||||
|
button_state = false; // released
|
||||||
|
}
|
||||||
|
|
||||||
// Factory reset is triggered if the button is pressed longer than 10 seconds
|
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
|
||||||
if (time_diff > decommissioningTimeout) {
|
if (button_state && time_diff > decommissioningTimeout) {
|
||||||
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
||||||
DimmableLight = false; // turn the light off
|
DimmableLight = false; // turn the light off
|
||||||
Matter.decommission();
|
Matter.decommission();
|
||||||
}
|
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,13 @@ const uint8_t ledPin = 2; // Set your pin here if your board has not defined LE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// set your board USER BUTTON pin here
|
// set your board USER BUTTON pin here
|
||||||
const uint8_t buttonPin = 0; // Set your pin here. Using BOOT Button. C6/C3 use GPIO9.
|
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
|
||||||
|
|
||||||
|
// Button control
|
||||||
|
uint32_t button_time_stamp = 0; // debouncing control
|
||||||
|
bool button_state = false; // false = released | true = pressed
|
||||||
|
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
||||||
|
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
|
||||||
|
|
||||||
// WiFi is manually set and started
|
// WiFi is manually set and started
|
||||||
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
||||||
|
|
@ -147,11 +153,6 @@ void setup() {
|
||||||
EnhancedColorLight.updateAccessory();
|
EnhancedColorLight.updateAccessory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Button control
|
|
||||||
uint32_t button_time_stamp = 0; // debouncing control
|
|
||||||
bool button_state = false; // false = released | true = pressed
|
|
||||||
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
|
||||||
const uint32_t decommissioningTimeout = 10000; // keep the button pressed for 10s to decommission the light
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Check Matter Light Commissioning state, which may change during execution of loop()
|
// Check Matter Light Commissioning state, which may change during execution of loop()
|
||||||
|
|
@ -194,12 +195,13 @@ void loop() {
|
||||||
// Toggle button is released - toggle the light
|
// Toggle button is released - toggle the light
|
||||||
Serial.println("User button released. Toggling Light!");
|
Serial.println("User button released. Toggling Light!");
|
||||||
EnhancedColorLight.toggle(); // Matter Controller also can see the change
|
EnhancedColorLight.toggle(); // Matter Controller also can see the change
|
||||||
|
}
|
||||||
|
|
||||||
// Factory reset is triggered if the button is pressed longer than 10 seconds
|
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
|
||||||
if (time_diff > decommissioningTimeout) {
|
if (button_state && time_diff > decommissioningTimeout) {
|
||||||
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
||||||
EnhancedColorLight = false; // turn the light off
|
EnhancedColorLight = false; // turn the light off
|
||||||
Matter.decommission();
|
Matter.decommission();
|
||||||
}
|
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,14 @@
|
||||||
// Fan Endpoint - On/Off control + Speed Percent Control + Fan Modes
|
// Fan Endpoint - On/Off control + Speed Percent Control + Fan Modes
|
||||||
MatterFan Fan;
|
MatterFan Fan;
|
||||||
|
|
||||||
// set your board USER BUTTON pin here - used for toggling On/Off
|
// set your board USER BUTTON pin here - used for toggling On/Off and decommission the Matter Node
|
||||||
const uint8_t buttonPin = 0; // Set your pin here. Using BOOT Button. C6/C3 use GPIO9.
|
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
|
||||||
|
|
||||||
|
// Button control
|
||||||
|
uint32_t button_time_stamp = 0; // debouncing control
|
||||||
|
bool button_state = false; // false = released | true = pressed
|
||||||
|
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
||||||
|
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
|
||||||
|
|
||||||
// set your board Analog Pin here - used for changing the Fan speed
|
// set your board Analog Pin here - used for changing the Fan speed
|
||||||
const uint8_t analogPin = A0; // Analog Pin depends on each board
|
const uint8_t analogPin = A0; // Analog Pin depends on each board
|
||||||
|
|
@ -56,7 +62,7 @@ void fanDCMotorDrive(bool fanState, uint8_t speedPercent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Initialize the USER BUTTON (Boot button) GPIO that will toggle the Fan (On/Off)
|
// Initialize the USER BUTTON (Boot button) GPIO that will toggle the Fan (On/Off) and decommission the Matter Node
|
||||||
pinMode(buttonPin, INPUT_PULLUP);
|
pinMode(buttonPin, INPUT_PULLUP);
|
||||||
// Initialize the Analog Pin A0 used to read input voltage and to set the Fan speed accordingly
|
// Initialize the Analog Pin A0 used to read input voltage and to set the Fan speed accordingly
|
||||||
pinMode(analogPin, INPUT);
|
pinMode(analogPin, INPUT);
|
||||||
|
|
@ -140,12 +146,6 @@ void setup() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Builtin Button control
|
|
||||||
uint32_t button_time_stamp = 0; // debouncing control
|
|
||||||
bool button_state = false; // false = released | true = pressed
|
|
||||||
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
|
||||||
const uint32_t decommissioningTimeout = 10000; // keep the button pressed for 10s to decommission the Matter Fabric
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Check Matter Accessory Commissioning state, which may change during execution of loop()
|
// Check Matter Accessory Commissioning state, which may change during execution of loop()
|
||||||
if (!Matter.isDeviceCommissioned()) {
|
if (!Matter.isDeviceCommissioned()) {
|
||||||
|
|
@ -181,12 +181,13 @@ void loop() {
|
||||||
// button is released - toggle Fan On/Off
|
// button is released - toggle Fan On/Off
|
||||||
Fan.toggle();
|
Fan.toggle();
|
||||||
Serial.printf("User button released. Setting the Fan %s.\r\n", Fan > 0 ? "ON" : "OFF");
|
Serial.printf("User button released. Setting the Fan %s.\r\n", Fan > 0 ? "ON" : "OFF");
|
||||||
|
}
|
||||||
|
|
||||||
// Factory reset is triggered if the button is pressed longer than 10 seconds
|
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
|
||||||
if (time_diff > decommissioningTimeout) {
|
if (button_state && time_diff > decommissioningTimeout) {
|
||||||
Serial.println("Decommissioning the Generic Switch Matter Accessory. It shall be commissioned again.");
|
Serial.println("Decommissioning the Generic Switch Matter Accessory. It shall be commissioned again.");
|
||||||
Matter.decommission();
|
Matter.decommission();
|
||||||
}
|
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks Analog pin and adjust the speed only if it has changed
|
// checks Analog pin and adjust the speed only if it has changed
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,14 @@ const uint8_t ledPin = LED_BUILTIN;
|
||||||
const uint8_t ledPin = 2; // Set your pin here if your board has not defined LED_BUILTIN
|
const uint8_t ledPin = 2; // Set your pin here if your board has not defined LED_BUILTIN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// set your board USER BUTTON pin here - decommissioning button
|
||||||
|
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
|
||||||
|
|
||||||
|
// Button control - decommision the Matter Node
|
||||||
|
uint32_t button_time_stamp = 0; // debouncing control
|
||||||
|
bool button_state = false; // false = released | true = pressed
|
||||||
|
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
|
||||||
|
|
||||||
// Matter Protocol Endpoint (On/OFF Light) Callback
|
// Matter Protocol Endpoint (On/OFF Light) Callback
|
||||||
bool matterCB(bool state) {
|
bool matterCB(bool state) {
|
||||||
digitalWrite(ledPin, state ? HIGH : LOW);
|
digitalWrite(ledPin, state ? HIGH : LOW);
|
||||||
|
|
@ -47,6 +55,8 @@ const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
||||||
const char *password = "your-password"; // Change this to your WiFi password
|
const char *password = "your-password"; // Change this to your WiFi password
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// Initialize the USER BUTTON (Boot button) that will be used to decommission the Matter Node
|
||||||
|
pinMode(buttonPin, INPUT_PULLUP);
|
||||||
// Initialize the LED GPIO
|
// Initialize the LED GPIO
|
||||||
pinMode(ledPin, OUTPUT);
|
pinMode(ledPin, OUTPUT);
|
||||||
|
|
||||||
|
|
@ -77,5 +87,24 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
// Check if the button has been pressed
|
||||||
|
if (digitalRead(buttonPin) == LOW && !button_state) {
|
||||||
|
// deals with button debouncing
|
||||||
|
button_time_stamp = millis(); // record the time while the button is pressed.
|
||||||
|
button_state = true; // pressed.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digitalRead(buttonPin) == HIGH && button_state) {
|
||||||
|
button_state = false; // released
|
||||||
|
}
|
||||||
|
|
||||||
|
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
|
||||||
|
uint32_t time_diff = millis() - button_time_stamp;
|
||||||
|
if (button_state && time_diff > decommissioningTimeout) {
|
||||||
|
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
||||||
|
Matter.decommission();
|
||||||
|
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
|
||||||
|
}
|
||||||
|
|
||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,13 @@ const uint8_t ledPin = 2; // Set your pin here if your board has not defined LE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// set your board USER BUTTON pin here
|
// set your board USER BUTTON pin here
|
||||||
const uint8_t buttonPin = 0; // Set your pin here. Using BOOT Button. C6/C3 use GPIO9.
|
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
|
||||||
|
|
||||||
|
// Button control
|
||||||
|
uint32_t button_time_stamp = 0; // debouncing control
|
||||||
|
bool button_state = false; // false = released | true = pressed
|
||||||
|
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
||||||
|
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
|
||||||
|
|
||||||
// WiFi is manually set and started
|
// WiFi is manually set and started
|
||||||
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
||||||
|
|
@ -97,11 +103,6 @@ void setup() {
|
||||||
OnOffLight.updateAccessory(); // configure the Light based on initial state
|
OnOffLight.updateAccessory(); // configure the Light based on initial state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Button control
|
|
||||||
uint32_t button_time_stamp = 0; // debouncing control
|
|
||||||
bool button_state = false; // false = released | true = pressed
|
|
||||||
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
|
||||||
const uint32_t decommissioningTimeout = 10000; // keep the button pressed for 10s to decommission the light
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Check Matter Light Commissioning state, which may change during execution of loop()
|
// Check Matter Light Commissioning state, which may change during execution of loop()
|
||||||
|
|
@ -140,12 +141,13 @@ void loop() {
|
||||||
// Toggle button is released - toggle the light
|
// Toggle button is released - toggle the light
|
||||||
Serial.println("User button released. Toggling Light!");
|
Serial.println("User button released. Toggling Light!");
|
||||||
OnOffLight.toggle(); // Matter Controller also can see the change
|
OnOffLight.toggle(); // Matter Controller also can see the change
|
||||||
|
}
|
||||||
|
|
||||||
// Factory reset is triggered if the button is pressed longer than 10 seconds
|
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
|
||||||
if (time_diff > decommissioningTimeout) {
|
if (button_state && time_diff > decommissioningTimeout) {
|
||||||
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
||||||
OnOffLight.setOnOff(false); // turn the light off
|
OnOffLight.setOnOff(false); // turn the light off
|
||||||
Matter.decommission();
|
Matter.decommission();
|
||||||
}
|
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,20 @@
|
||||||
MatterGenericSwitch SmartButton;
|
MatterGenericSwitch SmartButton;
|
||||||
|
|
||||||
// set your board USER BUTTON pin here
|
// set your board USER BUTTON pin here
|
||||||
const uint8_t buttonPin = 0; // Set your pin here. Using BOOT Button. C6/C3 use GPIO9.
|
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
|
||||||
|
|
||||||
|
// Button control
|
||||||
|
uint32_t button_time_stamp = 0; // debouncing control
|
||||||
|
bool button_state = false; // false = released | true = pressed
|
||||||
|
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
||||||
|
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
|
||||||
|
|
||||||
// WiFi is manually set and started
|
// WiFi is manually set and started
|
||||||
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
||||||
const char *password = "your-password"; // Change this to your WiFi password
|
const char *password = "your-password"; // Change this to your WiFi password
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Initialize the USER BUTTON (Boot button) GPIO that will act as a toggle switch
|
// Initialize the USER BUTTON (Boot button) GPIO that will act as a smart button or to decommission the Matter Node
|
||||||
pinMode(buttonPin, INPUT_PULLUP);
|
pinMode(buttonPin, INPUT_PULLUP);
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
@ -63,11 +69,6 @@ void setup() {
|
||||||
Serial.println("Matter Node is commissioned and connected to Wi-Fi. Ready for use.");
|
Serial.println("Matter Node is commissioned and connected to Wi-Fi. Ready for use.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Button control
|
|
||||||
uint32_t button_time_stamp = 0; // debouncing control
|
|
||||||
bool button_state = false; // false = released | true = pressed
|
|
||||||
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
|
||||||
const uint32_t decommissioningTimeout = 10000; // keep the button pressed for 10s to decommission the Matter Fabric
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Check Matter Accessory Commissioning state, which may change during execution of loop()
|
// Check Matter Accessory Commissioning state, which may change during execution of loop()
|
||||||
|
|
@ -105,11 +106,12 @@ void loop() {
|
||||||
Serial.println("User button released. Sending Click to the Matter Controller!");
|
Serial.println("User button released. Sending Click to the Matter Controller!");
|
||||||
// Matter Controller will receive an event and, if programmed, it will trigger an action
|
// Matter Controller will receive an event and, if programmed, it will trigger an action
|
||||||
SmartButton.click();
|
SmartButton.click();
|
||||||
|
}
|
||||||
|
|
||||||
// Factory reset is triggered if the button is pressed longer than 10 seconds
|
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
|
||||||
if (time_diff > decommissioningTimeout) {
|
if (button_state && time_diff > decommissioningTimeout) {
|
||||||
Serial.println("Decommissioning the Generic Switch Matter Accessory. It shall be commissioned again.");
|
Serial.println("Decommissioning the Generic Switch Matter Accessory. It shall be commissioned again.");
|
||||||
Matter.decommission();
|
Matter.decommission();
|
||||||
}
|
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,13 @@ const uint8_t ledPin = 2; // Set your pin here if your board has not defined LE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// set your board USER BUTTON pin here
|
// set your board USER BUTTON pin here
|
||||||
const uint8_t buttonPin = 0; // Set your pin here. Using BOOT Button. C6/C3 use GPIO9.
|
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
|
||||||
|
|
||||||
|
// Button control
|
||||||
|
uint32_t button_time_stamp = 0; // debouncing control
|
||||||
|
bool button_state = false; // false = released | true = pressed
|
||||||
|
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
||||||
|
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
|
||||||
|
|
||||||
// WiFi is manually set and started
|
// WiFi is manually set and started
|
||||||
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
||||||
|
|
@ -137,11 +143,6 @@ void setup() {
|
||||||
CW_WW_Light.updateAccessory();
|
CW_WW_Light.updateAccessory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Button control
|
|
||||||
uint32_t button_time_stamp = 0; // debouncing control
|
|
||||||
bool button_state = false; // false = released | true = pressed
|
|
||||||
const uint32_t debouceTime = 250; // button debouncing time (ms)
|
|
||||||
const uint32_t decommissioningTimeout = 10000; // keep the button pressed for 10s to decommission the light
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Check Matter Light Commissioning state, which may change during execution of loop()
|
// Check Matter Light Commissioning state, which may change during execution of loop()
|
||||||
|
|
@ -184,12 +185,13 @@ void loop() {
|
||||||
// Toggle button is released - toggle the light
|
// Toggle button is released - toggle the light
|
||||||
Serial.println("User button released. Toggling Light!");
|
Serial.println("User button released. Toggling Light!");
|
||||||
CW_WW_Light.toggle(); // Matter Controller also can see the change
|
CW_WW_Light.toggle(); // Matter Controller also can see the change
|
||||||
|
}
|
||||||
|
|
||||||
// Factory reset is triggered if the button is pressed longer than 10 seconds
|
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
|
||||||
if (time_diff > decommissioningTimeout) {
|
if (button_state && time_diff > decommissioningTimeout) {
|
||||||
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
||||||
CW_WW_Light = false; // turn the light off
|
CW_WW_Light = false; // turn the light off
|
||||||
Matter.decommission();
|
Matter.decommission();
|
||||||
}
|
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,6 +27,14 @@
|
||||||
// Matter Temperature Sensor Endpoint
|
// Matter Temperature Sensor Endpoint
|
||||||
MatterTemperatureSensor SimulatedTemperatureSensor;
|
MatterTemperatureSensor SimulatedTemperatureSensor;
|
||||||
|
|
||||||
|
// set your board USER BUTTON pin here - decommissioning button
|
||||||
|
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
|
||||||
|
|
||||||
|
// Button control - decommision the Matter Node
|
||||||
|
uint32_t button_time_stamp = 0; // debouncing control
|
||||||
|
bool button_state = false; // false = released | true = pressed
|
||||||
|
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
|
||||||
|
|
||||||
// WiFi is manually set and started
|
// WiFi is manually set and started
|
||||||
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
|
||||||
const char *password = "your-password"; // Change this to your WiFi password
|
const char *password = "your-password"; // Change this to your WiFi password
|
||||||
|
|
@ -47,6 +55,9 @@ float getSimulatedTemperature() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// Initialize the USER BUTTON (Boot button) that will be used to decommission the Matter Node
|
||||||
|
pinMode(buttonPin, INPUT_PULLUP);
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
// Manually connect to WiFi
|
// Manually connect to WiFi
|
||||||
|
|
@ -86,9 +97,35 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
Serial.printf("Current Temperature is %.02f <Temperature Units>\r\n", SimulatedTemperatureSensor.getTemperature());
|
static uint32_t timeCounter = 0;
|
||||||
// update the temperature sensor value every 5 seconds
|
|
||||||
// Matter APP shall display the updated temperature
|
// Print the current temperature value every 5s
|
||||||
delay(5000);
|
if (!(timeCounter++ % 10)) { // delaying for 500ms x 10 = 5s
|
||||||
SimulatedTemperatureSensor.setTemperature(getSimulatedTemperature());
|
// Print the current temperature value
|
||||||
|
Serial.printf("Current Temperature is %.02f <Temperature Units>\r\n", SimulatedTemperatureSensor.getTemperature());
|
||||||
|
// Update Temperature from the (Simulated) Hardware Sensor
|
||||||
|
// Matter APP shall display the updated temperature percent
|
||||||
|
SimulatedTemperatureSensor.setTemperature(getSimulatedTemperature());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the button has been pressed
|
||||||
|
if (digitalRead(buttonPin) == LOW && !button_state) {
|
||||||
|
// deals with button debouncing
|
||||||
|
button_time_stamp = millis(); // record the time while the button is pressed.
|
||||||
|
button_state = true; // pressed.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digitalRead(buttonPin) == HIGH && button_state) {
|
||||||
|
button_state = false; // released
|
||||||
|
}
|
||||||
|
|
||||||
|
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
|
||||||
|
uint32_t time_diff = millis() - button_time_stamp;
|
||||||
|
if (button_state && time_diff > decommissioningTimeout) {
|
||||||
|
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
||||||
|
Matter.decommission();
|
||||||
|
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(500);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,14 @@ const uint8_t ledPin = LED_BUILTIN;
|
||||||
const uint8_t ledPin = 2; // Set your pin here if your board has not defined LED_BUILTIN
|
const uint8_t ledPin = 2; // Set your pin here if your board has not defined LED_BUILTIN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// set your board USER BUTTON pin here - decommissioning button
|
||||||
|
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
|
||||||
|
|
||||||
|
// Button control - decommision the Matter Node
|
||||||
|
uint32_t button_time_stamp = 0; // debouncing control
|
||||||
|
bool button_state = false; // false = released | true = pressed
|
||||||
|
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
|
||||||
|
|
||||||
// Matter Protocol Endpoint (On/OFF Light) Callback
|
// Matter Protocol Endpoint (On/OFF Light) Callback
|
||||||
bool matterCB(bool state) {
|
bool matterCB(bool state) {
|
||||||
digitalWrite(ledPin, state ? HIGH : LOW);
|
digitalWrite(ledPin, state ? HIGH : LOW);
|
||||||
|
|
@ -49,6 +57,9 @@ bool matterCB(bool state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// Initialize the USER BUTTON (Boot button) that will be used to decommission the Matter Node
|
||||||
|
pinMode(buttonPin, INPUT_PULLUP);
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
// Initialize the LED GPIO
|
// Initialize the LED GPIO
|
||||||
pinMode(ledPin, OUTPUT);
|
pinMode(ledPin, OUTPUT);
|
||||||
|
|
@ -118,5 +129,24 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
// Check if the button has been pressed
|
||||||
|
if (digitalRead(buttonPin) == LOW && !button_state) {
|
||||||
|
// deals with button debouncing
|
||||||
|
button_time_stamp = millis(); // record the time while the button is pressed.
|
||||||
|
button_state = true; // pressed.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digitalRead(buttonPin) == HIGH && button_state) {
|
||||||
|
button_state = false; // released
|
||||||
|
}
|
||||||
|
|
||||||
|
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
|
||||||
|
uint32_t time_diff = millis() - button_time_stamp;
|
||||||
|
if (button_state && time_diff > decommissioningTimeout) {
|
||||||
|
Serial.println("Decommissioning the Light Matter Accessory. It shall be commissioned again.");
|
||||||
|
Matter.decommission();
|
||||||
|
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
|
||||||
|
}
|
||||||
|
|
||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue