@@ -23,6 +23,7 @@ MatterOnOffLight OnOffLight;
2323
2424// it will keep last OnOff state stored, using Preferences
2525Preferences lastStatePref;
26+ #define ON_OFF_PREF_KEY " lastOnOffState"
2627
2728// set your board LED pin here
2829#ifdef LED_BUILTIN
@@ -48,7 +49,7 @@ bool setLightOnOff(bool state) {
4849 digitalWrite (ledPin, LOW);
4950 }
5051 // store last OnOff state for when the Light is restarted / power goes off
51- lastStatePref.putBool (" lastOnOffState " , state);
52+ lastStatePref.putBool (ON_OFF_PREF_KEY , state);
5253 // This callback must return the success state to Matter core
5354 return true ;
5455}
@@ -83,8 +84,8 @@ void setup() {
8384
8485 // Initialize Matter EndPoint
8586 lastStatePref.begin (" matterLight" , false );
86- bool lastOnOffState = lastStatePref.getBool (" lastOnOffState " , true );
87- OnOffLight.begin (lastOnOffState);
87+ bool lastOnOffState = lastStatePref.getBool (ON_OFF_PREF_KEY , true );
88+ OnOffLight.begin (lastOnOffState);
8889 OnOffLight.onChange (setLightOnOff);
8990
9091 // Matter beginning - Last step, after all EndPoints are initialized
0 commit comments