Merge pull request #10732 from SuGlider/matter_while_serial

feat(matter): General Review - remove while(!serial)  ipv6(enable) and fixes some commentaries in the code
This commit is contained in:
Me No Dev 2024-12-16 19:11:52 +02:00 committed by GitHub
commit 30e55fc4b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 153 additions and 185 deletions

View file

@ -21,6 +21,10 @@
// Color Light Endpoint // Color Light Endpoint
MatterColorLight ColorLight; MatterColorLight ColorLight;
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// it will keep last OnOff & HSV Color state stored, using Preferences // it will keep last OnOff & HSV Color state stored, using Preferences
Preferences matterPref; Preferences matterPref;
const char *onOffPrefKey = "OnOff"; const char *onOffPrefKey = "OnOff";
@ -43,10 +47,6 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms) const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// Set the RGB LED Light based on the current state of the Color Light // Set the RGB LED Light based on the current state of the Color Light
bool setLightState(bool state, espHsvColor_t colorHSV) { bool setLightState(bool state, espHsvColor_t colorHSV) {
@ -76,15 +76,10 @@ void setup() {
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
Serial.begin(115200); Serial.begin(115200);
while (!Serial) {
delay(100);
}
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
Serial.print("Connecting to "); Serial.print("Connecting to ");
Serial.println(ssid); Serial.println(ssid);
// enable IPv6
WiFi.enableIPv6(true);
// Manually connect to WiFi // Manually connect to WiFi
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
// Wait for connection // Wait for connection

View file

@ -26,15 +26,10 @@ const char *password = "your-password"; // Change this to your WiFi password
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
while (!Serial) {
delay(100);
}
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
Serial.print("Connecting to "); Serial.print("Connecting to ");
Serial.println(ssid); Serial.println(ssid);
// enable IPv6
WiFi.enableIPv6(true);
// Manually connect to WiFi // Manually connect to WiFi
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
// Wait for connection // Wait for connection

View file

@ -55,15 +55,10 @@ void setup() {
pinMode(buttonPin, INPUT_PULLUP); pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(115200); Serial.begin(115200);
while (!Serial) {
delay(100);
}
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
Serial.print("Connecting to "); Serial.print("Connecting to ");
Serial.println(ssid); Serial.println(ssid);
// enable IPv6
WiFi.enableIPv6(true);
// Manually connect to WiFi // Manually connect to WiFi
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
// Wait for connection // Wait for connection

View file

@ -36,6 +36,10 @@
// Matter Contact Sensor Endpoint // Matter Contact Sensor Endpoint
MatterContactSensor ContactSensor; MatterContactSensor ContactSensor;
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// LED will be used to indicate the Contact Sensor state // LED will be used to indicate the Contact Sensor state
// set your board RGB LED pin here // set your board RGB LED pin here
#ifdef RGB_BUILTIN #ifdef RGB_BUILTIN
@ -48,10 +52,6 @@ const uint8_t ledPin = 2; // Set your pin here if your board has not defined LE
// set your board USER BUTTON pin here - decommissioning and Manual Contact Sensor toggle button // set your board USER BUTTON pin here - decommissioning and Manual Contact Sensor toggle button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button. const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// Button control // Button control
uint32_t button_time_stamp = 0; // debouncing control uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed bool button_state = false; // false = released | true = pressed

View file

@ -21,6 +21,10 @@
// Dimmable Light Endpoint // Dimmable Light Endpoint
MatterDimmableLight DimmableLight; MatterDimmableLight DimmableLight;
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// it will keep last OnOff & Brightness state stored, using Preferences // it will keep last OnOff & Brightness state stored, using Preferences
Preferences matterPref; Preferences matterPref;
const char *onOffPrefKey = "OnOff"; const char *onOffPrefKey = "OnOff";
@ -43,10 +47,6 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms) const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// Set the RGB LED Light based on the current state of the Dimmable Light // Set the RGB LED Light based on the current state of the Dimmable Light
bool setLightState(bool state, uint8_t brightness) { bool setLightState(bool state, uint8_t brightness) {
if (state) { if (state) {
@ -72,15 +72,10 @@ void setup() {
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
Serial.begin(115200); Serial.begin(115200);
while (!Serial) {
delay(100);
}
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
Serial.print("Connecting to "); Serial.print("Connecting to ");
Serial.println(ssid); Serial.println(ssid);
// enable IPv6
WiFi.enableIPv6(true);
// Manually connect to WiFi // Manually connect to WiFi
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
// Wait for connection // Wait for connection

View file

@ -21,6 +21,10 @@
// Color Light Endpoint // Color Light Endpoint
MatterEnhancedColorLight EnhancedColorLight; MatterEnhancedColorLight EnhancedColorLight;
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// It will use HSV color to control all Matter Attribute Changes // It will use HSV color to control all Matter Attribute Changes
HsvColor_t currentHSVColor = {0, 0, 0}; HsvColor_t currentHSVColor = {0, 0, 0};
@ -46,10 +50,6 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms) const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// Set the RGB LED Light based on the current state of the Enhanced Color Light // Set the RGB LED Light based on the current state of the Enhanced Color Light
bool setLightState(bool state, espHsvColor_t colorHSV, uint8_t brighteness, uint16_t temperature_Mireds) { bool setLightState(bool state, espHsvColor_t colorHSV, uint8_t brighteness, uint16_t temperature_Mireds) {
@ -80,15 +80,10 @@ void setup() {
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
Serial.begin(115200); Serial.begin(115200);
while (!Serial) {
delay(100);
}
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
Serial.print("Connecting to "); Serial.print("Connecting to ");
Serial.println(ssid); Serial.println(ssid);
// enable IPv6
WiFi.enableIPv6(true);
// Manually connect to WiFi // Manually connect to WiFi
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
// Wait for connection // Wait for connection

View file

@ -20,6 +20,10 @@
// Fan Endpoint - On/Off control + Speed Percent Control + Fan Modes // Fan Endpoint - On/Off control + Speed Percent Control + Fan Modes
MatterFan Fan; MatterFan Fan;
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// set your board USER BUTTON pin here - used for toggling On/Off and decommission the Matter Node // set your board USER BUTTON pin here - used for toggling On/Off and decommission the Matter Node
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button. const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
@ -41,10 +45,6 @@ const uint8_t dcMotorPin = 2; // Set your pin here if your board has not define
#warning "Do not forget to set the RGB LED pin" #warning "Do not forget to set the RGB LED pin"
#endif #endif
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
void fanDCMotorDrive(bool fanState, uint8_t speedPercent) { void fanDCMotorDrive(bool fanState, uint8_t speedPercent) {
// drive the Fan DC motor // drive the Fan DC motor
if (fanState == false) { if (fanState == false) {
@ -71,15 +71,10 @@ void setup() {
pinMode(dcMotorPin, OUTPUT); pinMode(dcMotorPin, OUTPUT);
Serial.begin(115200); Serial.begin(115200);
while (!Serial) {
delay(100);
}
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
Serial.print("Connecting to "); Serial.print("Connecting to ");
Serial.println(ssid); Serial.println(ssid);
// enable IPv6
WiFi.enableIPv6(true);
// Manually connect to WiFi // Manually connect to WiFi
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
// Wait for connection // Wait for connection

View file

@ -27,13 +27,13 @@
// Matter Humidity Sensor Endpoint // Matter Humidity Sensor Endpoint
MatterHumiditySensor SimulatedHumiditySensor; MatterHumiditySensor SimulatedHumiditySensor;
// set your board USER BUTTON pin here - decommissioning button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
// 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 - decommissioning button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
// Button control - decommision the Matter Node // Button control - decommision the Matter Node
uint32_t button_time_stamp = 0; // debouncing control uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed bool button_state = false; // false = released | true = pressed

View file

@ -28,6 +28,10 @@
// Single On/Off Light Endpoint - at least one per node // Single On/Off Light Endpoint - at least one per node
MatterOnOffLight OnOffLight; MatterOnOffLight OnOffLight;
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// Light GPIO that can be controlled by Matter APP // Light GPIO that can be controlled by Matter APP
#ifdef LED_BUILTIN #ifdef LED_BUILTIN
const uint8_t ledPin = LED_BUILTIN; const uint8_t ledPin = LED_BUILTIN;
@ -44,23 +48,18 @@ bool button_state = false; // false = released | true = pres
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission 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 onOffLightCallback(bool state) {
digitalWrite(ledPin, state ? HIGH : LOW); digitalWrite(ledPin, state ? HIGH : LOW);
// This callback must return the success state to Matter core // This callback must return the success state to Matter core
return true; return true;
} }
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
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 // Initialize the USER BUTTON (Boot button) that will be used to decommission the Matter Node
pinMode(buttonPin, INPUT_PULLUP); pinMode(buttonPin, INPUT_PULLUP);
// Initialize the LED GPIO // Initialize the LED GPIO
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
WiFi.enableIPv6(true);
// Manually connect to WiFi // Manually connect to WiFi
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
// Wait for connection // Wait for connection
@ -72,7 +71,7 @@ void setup() {
OnOffLight.begin(); OnOffLight.begin();
// Associate a callback to the Matter Controller // Associate a callback to the Matter Controller
OnOffLight.onChange(matterCB); OnOffLight.onChange(onOffLightCallback);
// Matter beginning - Last step, after all EndPoints are initialized // Matter beginning - Last step, after all EndPoints are initialized
Matter.begin(); Matter.begin();

View file

@ -34,13 +34,13 @@
// Matter Occupancy Sensor Endpoint // Matter Occupancy Sensor Endpoint
MatterOccupancySensor OccupancySensor; MatterOccupancySensor OccupancySensor;
// set your board USER BUTTON pin here - decommissioning only
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
// 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 - decommissioning only
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
// Button control // Button control
uint32_t button_time_stamp = 0; // debouncing control uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed bool button_state = false; // false = released | true = pressed

View file

@ -17,6 +17,10 @@
#include <WiFi.h> #include <WiFi.h>
#include <Preferences.h> #include <Preferences.h>
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// List of Matter Endpoints for this Node // List of Matter Endpoints for this Node
// On/Off Light Endpoint // On/Off Light Endpoint
MatterOnOffLight OnOffLight; MatterOnOffLight OnOffLight;
@ -42,10 +46,6 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms) const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// Matter Protocol Endpoint Callback // Matter Protocol Endpoint Callback
bool setLightOnOff(bool state) { bool setLightOnOff(bool state) {
Serial.printf("User Callback :: New Light State = %s\r\n", state ? "ON" : "OFF"); Serial.printf("User Callback :: New Light State = %s\r\n", state ? "ON" : "OFF");
@ -67,15 +67,10 @@ void setup() {
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
Serial.begin(115200); Serial.begin(115200);
while (!Serial) {
delay(100);
}
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
Serial.print("Connecting to "); Serial.print("Connecting to ");
Serial.println(ssid); Serial.println(ssid);
// enable IPv6
WiFi.enableIPv6(true);
// Manually connect to WiFi // Manually connect to WiFi
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
// Wait for connection // Wait for connection

View file

@ -21,6 +21,10 @@
// On/Off Plugin Endpoint // On/Off Plugin Endpoint
MatterOnOffPlugin OnOffPlugin; MatterOnOffPlugin OnOffPlugin;
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// it will keep last OnOff state stored, using Preferences // it will keep last OnOff state stored, using Preferences
Preferences matterPref; Preferences matterPref;
const char *onOffPrefKey = "OnOff"; const char *onOffPrefKey = "OnOff";
@ -41,10 +45,6 @@ uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed bool button_state = false; // false = released | true = pressed
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// Matter Protocol Endpoint Callback // Matter Protocol Endpoint Callback
bool setPluginOnOff(bool state) { bool setPluginOnOff(bool state) {
Serial.printf("User Callback :: New Plugin State = %s\r\n", state ? "ON" : "OFF"); Serial.printf("User Callback :: New Plugin State = %s\r\n", state ? "ON" : "OFF");

View file

@ -27,13 +27,13 @@
// Matter Pressure Sensor Endpoint // Matter Pressure Sensor Endpoint
MatterPressureSensor SimulatedPressureSensor; MatterPressureSensor SimulatedPressureSensor;
// set your board USER BUTTON pin here - decommissioning button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
// 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 - decommissioning button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
// Button control - decommision the Matter Node // Button control - decommision the Matter Node
uint32_t button_time_stamp = 0; // debouncing control uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed bool button_state = false; // false = released | true = pressed

View file

@ -20,6 +20,10 @@
// Generic Switch Endpoint - works as a smart button with a single click // Generic Switch Endpoint - works as a smart button with a single click
MatterGenericSwitch SmartButton; MatterGenericSwitch SmartButton;
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// set your board USER BUTTON pin here // set your board USER BUTTON pin here
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button. const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
@ -29,24 +33,16 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms) const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
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 smart button or to decommission the Matter Node // 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);
while (!Serial) {
delay(100);
}
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
Serial.print("Connecting to "); Serial.print("Connecting to ");
Serial.println(ssid); Serial.println(ssid);
// enable IPv6
WiFi.enableIPv6(true);
// Manually connect to WiFi // Manually connect to WiFi
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
// Wait for connection // Wait for connection

View file

@ -21,6 +21,10 @@
// Color Temperature CW/WW Light Endpoint // Color Temperature CW/WW Light Endpoint
MatterColorTemperatureLight CW_WW_Light; MatterColorTemperatureLight CW_WW_Light;
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// it will keep last OnOff & Brightness state stored, using Preferences // it will keep last OnOff & Brightness state stored, using Preferences
Preferences matterPref; Preferences matterPref;
const char *onOffPrefKey = "OnOff"; const char *onOffPrefKey = "OnOff";
@ -44,10 +48,6 @@ bool button_state = false; // false = released | true = pres
const uint32_t debouceTime = 250; // button debouncing time (ms) const uint32_t debouceTime = 250; // button debouncing time (ms)
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// Set the RGB LED Light based on the current state of the Color Temperature Light // Set the RGB LED Light based on the current state of the Color Temperature Light
bool setLightState(bool state, uint8_t brightness, uint16_t temperature_Mireds) { bool setLightState(bool state, uint8_t brightness, uint16_t temperature_Mireds) {
@ -83,15 +83,10 @@ void setup() {
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
Serial.begin(115200); Serial.begin(115200);
while (!Serial) {
delay(100);
}
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
Serial.print("Connecting to "); Serial.print("Connecting to ");
Serial.println(ssid); Serial.println(ssid);
// enable IPv6
WiFi.enableIPv6(true);
// Manually connect to WiFi // Manually connect to WiFi
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
// Wait for connection // Wait for connection

View file

@ -27,6 +27,10 @@
// Matter Temperature Sensor Endpoint // Matter Temperature Sensor Endpoint
MatterTemperatureSensor SimulatedTemperatureSensor; MatterTemperatureSensor SimulatedTemperatureSensor;
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// set your board USER BUTTON pin here - decommissioning button // set your board USER BUTTON pin here - decommissioning button
const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button. const uint8_t buttonPin = BOOT_PIN; // Set your pin here. Using BOOT Button.
@ -35,10 +39,6 @@ uint32_t button_time_stamp = 0; // debouncing control
bool button_state = false; // false = released | true = pressed bool button_state = false; // false = released | true = pressed
const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission const uint32_t decommissioningTimeout = 5000; // keep the button pressed for 5s, or longer, to decommission
// WiFi is manually set and started
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
const char *password = "your-password"; // Change this to your WiFi password
// Simulate a temperature sensor - add your preferred temperature sensor library code here // Simulate a temperature sensor - add your preferred temperature sensor library code here
float getSimulatedTemperature() { float getSimulatedTemperature() {
// The Endpoint implementation keeps an int16_t as internal value information, // The Endpoint implementation keeps an int16_t as internal value information,

View file

@ -206,7 +206,7 @@ bool MatterColorLight::setOnOff(bool newState) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (onOffState == newState) { if (onOffState == newState) {
return true; return true;
} }
@ -256,7 +256,7 @@ bool MatterColorLight::setColorHSV(espHsvColor_t _hsvColor) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (colorHSV.h == _hsvColor.h && colorHSV.s == _hsvColor.s && colorHSV.v == _hsvColor.v) { if (colorHSV.h == _hsvColor.h && colorHSV.s == _hsvColor.s && colorHSV.v == _hsvColor.v) {
return true; return true;
} }

View file

@ -37,16 +37,6 @@ public:
bool setColorHSV(espHsvColor_t hsvColor); // returns true if successful bool setColorHSV(espHsvColor_t hsvColor); // returns true if successful
espHsvColor_t getColorHSV(); // returns current HSV Color espHsvColor_t getColorHSV(); // returns current HSV Color
// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();
operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
// User Callback for whenever the Light On/Off state is changed by the Matter Controller // User Callback for whenever the Light On/Off state is changed by the Matter Controller
using EndPointOnOffCB = std::function<bool(bool)>; using EndPointOnOffCB = std::function<bool(bool)>;
void onChangeOnOff(EndPointOnOffCB onChangeCB) { void onChangeOnOff(EndPointOnOffCB onChangeCB) {
@ -64,6 +54,16 @@ public:
_onChangeCB = onChangeCB; _onChangeCB = onChangeCB;
} }
// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();
operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
protected: protected:
bool started = false; bool started = false;
bool onOffState = false; // default initial state is off, but it can be changed by begin(bool) bool onOffState = false; // default initial state is off, but it can be changed by begin(bool)

View file

@ -138,7 +138,7 @@ bool MatterColorTemperatureLight::setOnOff(bool newState) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (onOffState == newState) { if (onOffState == newState) {
return true; return true;
} }
@ -179,7 +179,7 @@ bool MatterColorTemperatureLight::setBrightness(uint8_t newBrightness) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (brightnessLevel == newBrightness) { if (brightnessLevel == newBrightness) {
return true; return true;
} }
@ -210,7 +210,7 @@ bool MatterColorTemperatureLight::setColorTemperature(uint16_t newTemperature) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (colorTemperatureLevel == newTemperature) { if (colorTemperatureLevel == newTemperature) {
return true; return true;
} }

View file

@ -42,16 +42,6 @@ public:
bool setColorTemperature(uint16_t newTemperature); // returns true if successful bool setColorTemperature(uint16_t newTemperature); // returns true if successful
uint16_t getColorTemperature(); // returns current temperature uint16_t getColorTemperature(); // returns current temperature
// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();
operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
// User Callback for whenever the Light On/Off state is changed by the Matter Controller // User Callback for whenever the Light On/Off state is changed by the Matter Controller
using EndPointOnOffCB = std::function<bool(bool)>; using EndPointOnOffCB = std::function<bool(bool)>;
void onChangeOnOff(EndPointOnOffCB onChangeCB) { void onChangeOnOff(EndPointOnOffCB onChangeCB) {
@ -76,6 +66,16 @@ public:
_onChangeCB = onChangeCB; _onChangeCB = onChangeCB;
} }
// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();
operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
protected: protected:
bool started = false; bool started = false;
bool onOffState = false; // default initial state is off, but it can be changed by begin(bool) bool onOffState = false; // default initial state is off, but it can be changed by begin(bool)

View file

@ -69,7 +69,7 @@ bool MatterContactSensor::setContact(bool _contactState) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (contactState == _contactState) { if (contactState == _contactState) {
return true; return true;
} }

View file

@ -114,7 +114,7 @@ bool MatterDimmableLight::setOnOff(bool newState) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (onOffState == newState) { if (onOffState == newState) {
return true; return true;
} }
@ -155,7 +155,7 @@ bool MatterDimmableLight::setBrightness(uint8_t newBrightness) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (brightnessLevel == newBrightness) { if (brightnessLevel == newBrightness) {
return true; return true;
} }

View file

@ -37,19 +37,12 @@ public:
bool setBrightness(uint8_t newBrightness); // returns true if successful bool setBrightness(uint8_t newBrightness); // returns true if successful
uint8_t getBrightness(); // returns current brightness uint8_t getBrightness(); // returns current brightness
// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();
operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
// User Callback for whenever the Light On/Off state is changed by the Matter Controller // User Callback for whenever the Light On/Off state is changed by the Matter Controller
using EndPointOnOffCB = std::function<bool(bool)>; using EndPointOnOffCB = std::function<bool(bool)>;
void onChangeOnOff(EndPointOnOffCB onChangeCB) { void onChangeOnOff(EndPointOnOffCB onChangeCB) {
_onChangeOnOffCB = onChangeCB; _onChangeOnOffCB = onChangeCB;
} }
// User Callback for whenever the Light brightness value [0..255] is changed by the Matter Controller // User Callback for whenever the Light brightness value [0..255] is changed by the Matter Controller
using EndPointBrightnessCB = std::function<bool(uint8_t)>; using EndPointBrightnessCB = std::function<bool(uint8_t)>;
void onChangeBrightness(EndPointBrightnessCB onChangeCB) { void onChangeBrightness(EndPointBrightnessCB onChangeCB) {
@ -62,6 +55,15 @@ public:
_onChangeCB = onChangeCB; _onChangeCB = onChangeCB;
} }
// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();
operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
protected: protected:
bool started = false; bool started = false;
bool onOffState = false; // default initial state is off, but it can be changed by begin(bool) bool onOffState = false; // default initial state is off, but it can be changed by begin(bool)

View file

@ -226,7 +226,7 @@ bool MatterEnhancedColorLight::setOnOff(bool newState) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (onOffState == newState) { if (onOffState == newState) {
return true; return true;
} }
@ -267,7 +267,7 @@ bool MatterEnhancedColorLight::setBrightness(uint8_t newBrightness) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (brightnessLevel == newBrightness) { if (brightnessLevel == newBrightness) {
return true; return true;
} }
@ -298,7 +298,7 @@ bool MatterEnhancedColorLight::setColorTemperature(uint16_t newTemperature) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (colorTemperatureLevel == newTemperature) { if (colorTemperatureLevel == newTemperature) {
return true; return true;
} }
@ -338,7 +338,7 @@ bool MatterEnhancedColorLight::setColorHSV(espHsvColor_t _hsvColor) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (colorHSV.h == _hsvColor.h && colorHSV.s == _hsvColor.s && colorHSV.v == _hsvColor.v) { if (colorHSV.h == _hsvColor.h && colorHSV.s == _hsvColor.s && colorHSV.v == _hsvColor.v) {
return true; return true;
} }

View file

@ -47,16 +47,6 @@ public:
bool setColorHSV(espHsvColor_t hsvColor); // returns true if successful bool setColorHSV(espHsvColor_t hsvColor); // returns true if successful
espHsvColor_t getColorHSV(); // returns current HSV Color espHsvColor_t getColorHSV(); // returns current HSV Color
// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();
operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
// User Callback for whenever the Light On/Off state is changed by the Matter Controller // User Callback for whenever the Light On/Off state is changed by the Matter Controller
using EndPointOnOffCB = std::function<bool(bool)>; using EndPointOnOffCB = std::function<bool(bool)>;
void onChangeOnOff(EndPointOnOffCB onChangeCB) { void onChangeOnOff(EndPointOnOffCB onChangeCB) {
@ -87,6 +77,16 @@ public:
_onChangeCB = onChangeCB; _onChangeCB = onChangeCB;
} }
// used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory();
operator bool(); // returns current on/off light state
void operator=(bool state); // turns light on or off
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
protected: protected:
bool started = false; bool started = false;
bool onOffState = false; // default initial state is off, but it can be changed by begin(bool) bool onOffState = false; // default initial state is off, but it can be changed by begin(bool)

View file

@ -118,7 +118,7 @@ bool MatterFan::setMode(FanMode_t newMode, bool performUpdate) {
log_w("Matter Fan device has not begun."); log_w("Matter Fan device has not begun.");
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (currentFanMode == newMode) { if (currentFanMode == newMode) {
return true; return true;
} }
@ -159,7 +159,7 @@ bool MatterFan::setSpeedPercent(uint8_t newPercent, bool performUpdate) {
log_w("Matter Fan device has not begun."); log_w("Matter Fan device has not begun.");
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (currentPercent == newPercent) { if (currentPercent == newPercent) {
return true; return true;
} }
@ -193,7 +193,7 @@ bool MatterFan::setOnOff(bool newState, bool performUpdate) {
log_w("Matter Fan device has not begun."); log_w("Matter Fan device has not begun.");
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (getOnOff() == newState) { if (getOnOff() == newState) {
return true; return true;
} }

View file

@ -98,13 +98,6 @@ public:
operator uint8_t() { operator uint8_t() {
return getSpeedPercent(); return getSpeedPercent();
} }
// sets Fan speed percent
void operator=(uint8_t speedPercent) {
setSpeedPercent(speedPercent);
}
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
// User Callback for whenever the Fan Mode (state) is changed by the Matter Controller // User Callback for whenever the Fan Mode (state) is changed by the Matter Controller
using EndPointModeCB = std::function<bool(FanMode_t)>; using EndPointModeCB = std::function<bool(FanMode_t)>;
@ -124,6 +117,14 @@ public:
_onChangeCB = onChangeCB; _onChangeCB = onChangeCB;
} }
// sets Fan speed percent
void operator=(uint8_t speedPercent) {
setSpeedPercent(speedPercent);
}
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
protected: protected:
bool started = false; bool started = false;
uint8_t validFanModes = 0; // bitmap for valid Fan Modes - index of fanModeSequence[] uint8_t validFanModes = 0; // bitmap for valid Fan Modes - index of fanModeSequence[]

View file

@ -82,7 +82,7 @@ bool MatterHumiditySensor::setRawHumidity(uint16_t _rawHumidity) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (rawHumidity == _rawHumidity) { if (rawHumidity == _rawHumidity) {
return true; return true;
} }
@ -98,7 +98,7 @@ bool MatterHumiditySensor::setRawHumidity(uint16_t _rawHumidity) {
bool ret; bool ret;
ret = updateAttributeVal(RelativeHumidityMeasurement::Id, RelativeHumidityMeasurement::Attributes::MeasuredValue::Id, &humidityVal); ret = updateAttributeVal(RelativeHumidityMeasurement::Id, RelativeHumidityMeasurement::Attributes::MeasuredValue::Id, &humidityVal);
if (!ret) { if (!ret) {
log_e("Failed to update Fan Speed Percent Attribute."); log_e("Failed to update Humidity Sensor Attribute.");
return false; return false;
} }
rawHumidity = _rawHumidity; rawHumidity = _rawHumidity;

View file

@ -80,7 +80,7 @@ bool MatterOccupancySensor::setOccupancy(bool _occupancyState) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (occupancyState == _occupancyState) { if (occupancyState == _occupancyState) {
return true; return true;
} }

View file

@ -94,7 +94,7 @@ bool MatterOnOffLight::setOnOff(bool newState) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (onOffState == newState) { if (onOffState == newState) {
return true; return true;
} }

View file

@ -30,22 +30,26 @@ public:
bool getOnOff(); // returns current light state bool getOnOff(); // returns current light state
bool toggle(); // returns true if successful bool toggle(); // returns true if successful
// User Callback for whenever the Light state is changed by the Matter Controller
using EndPointCB = std::function<bool(bool)>;
void onChange(EndPointCB onChangeCB) {
_onChangeCB = onChangeCB;
}
// User Callback for whenever the Light On/Off state is changed by the Matter Controller
void onChangeOnOff(EndPointCB onChangeCB) {
_onChangeOnOffCB = onChangeCB;
}
// used to update the state of the light using the current Matter Light internal state // used to update the state of the light using the current Matter Light internal state
// It is necessary to set a user callback function using onChange() to handle the physical light state // It is necessary to set a user callback function using onChange() to handle the physical light state
void updateAccessory(); void updateAccessory();
operator bool(); // returns current light state operator bool(); // returns current light state
void operator=(bool state); // turns light on or off void operator=(bool state); // turns light on or off
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary. // this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val); bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
// User Callback for whenever the Light state is changed by the Matter Controller
using EndPointCB = std::function<bool(bool)>;
void onChange(EndPointCB onChangeCB) {
_onChangeCB = onChangeCB;
}
void onChangeOnOff(EndPointCB onChangeCB) {
_onChangeOnOffCB = onChangeCB;
}
protected: protected:
bool started = false; bool started = false;

View file

@ -93,7 +93,7 @@ bool MatterOnOffPlugin::setOnOff(bool newState) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (onOffState == newState) { if (onOffState == newState) {
return true; return true;
} }

View file

@ -30,22 +30,26 @@ public:
bool getOnOff(); // returns current plugin state bool getOnOff(); // returns current plugin state
bool toggle(); // returns true if successful bool toggle(); // returns true if successful
// User Callback for whenever the Plugin state is changed by the Matter Controller
using EndPointCB = std::function<bool(bool)>;
void onChange(EndPointCB onChangeCB) {
_onChangeCB = onChangeCB;
}
// User Callback for whenever the On/Off state is changed by the Matter Controller
void onChangeOnOff(EndPointCB onChangeCB) {
_onChangeOnOffCB = onChangeCB;
}
// used to update the state of the plugin using the current Matter Plugin internal state // used to update the state of the plugin using the current Matter Plugin internal state
// It is necessary to set a user callback function using onChange() to handle the physical plugin state // It is necessary to set a user callback function using onChange() to handle the physical plugin state
void updateAccessory(); void updateAccessory();
operator bool(); // returns current plugin state operator bool(); // returns current plugin state
void operator=(bool state); // turns plugin on or off void operator=(bool state); // turns plugin on or off
// this function is called by Matter internal event processor. It could be overwritten by the application, if necessary. // this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val); bool attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
// User Callback for whenever the Plugin state is changed by the Matter Controller
using EndPointCB = std::function<bool(bool)>;
void onChange(EndPointCB onChangeCB) {
_onChangeCB = onChangeCB;
}
void onChangeOnOff(EndPointCB onChangeCB) {
_onChangeOnOffCB = onChangeCB;
}
protected: protected:
bool started = false; bool started = false;

View file

@ -70,7 +70,7 @@ bool MatterPressureSensor::setRawPressure(int16_t _rawPressure) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (rawPressure == _rawPressure) { if (rawPressure == _rawPressure) {
return true; return true;
} }

View file

@ -39,6 +39,7 @@ public:
double getPressure() { double getPressure() {
return (double)rawPressure; return (double)rawPressure;
} }
// double conversion operator // double conversion operator
void operator=(double pressure) { void operator=(double pressure) {
setPressure(pressure); setPressure(pressure);

View file

@ -70,7 +70,7 @@ bool MatterTemperatureSensor::setRawTemperature(int16_t _rawTemperature) {
return false; return false;
} }
// avoid processing the a "no-change" // avoid processing if there was no change
if (rawTemperature == _rawTemperature) { if (rawTemperature == _rawTemperature) {
return true; return true;
} }
@ -86,7 +86,7 @@ bool MatterTemperatureSensor::setRawTemperature(int16_t _rawTemperature) {
bool ret; bool ret;
ret = updateAttributeVal(TemperatureMeasurement::Id, TemperatureMeasurement::Attributes::MeasuredValue::Id, &temperatureVal); ret = updateAttributeVal(TemperatureMeasurement::Id, TemperatureMeasurement::Attributes::MeasuredValue::Id, &temperatureVal);
if (!ret) { if (!ret) {
log_e("Failed to update Fan Speed Percent Attribute."); log_e("Failed to update Temperature Sensor Attribute.");
return false; return false;
} }
rawTemperature = _rawTemperature; rawTemperature = _rawTemperature;

View file

@ -40,6 +40,7 @@ public:
double getTemperature() { double getTemperature() {
return (double)rawTemperature / 100.0; return (double)rawTemperature / 100.0;
} }
// double conversion operator // double conversion operator
void operator=(double temperature) { void operator=(double temperature) {
setTemperature(temperature); setTemperature(temperature);