Comments (1)
#include <homekit/homekit.h>
#include <homekit/characteristics.h>
void my_accessory_identify(homekit_value_t _value) {
printf("accessory identify\n");
}
homekit_characteristic_t cha_switch_on = HOMEKIT_CHARACTERISTIC_(ON, false);
//homekit_characteristic_t cha_name = HOMEKIT_CHARACTERISTIC_(NAME, "Switch");
homekit_characteristic_t cha_bright = HOMEKIT_CHARACTERISTIC_(BRIGHTNESS, 50);
homekit_accessory_t accessories[] = {
HOMEKIT_ACCESSORY(.id = 1, .category = homekit_accessory_category_other, .services = (homekit_service_t[]) {
HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics = (homekit_characteristic_t*[]) {
HOMEKIT_CHARACTERISTIC(NAME, "Universal Controller"),
HOMEKIT_CHARACTERISTIC(MANUFACTURER, "smart.ledstairs.com.ua"),
HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "smart"),
HOMEKIT_CHARACTERISTIC(MODEL, "Universal Controller"),
HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "1.0"),
HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify),
NULL
}),
NULL
}),
//===============================================================================
HOMEKIT_ACCESSORY(.id = 2, .category = homekit_accessory_category_switch, .services = (homekit_service_t*[]) {
HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics = (homekit_characteristic_t*[]) {
HOMEKIT_CHARACTERISTIC(NAME, "Switch"),
HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify),
NULL
}),
HOMEKIT_SERVICE(SWITCH, .primary = true, .characteristics = (homekit_characteristic_t*[]) {
&cha_switch_on,
//&cha_name,
NULL
}),
NULL
}),
//===============================================================================
HOMEKIT_ACCESSORY(.id = 3, .category = homekit_accessory_category_lightbulb, .services = (homekit_service_t*[]) {
HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics = (homekit_characteristic_t*[]) {
HOMEKIT_CHARACTERISTIC(NAME, "Brightness"),
HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify),
NULL
}),
// Обратите внимание, что для использования нескольких сервисов LIGHTBULB вам нужно создать отдельный массив characteristics
HOMEKIT_SERVICE(LIGHTBULB, .primary = true, .characteristics = (homekit_characteristic_t*[]) {
HOMEKIT_CHARACTERISTIC(NAME, "Brightness of Steps"),
&cha_bright,
NULL
}),
NULL
}),
//===============================================================================
//===============================================================================
//===============================================================================
//===============================================================================
//===============================================================================
//===============================================================================
//===============================================================================
NULL
};
homekit_server_config_t accessory_config = {
.accessories = accessories,
.password = "111-11-111"
};
extern "C" homekit_server_config_t accessory_config;
extern "C" homekit_characteristic_t cha_switch_on;
extern "C" homekit_characteristic_t cha_bright;
static uint32_t next_heap_millis = 0;
void my_homekit_setup() {
cha_bright.setter = set_bright;
cha_switch_on.setter = cha_switch_on_setter;
arduino_homekit_setup(&accessory_config);
}
void my_homekit_loop() {
arduino_homekit_loop();
const uint32_t t = millis();
if (t > next_heap_millis) {
// show heap info every 5 seconds
next_heap_millis = t + 5 * 1000;
LOG_D("Free heap: %d, HomeKit clients: %d",
ESP.getFreeHeap(), arduino_homekit_connected_clients_count());
}
}
//===============================================================================
void cha_switch_on_setter(const homekit_value_t value) {
bool on = value.bool_value;
cha_switch_on.value.bool_value = on; // sync the value
LOG_D("Switch: %s", on ? "ON" : "OFF");
digitalWrite(vikl, on ? HIGH : LOW);
if (on) {
vikluchatel(); // Вызываем функцию при включении
} else {
vikluchatel();
}
homekit_characteristic_notify(&cha_switch_on, cha_switch_on.value);
}
//===============================================================================
void set_bright(const homekit_value_t v) {
int brightness_percentage = v.int_value; // Принимаем значение яркости в процентах
mainColor = constrain(brightness_percentage * 40, 0, 4000); // Преобразуем проценты в абсолютный цвет и ограничиваем диапазон
cha_bright.value.int_value = brightness_percentage; // Обновляем значение яркости в переменной homekit
saveConfig();
Serial.println(mainColor);
for (int k = 0; k <= kol_st - 1; k++) {
led(k, mainColor); // Проверка всех ступенек
}
delay(2000);
for (int k = 0; k <= kol_st - 1; k++) {
led(k, 0); // Тушим
}
homekit_characteristic_notify(&cha_bright, cha_bright.value); // Отправляем новую яркость в HomeKit
}
from arduino-homekit-esp8266.
Related Issues (20)
- Is there a relay wiring diagram for the ESP-01? HOT 1
- Issue with EEPROM definitions? HOT 2
- EEPROM on ESP8266 will be restore after arduino_homekit_setup HOT 3
- LDR Light Sensor HOT 4
- Sensors looses Connection HOT 9
- HAPStatus call anyone
- New architecture HOT 3
- Compatibility issue with ios 16.6 HOT 5
- Use Homekit-ESP8266 to control a stepper driver. HOT 3
- Loosing accessories with iOS 16.7 and powerloss HOT 12
- Accesorry not showing up in the home app HOT 2
- Lock Management Auto Security Timeout
- hiding accessories HOT 6
- Disconnect on pair setup step 3/3 HOT 6
- Can't find device in HomeApp
- esp8266 [ Error compiling for board NodeMCU 1.0 (ESP-12E Module).] issue
- Implement temperature, humidity and 2 switches and oled 0.96 to monitor the sensors. HOT 5
- Accessories not respond
- Sensor Pin
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino-homekit-esp8266.