You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using namespace chip;
using namespace chip::app::Clusters;
using namespace esp_matter;
using namespace esp_matter::endpoint;
// Пины для сервоприводов
const int SERVO_PIN_1 = 12;
const int SERVO_PIN_2 = 13;
// Кастомный кластер и атрибуты для управления приводом окна
const uint32_t CUSTOM_WINDOW_COVERING_CLUSTER_ID = 0x1001;
const uint32_t CURRENT_POSITION_ATTRIBUTE_ID = 0x0001;
const uint32_t TARGET_POSITION_ATTRIBUTE_ID = 0x0002;
// Идентификатор конечной точки и атрибуты
uint16_t window_endpoint_id = 0;
attribute_t *current_position_attribute;
attribute_t *target_position_attribute;
// Текущее положение окна
uint16_t current_position = 0;
// Объекты для управления сервоприводами
Servo servo1;
Servo servo2;
// WiFi credentials (replace with your actual credentials)
// Callback функция для событий устройства
static void on_device_event(const ChipDeviceEvent *event, intptr_t arg) {
Serial.print("Device event: ");
Serial.println(event->Type);
}
if (type == attribute::PRE_UPDATE && endpoint_id == window_endpoint_id &&
cluster_id == CUSTOM_WINDOW_COVERING_CLUSTER_ID && attribute_id == TARGET_POSITION_ATTRIBUTE_ID) {
// Получаем целевое положение и перемещаем окно
uint16_t target_position = val->val.u16;
Serial.printf("Target position received: %d\n", target_position);
move_window_to_position(target_position);
}
return ESP_OK;
}
// Функция для перемещения окна в целевое положение
void move_window_to_position(uint16_t target_position) {
// Ограничиваем значение целевого положения от 0 до 100
target_position = std::max(0, std::min(100, (int)target_position));
// Преобразуем положение в угол для сервопривода
uint16_t target_angle = static_cast<uint16_t>(map(target_position, 0, 100, 0, 180));
// Перемещаем окно в целевое положение
Serial.printf("Moving window to position: %d (angle: %d)\n", target_position, target_angle);
if (target_position > current_position) {
for (int i = current_position; i <= target_position; i++) {
servo1.write(map(i, 0, 100, 0, 180));
delay(20);
Serial.printf("Moving servo1 to angle: %d\n", map(i, 0, 100, 0, 180));
}
} else if (target_position < current_position) {
for (int i = current_position; i >= target_position; i--) {
servo2.write(map(i, 0, 100, 0, 180));
delay(20);
Serial.printf("Moving servo2 to angle: %d\n", map(i, 0, 100, 0, 180));
}
}
// Обновляем текущее положение
current_position = target_position;
// Обновляем атрибут текущего положения
esp_matter_attr_val_t position_val = esp_matter_uint16(current_position);
attribute::update(window_endpoint_id, CUSTOM_WINDOW_COVERING_CLUSTER_ID, CURRENT_POSITION_ATTRIBUTE_ID, &position_val);
Serial.printf("Current position updated to: %d\n", current_position);
Всем привет ! Когда работал над проектом, столкнулся с такой проблемой, код компилируется, но не выводит QR-COD для подключения устройства, что может быть не так?
The text was updated successfully, but these errors were encountered:
#include "Matter.h"
#include <app/server/OnboardingCodesUtil.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <esp_matter.h>
#include <esp_matter_core.h>
#include <esp_matter_cluster.h>
#include <esp_matter_endpoint.h>
#include <ESP32Servo.h>
#include <nvs_flash.h> // Добавлено для инициализации NVS
#include <WiFi.h>
using namespace chip;
using namespace chip::app::Clusters;
using namespace esp_matter;
using namespace esp_matter::endpoint;
// Пины для сервоприводов
const int SERVO_PIN_1 = 12;
const int SERVO_PIN_2 = 13;
// Кастомный кластер и атрибуты для управления приводом окна
const uint32_t CUSTOM_WINDOW_COVERING_CLUSTER_ID = 0x1001;
const uint32_t CURRENT_POSITION_ATTRIBUTE_ID = 0x0001;
const uint32_t TARGET_POSITION_ATTRIBUTE_ID = 0x0002;
// Идентификатор конечной точки и атрибуты
uint16_t window_endpoint_id = 0;
attribute_t *current_position_attribute;
attribute_t *target_position_attribute;
// Текущее положение окна
uint16_t current_position = 0;
// Объекты для управления сервоприводами
Servo servo1;
Servo servo2;
// WiFi credentials (replace with your actual credentials)
// Callback функция для событий устройства
static void on_device_event(const ChipDeviceEvent *event, intptr_t arg) {
Serial.print("Device event: ");
Serial.println(event->Type);
}
// Обработчик обновления атрибутов
static esp_err_t on_attribute_update(attribute::callback_type_t type, uint16_t endpoint_id, uint32_t cluster_id,
uint32_t attribute_id, esp_matter_attr_val_t *val, void *priv_data) {
Serial.printf("Attribute update: type=%d, endpoint_id=%d, cluster_id=0x%x, attribute_id=0x%x\n",
type, endpoint_id, cluster_id, attribute_id);
}
// Функция для перемещения окна в целевое положение
void move_window_to_position(uint16_t target_position) {
// Ограничиваем значение целевого положения от 0 до 100
target_position = std::max(0, std::min(100, (int)target_position));
}
// Создание кастомного кластера для управления приводом окна
cluster_t *create_custom_window_covering_cluster(endpoint_t *endpoint) {
cluster_t *cluster = cluster::create(endpoint, CUSTOM_WINDOW_COVERING_CLUSTER_ID, CLUSTER_FLAG_SERVER);
current_position_attribute = attribute::create(cluster, CURRENT_POSITION_ATTRIBUTE_ID, ATTRIBUTE_FLAG_NONE, esp_matter_uint16(0));
target_position_attribute = attribute::create(cluster, TARGET_POSITION_ATTRIBUTE_ID, ATTRIBUTE_FLAG_WRITABLE, esp_matter_uint16(0));
return cluster;
}
void setup() {
Serial.begin(115200);
}
void loop() {
// Основной цикл пуст
}
Всем привет ! Когда работал над проектом, столкнулся с такой проблемой, код компилируется, но не выводит QR-COD для подключения устройства, что может быть не так?
The text was updated successfully, but these errors were encountered: