Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 962ab3a

Browse filesBrowse files
authored
Adds a Minimum Code Matter Example (#10639)
* feat(matter): add a new example for a minimum matter device ---------
1 parent 6bc3ce6 commit 962ab3a
Copy full SHA for 962ab3a

File tree

2 files changed

+88
-0
lines changed
Filter options

2 files changed

+88
-0
lines changed
+81Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/*
16+
* This example is the smallest code that will create a Matter Device which can be
17+
* commissioned and controlled from a Matter Environment APP.
18+
* It controls a GPIO that could be attached to a LED for visualization.
19+
* Additionally the ESP32 will send debug messages indicating the Matter activity.
20+
* Turning DEBUG Level ON may be useful to following Matter Accessory and Controller messages.
21+
*/
22+
23+
// Matter Manager
24+
#include <Matter.h>
25+
#include <WiFi.h>
26+
27+
// List of Matter Endpoints for this Node
28+
// Single On/Off Light Endpoint - at least one per node
29+
MatterOnOffLight OnOffLight;
30+
31+
// Light GPIO that can be controlled by Matter APP
32+
#ifdef LED_BUILTIN
33+
const uint8_t ledPin = LED_BUILTIN;
34+
#else
35+
const uint8_t ledPin = 2; // Set your pin here if your board has not defined LED_BUILTIN
36+
#endif
37+
38+
// Matter Protocol Endpoint (On/OFF Light) Callback
39+
bool matterCB(bool state) {
40+
digitalWrite(ledPin, state ? HIGH : LOW);
41+
// This callback must return the success state to Matter core
42+
return true;
43+
}
44+
45+
// WiFi is manually set and started
46+
const char *ssid = "your-ssid"; // Change this to your WiFi SSID
47+
const char *password = "your-password"; // Change this to your WiFi password
48+
49+
void setup() {
50+
// Initialize the LED GPIO
51+
pinMode(ledPin, OUTPUT);
52+
53+
WiFi.enableIPv6(true);
54+
// Manually connect to WiFi
55+
WiFi.begin(ssid, password);
56+
// Wait for connection
57+
while (WiFi.status() != WL_CONNECTED) {
58+
delay(500);
59+
}
60+
61+
// Initialize at least one Matter EndPoint
62+
OnOffLight.begin();
63+
64+
// Associate a callback to the Matter Controller
65+
OnOffLight.onChange(matterCB);
66+
67+
// Matter beginning - Last step, after all EndPoints are initialized
68+
Matter.begin();
69+
70+
if (!Matter.isDeviceCommissioned()) {
71+
log_i("Matter Node is not commissioned yet.");
72+
log_i("Initiate the device discovery in your Matter environment.");
73+
log_i("Commission it to your Matter hub with the manual pairing code or QR code");
74+
log_i("Manual pairing code: %s\r\n", Matter.getManualPairingCode().c_str());
75+
log_i("QR code URL: %s\r\n", Matter.getOnboardingQRCodeUrl().c_str());
76+
}
77+
}
78+
79+
void loop() {
80+
delay(500);
81+
}
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"fqbn_append": "PartitionScheme=huge_app",
3+
"requires": [
4+
"CONFIG_SOC_WIFI_SUPPORTED=y",
5+
"CONFIG_ESP_MATTER_ENABLE_DATA_MODEL=y"
6+
]
7+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.