-
Notifications
You must be signed in to change notification settings - Fork 7.6k
multiple endpoints? #11233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@giulioto - What is the Matter envrionment that you have there? Apple, Google, Alexa, ... |
I'm using Samsung SmartThings, my smart TV is the hub. |
@giulioto - I'm sure that ESP32 Matter Arduino library using the two endpoints (MatterOccupancySensor + MatterOnOffPlugin) works correctly as expected. I have made it work using a Alexa device/APP with WiFi. What is the Arduino Core version that you are using? ESP32 Core 3.1.x has Matter 1.3 and Core 3.2 has Matter 1.4. When compiling an uploading the sketch, please make sure to enable "Erase All Flash Before Sketch Upload" option, select the Huge Partition option and enabling Debug Info Level to see additional debug messages. Actually ESP32 Matter Arduino Library works fine with any kind of endpoint combination. We have demonstrated a single ESP32 board with more than one endpoint working fine in the Embedded World last month. I use Amazon Alexa and it finds and commissions both, the OccupancySensor and the Plugin. This is the scketch:// Matter Manager
#include <Matter.h>
#include <WiFi.h>
#include <Preferences.h>
// List of Matter Endpoints for this Node
// On/Off Plugin Endpoint
MatterOnOffPlugin OnOffPlugin;
// Matter Occupancy Sensor Endpoint
MatterOccupancySensor OccupancySensor;
// 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
Preferences matterPref;
const char *onOffPrefKey = "OnOff";
// LED will be used to indicate the current Occupancy state
// set your board RGB LED pin here
#ifdef RGB_BUILTIN
const uint8_t ledPin = RGB_BUILTIN;
#else
const uint8_t ledPin = 2; // Set your pin here if your board has not defined LED_BUILTIN
#warning "Do not forget to set the RGB LED pin"
#endif
// set your board Power Relay pin here - this example uses the built-in LED for easy visualization
const uint8_t onoffPin = 4; // Set your pin here - usually a power relay
// set your board USER BUTTON pin here
// used for decommissioning and Manual Power Plugin toggle button
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
// Matter Protocol Endpoint Callback
bool setPluginOnOff(bool state) {
Serial.printf("User Callback :: New Plugin State = %s\r\n", state ? "ON" : "OFF");
if (state) {
digitalWrite(onoffPin, HIGH);
} else {
digitalWrite(onoffPin, LOW);
}
// store last OnOff state for when the Plugin is restarted / power goes off
matterPref.putBool(onOffPrefKey, state);
// This callback must return the success state to Matter core
return true;
}
// This routine simulates a "timed occupancy sensor".
// It will toggle its state every 30 seconds (30,000 milliseconds)
// Real one should read a GPIO connected to a PIR or some other device
// This should be called from loop()
bool simulatedHWOccupancySensor() {
// Simulated Occupancy Sensor
static bool occupancyState = false;
static uint32_t lastTime = millis();
const uint32_t occupancyTimeout = 30000; // 30 seconds to toggle the state
// Simulate a Occupancy Sensor state change every 30 seconds
if (millis() - lastTime > occupancyTimeout) {
occupancyState = !occupancyState;
// LED will indicate the Occupancy Sensor state
if (occupancyState) {
digitalWrite(ledPin, HIGH); // LED ON
} else {
digitalWrite(ledPin, LOW); // LED OFF
}
lastTime = millis();
Serial.printf("Occupancy State is %s\r\n", occupancyState ? "Occupied" : "Vacant");
}
return occupancyState;
}
void setup() {
// Initialize the USER BUTTON (Boot button) that will be used to decommission the Matter Node
// The button will also be used to manually toggle the Contact Sensor state
pinMode(buttonPin, INPUT_PULLUP);
// Initialize the LED GPIO used to indicate occupancy and Matter End Point
pinMode(ledPin, OUTPUT);
// Initialize the Power Plug (relay) GPIO
pinMode(onoffPin, OUTPUT);
Serial.begin(115200);
// Manually connect to WiFi
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
// Initialize Matter EndPoint
matterPref.begin("MatterPrefs", false);
bool lastOnOffState = matterPref.getBool(onOffPrefKey, false);
OnOffPlugin.begin(lastOnOffState);
OnOffPlugin.onChange(setPluginOnOff);
// set initial occupancy sensor state as false and connected to a PIR sensor type (default)
OccupancySensor.begin();
digitalWrite(ledPin, LOW); // LED OFF
// Matter beginning - Last step, after all EndPoints are initialized
Matter.begin();
// Check Matter Accessory Commissioning state, which may change during execution of loop()
if (!Matter.isDeviceCommissioned()) {
Serial.println("");
Serial.println("Matter Node is not commissioned yet.");
Serial.println("Initiate the device discovery in your Matter environment.");
Serial.println("Commission it to your Matter hub with the manual pairing code or QR code");
Serial.printf("Manual pairing code: %s\r\n", Matter.getManualPairingCode().c_str());
Serial.printf("QR code URL: %s\r\n", Matter.getOnboardingQRCodeUrl().c_str());
// waits for Matter Contact Sensor Commissioning.
uint32_t timeCount = 0;
while (!Matter.isDeviceCommissioned()) {
delay(100);
if ((timeCount++ % 50) == 0) { // 50*100ms = 5 sec
Serial.println("Matter Node not commissioned yet. Waiting for commissioning.");
}
}
Serial.println("Matter Node is commissioned and connected to Wi-Fi. Ready for use.");
}
Serial.println("This device has 2 endpoints:");
Serial.println("1 - Occupancy Sensor that toogles automatically based on time - 30 seconds");
Serial.println("2 - Power Plug that uses the BOOT Pin to toggle its state (on/off)");
Serial.println("The Occupancy Sensor state can be seen in the Alexa APP");
Serial.println("The Power Plug can be controlled by the Alexa APP");
Serial.println("Both can be used to create routines (automation) using Alexa APP");
Serial.println("Initial end point states:");
Serial.printf("Power Plugin State: %s\r\n", OnOffPlugin.getOnOff() ? "ON" : "OFF");
OnOffPlugin.updateAccessory(); // configure the Plugin based on initial state
Serial.printf("Occupancy State is %s\r\n", OccupancySensor ? "Occupied" : "Vacant");
}
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.
}
uint32_t time_diff = millis() - button_time_stamp;
if (button_state && time_diff > debouceTime && digitalRead(buttonPin) == HIGH) {
button_state = false; // released
// button is released - toggle Power Plugin State (Open/Closed)
OnOffPlugin.toggle(); // toggle power outlet
Serial.printf("User button released. Setting the Power Plugin to %s.\r\n", OnOffPlugin ? "Closed" : "Open");
}
// Onboard User Button is kept pressed for longer than 5 seconds in order to decommission matter node
if (button_state && time_diff > decommissioningTimeout) {
Serial.println("Decommissioning Contact Sensor Matter Accessory. It shall be commissioned again.");
OnOffPlugin.setOnOff(false); // turn the plugin off
Matter.decommission();
button_time_stamp = millis(); // avoid running decommissining again, reboot takes a second or so
}
// Check (timed) Simulated Occupancy Sensor and set Matter Attribute
OccupancySensor.setOccupancy(simulatedHWOccupancySensor());
delay(50);
} |
I solved the problem. |
Board
ESP32 DevKitC
Device Description
DevKitC
Hardware Configuration
OccupancySensor on GPIO23, Relay on GPIO02
Version
latest stable Release (if not listed below)
IDE Name
Arduino IDE
Operating System
Win11
Flash frequency
80MHz
PSRAM enabled
yes
Upload speed
115200
Description
I'd like to use a MatterOccupancySensor on GPIO23 and a MatterOnOffPlugin (relay activation) on GPIO2.
The sketch compile correctly, but after commissioning the Matter device i see only the plugin device, the sensor don't exist.
I don't know if is possible use more than 1 type of endpoint on matter device.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: