ESP32 Matter Arduino 未恢复会话
#include <Matter.h> #include <WiFi.h>
// WiFi credentials const char *ssid = "ssid "; const char *password = "password ";
MatterColorLight ColorLight;
// LED strip configuration #define LEFT_PIN 12 #define RIGHT_PIN 13 #define NUM_LEDS 60 CRGB left[NUM_LEDS]; CRGB right[NUM_LEDS];
TaskHandle_t matterTask;
// Task state and target color bool state = true; espHsvColor_t colour = { 0, 0, 0 }; espHsvColor_t target = { 140, 254, 127 };
void setup() { // Initialize serial port for debugging Serial.begin(115200);
// Initialize LED strips FastLED.addLeds<WS2812, LEFT_PIN, GRB>(left, NUM_LEDS).setRgbw(RgbwDefault()); FastLED.addLeds<WS2812, RIGHT_PIN, GRB>(right, NUM_LEDS).setRgbw(RgbwDefault());
// Set all LEDs to black set_all(CRGB::Black);
// Connect to WiFi WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { // Wait 500ms and blink yellow LED delay(500); centre_wipe(CRGB::Yellow); delay(500); centre_wipe(CRGB::Black); }
// Initialize MatterColorLight accessory ColorLight.begin(state, target);
// Set callback function for accessory state change ColorLight.onChange(update);
// Create Matter task and pin it to core 0 xTaskCreatePinnedToCore( matter, // Function to implement the task "matterTask", // Name of the task 8192, // Stack size in words (causes stack overflow (DUH!!!!) if too low NULL, // Task input parameter 0, // Priority of the task, 0 is lowest &matterTask, // Task handle 0); // Core where the task should run, code runs on core 1 by default }
void matter(void *parameter) { // Initialize Matter Matter.begin();
// Wait 500ms before continuing vTaskDelay(500);
// Check if the device is already commissioned if (Matter.isDeviceCommissioned()) { // Wait until the device is connected while (!Matter.isDeviceConnected()) { vTaskDelay(500); centre_wipe(CRGB::Orange); vTaskDelay(500); centre_wipe(CRGB::Black); }
// Configure the light based on the initial state and colour
ColorLight.updateAccessory();
}
// Loop forever for (;;) { // Wait 10ms before continuing vTaskDelay(10);
// Check if the device is not commissioned yet
if (!Matter.isDeviceCommissioned()) {
// Print message to serial port
Serial.println("");
Serial.println("Matter Node is not commissioned yet.");
Serial.println("Initiate the
…
内容来源: espressif/arduino-esp32