32
32
// Single On/Off Light Endpoint - at least one per node
33
33
MatterOnOffLight OnOffLight;
34
34
35
+ // WiFi is manually set and started
36
+ const char *ssid = " your-ssid" ; // Change this to your WiFi SSID
37
+ const char *password = " your-password" ; // Change this to your WiFi password
38
+
35
39
// Light GPIO that can be controlled by Matter APP
36
40
#ifdef LED_BUILTIN
37
41
const uint8_t ledPin = LED_BUILTIN;
@@ -48,15 +52,23 @@ bool button_state = false; // false = released | true = pres
48
52
const uint32_t decommissioningTimeout = 5000 ; // keep the button pressed for 5s, or longer, to decommission
49
53
50
54
// Matter Protocol Endpoint (On/OFF Light) Callback
51
- bool matterCB (bool state) {
55
+ bool onOffLightCallback (bool state) {
52
56
digitalWrite (ledPin, state ? HIGH : LOW);
53
57
// This callback must return the success state to Matter core
54
58
return true ;
55
59
}
56
60
57
- // WiFi is manually set and started
58
- const char *ssid = " your-ssid" ; // Change this to your WiFi SSID
59
- const char *password = " your-password" ; // Change this to your WiFi password
61
+ bool onIdentifyLightCallback (bool identifyIsActive, uint8_t counter) {
62
+ log_i (" Identify Cluster is %s, counter: %d" , identifyIsActive ? " Active" : " Inactive" , counter);
63
+ if (identifyIsActive) {
64
+ // Start Blinking the light
65
+ OnOffLight.toggle ();
66
+ } else {
67
+ // Stop Blinking and restore the light to the its last state
68
+ OnOffLight.updateAccessory ();
69
+ }
70
+ return true ;
71
+ }
60
72
61
73
void setup () {
62
74
// Initialize the USER BUTTON (Boot button) that will be used to decommission the Matter Node
@@ -75,20 +87,10 @@ void setup() {
75
87
OnOffLight.begin ();
76
88
77
89
// On Identify Callback - Blink the LED
78
- OnOffLight.onIdentify ([](bool identifyIsActive, uint8_t counter) {
79
- log_i (" Identify Cluster is %s, counter: %d" , identifyIsActive ? " Active" : " Inactive" , counter);
80
- if (identifyIsActive) {
81
- // Start Blinking the light
82
- OnOffLight.toggle ();
83
- } else {
84
- // Stop Blinking and restore the light to the its last state
85
- OnOffLight.updateAccessory ();
86
- }
87
- return true ;
88
- });
90
+ OnOffLight.onIdentify (onIdentifyLightCallback);
89
91
90
92
// Associate a callback to the Matter Controller
91
- OnOffLight.onChange (matterCB );
93
+ OnOffLight.onChange (onOffLightCallback );
92
94
93
95
// Matter beginning - Last step, after all EndPoints are initialized
94
96
Matter.begin ();
0 commit comments