-
Notifications
You must be signed in to change notification settings - Fork 7.6k
feat(matter): initial commit with arduino matter lib #10467
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
Merged
me-no-dev
merged 24 commits into
espressif:release/v3.1.x
from
SuGlider:arduino_matter_library
Oct 21, 2024
Merged
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1229e54
feat(matter): initial commit with arduino matter lib
SuGlider a9a6fc2
feat(matter): add matter library to cmakelists.txt
SuGlider 713a1d6
fix(matter): add correct guard for ci
SuGlider 3a185e9
fix(matter): using correct ci requirements in ci.json
SuGlider 260d619
fix(matter): using correct ci requirements in header files
SuGlider b495cc3
fix(matter): using correct ci requirements header and examples
SuGlider d3b83d9
fix(typo): typo and commentaries
SuGlider 2fbbca8
fix(typo): typo and commentaries
SuGlider d733d19
fix(typo): typo and commentaries
SuGlider d3f8703
fix(commentary): longer explanation
SuGlider 695df24
feat(matter): api simplification with begin
SuGlider 5960abe
feat(matter): testing flashmode=qio in CI
SuGlider 9e74283
feat(matter): testing flashmode=qio in CI
SuGlider 96672e6
fix(matter): changes CI FQBN
SuGlider 1797133
fix(matte): include all fqbn in ci.json using qio
SuGlider bb43fbf
fix(matter): revert ci and guard changes
SuGlider 9380713
fix(matter): typo and commentaties
SuGlider cb1759b
feat(matter): adds a light toggle switch button
SuGlider 7865619
feat(matter): improved the button control
SuGlider a980226
feat(matter): using switch instead of if() for attibute change
SuGlider 8d6575a
fix(matter): switch/case scope
SuGlider 966ae0d
fix(matter): problems found after pressing reset
SuGlider 9ecb6f3
feat(matter): improve example using preferences
SuGlider a6d1d20
fix(pre-commit): Fix and apply pre-commit hooks
lucasssvaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
libraries/Matter/examples/MatterCommissionTest/MatterCommissionTest.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <sdkconfig.h> | ||
#ifdef CONFIG_ESP_MATTER_ENABLE_DATA_MODEL | ||
#include <Arduino.h> | ||
#include <WiFi.h> | ||
|
||
// Matter Manager | ||
#include <Matter.h> | ||
|
||
// List of Matter Endpoints for this Node | ||
// On/Off Light Endpoint | ||
#include <MatterOnOffLight.h> | ||
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 | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
while (!Serial) { | ||
delay(100); | ||
} | ||
|
||
// We start by connecting to a WiFi network | ||
Serial.print("Connecting to "); | ||
Serial.println(ssid); | ||
// enable IPv6 | ||
WiFi.enableIPv6(true); | ||
// Manually connect to WiFi | ||
WiFi.begin(ssid, password); | ||
// Wait for connection | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
Serial.println("\r\nWiFi connected"); | ||
Serial.println("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
delay(500); | ||
|
||
// Initialize at least one Matter EndPoint | ||
OnOffLight.begin(); | ||
|
||
// Matter begining - Last step, after all EndPoints are initialized | ||
Matter.begin(); | ||
} | ||
|
||
void loop() { | ||
// Check Matter Commissioning state | ||
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 Light Commissioning. | ||
while (!Matter.isDeviceCommissioned()) { | ||
delay(5000); | ||
Serial.println("Matter Fabric not commissioned yet. Waiting for commissioning."); | ||
} | ||
} | ||
Serial.println("Matter Node is commissioned and connected to Wi-Fi."); | ||
Serial.println("====> Decommissioning in 30 seconds. <===="); | ||
delay(30000); | ||
Matter.decommission(); | ||
Serial.println("Matter Node is decommissioned. Commsssioning widget shall start over."); | ||
} | ||
|
||
#else | ||
void setup() {} | ||
void loop() {} | ||
#endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"fqbn_append": "PartitionScheme=huge_app", | ||
"requires": [ | ||
"CONFIG_SOC_WIFI_SUPPORTED=y", | ||
"CONFIG_ESP_MATTER_ENABLE_DATA_MODEL=y" | ||
] | ||
} | ||
|
103 changes: 103 additions & 0 deletions
103
libraries/Matter/examples/MatterComposedLights/MatterComposedLights.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include <sdkconfig.h> | ||
#ifdef CONFIG_ESP_MATTER_ENABLE_DATA_MODEL | ||
#include <Arduino.h> | ||
#include <WiFi.h> | ||
|
||
// Matter Manager | ||
#include <Matter.h> | ||
|
||
// List of Matter Endpoints for this Node | ||
// There will be 3 On/Off Light Endpoints in the same Node | ||
#include <MatterOnOffLight.h> | ||
MatterOnOffLight OnOffLight1; | ||
MatterOnOffLight OnOffLight2; | ||
MatterOnOffLight OnOffLight3; | ||
|
||
// Matter Protocol Endpoint Callback for each Light Accessory | ||
bool setLightOnOff1(bool state) { | ||
Serial.printf("CB-Light1 changed state to: %s\r\n", state ? "ON" : "OFF"); | ||
return true; | ||
} | ||
|
||
bool setLightOnOff2(bool state) { | ||
Serial.printf("CB-Light2 changed state to: %s\r\n", state ? "ON" : "OFF"); | ||
return true; | ||
} | ||
|
||
bool setLightOnOff3(bool state) { | ||
Serial.printf("CB-Light3 changed state to: %s\r\n", state ? "ON" : "OFF"); | ||
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() { | ||
Serial.begin(115200); | ||
while (!Serial) { | ||
delay(100); | ||
} | ||
|
||
// We start by connecting to a WiFi network | ||
Serial.print("Connecting to "); | ||
Serial.println(ssid); | ||
// enable IPv6 | ||
WiFi.enableIPv6(true); | ||
// Manually connect to WiFi | ||
WiFi.begin(ssid, password); | ||
// Wait for connection | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
Serial.println("\r\nWiFi connected"); | ||
Serial.println("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
delay(500); | ||
|
||
// Initialize all 3 Matter EndPoints | ||
OnOffLight1.begin(); | ||
OnOffLight2.begin(); | ||
OnOffLight3.begin(); | ||
OnOffLight1.onChangeOnOff(setLightOnOff1); | ||
OnOffLight2.onChangeOnOff(setLightOnOff2); | ||
OnOffLight3.onChangeOnOff(setLightOnOff3); | ||
|
||
// Matter begining - Last step, after all EndPoints are initialized | ||
Matter.begin(); | ||
} | ||
|
||
void loop() { | ||
// Check Matter Light Commissioning state | ||
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 Light 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."); | ||
} | ||
|
||
//displays the Light state every 3 seconds | ||
Serial.println("======================"); | ||
Serial.printf("Matter Light #1 is %s\r\n", OnOffLight1.getOnOff() ? "ON" : "OFF"); | ||
Serial.printf("Matter Light #2 is %s\r\n", OnOffLight2.getOnOff() ? "ON" : "OFF"); | ||
Serial.printf("Matter Light #3 is %s\r\n", OnOffLight3.getOnOff() ? "ON" : "OFF"); | ||
delay(3000); | ||
} | ||
|
||
#else | ||
void setup() {} | ||
void loop() {} | ||
#endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */ | ||
SuGlider marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"fqbn_append": "PartitionScheme=huge_app", | ||
"requires": [ | ||
"CONFIG_SOC_WIFI_SUPPORTED=y", | ||
"CONFIG_ESP_MATTER_ENABLE_DATA_MODEL=y" | ||
] | ||
} | ||
|
110 changes: 110 additions & 0 deletions
110
libraries/Matter/examples/MatterOnOffLight/MatterOnOffLight.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#include <sdkconfig.h> | ||
#ifdef CONFIG_ESP_MATTER_ENABLE_DATA_MODEL | ||
#include <Arduino.h> | ||
#include <WiFi.h> | ||
|
||
// Matter Manager | ||
#include <Matter.h> | ||
|
||
// List of Matter Endpoints for this Node | ||
// On/Off Light Endpoint | ||
#include <MatterOnOffLight.h> | ||
MatterOnOffLight OnOffLight; | ||
|
||
// set your board LED pin here | ||
#ifdef LED_BUILTIN | ||
const uint8_t ledPin = LED_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 LED pin" | ||
#endif | ||
|
||
// Matter Protocol Endpoint Callback | ||
bool setLightOnOff(bool state) { | ||
Serial.printf("User Callback :: New Light State = %s\r\n", state ? "ON" : "OFF"); | ||
if (state) { | ||
digitalWrite(ledPin, HIGH); | ||
} else { | ||
digitalWrite(ledPin, LOW); | ||
} | ||
// This callback must return the success state to Matter core | ||
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() { | ||
Serial.begin(115200); | ||
while (!Serial) { | ||
delay(100); | ||
} | ||
|
||
// We start by connecting to a WiFi network | ||
Serial.print("Connecting to "); | ||
Serial.println(ssid); | ||
// enable IPv6 | ||
WiFi.enableIPv6(true); | ||
// Manually connect to WiFi | ||
WiFi.begin(ssid, password); | ||
// Wait for connection | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
Serial.println("\r\nWiFi connected"); | ||
Serial.println("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
delay(500); | ||
|
||
// Initialize Matter EndPoint | ||
OnOffLight.begin(true); | ||
OnOffLight.onChangeOnOff(setLightOnOff); | ||
|
||
// Matter begining - Last step, after all EndPoints are initialized | ||
Matter.begin(); | ||
} | ||
|
||
uint32_t lastMillis = millis(); | ||
const uint32_t toggle_interval = 15000; // light will toggle every 15 seconds | ||
void loop() { | ||
// Check Matter Light Commissioning state | ||
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 Light 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."); | ||
} | ||
} | ||
// Initialize the LED (light) GPIO and Matter End Point | ||
pinMode(ledPin, OUTPUT); | ||
Serial.printf("Initial state: %s\r\n", OnOffLight.getOnOff() ? "ON" : "OFF"); | ||
setLightOnOff(OnOffLight.getOnOff()); // configure the Light based on initial state | ||
Serial.println("Matter Node is commissioned and connected to Wi-Fi. Ready for use."); | ||
delay(10000); | ||
} | ||
|
||
//displays the Light state every 3 seconds | ||
Serial.printf("Matter Light is %s\r\n", OnOffLight.getOnOff() ? "ON" : "OFF"); | ||
delay(3000); | ||
if (millis() - lastMillis > toggle_interval) { | ||
Serial.println("Toggling Light!"); | ||
lastMillis = millis(); | ||
OnOffLight.toggle(); // Matter Controller also can see the change | ||
} | ||
} | ||
|
||
#else | ||
void setup() {} | ||
void loop() {} | ||
#endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */ | ||
SuGlider marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"fqbn_append": "PartitionScheme=huge_app", | ||
"requires": [ | ||
"CONFIG_SOC_WIFI_SUPPORTED=y", | ||
"CONFIG_ESP_MATTER_ENABLE_DATA_MODEL=y" | ||
] | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
####################################### | ||
# Syntax Coloring Map For OpenThread | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
Matter KEYWORD1 | ||
MatterOnOffLight KEYWORD1 | ||
MatterEndPoint KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
|
||
begin KEYWORD2 | ||
end KEYWORD2 | ||
start KEYWORD2 | ||
getManualPairingCode KEYWORD2 | ||
getOnboardingQRCodeUrl KEYWORD2 | ||
isDeviceCommissioned KEYWORD2 | ||
isWiFiConnected KEYWORD2 | ||
isThreadConnected KEYWORD2 | ||
isDeviceConnected KEYWORD2 | ||
decommission KEYWORD2 | ||
attributeChangeCB KEYWORD2 | ||
setOnOff KEYWORD2 | ||
getOnOff KEYWORD2 | ||
toggle KEYWORD2 | ||
onChangeOnOff KEYWORD2 | ||
|
||
####################################### | ||
# Constants (LITERAL1) | ||
####################################### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=Matter | ||
version=3.1.0 | ||
author=Rodrigo Garcia | GitHub @SuGlider | ||
maintainer=Rodrigo Garcia <Rodrigo.Garcia@espressif.com> | ||
sentence=Library for supporting Matter environment on ESP32. | ||
paragraph=This library implements Matter accessories using WiFi network. | ||
category=Communication | ||
url=https://github.com/espressif/arduino-esp32/ | ||
architectures=esp32 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.