Skip to content
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

Gives code -2 #242

Open
Max5040309 opened this issue Dec 16, 2023 · 1 comment
Open

Gives code -2 #242

Max5040309 opened this issue Dec 16, 2023 · 1 comment

Comments

@Max5040309
Copy link

I don’t understand why it gives code -2 and doesn’t add the device

Free heap: 11136, HomeKit clients: 0

[ 137509] HomeKit: Got new client: local 192.168.1.17:5556, remote 192.168.1.34:57466
[ 137518] HomeKit: [Client 1073712724] Pair Setup Step 1/3
Free heap: 9552, HomeKit clients: 1
[ 139526] HomeKit: [Client 1073712724] Pair Setup Step 2/3
[ 139537] HomeKit: Call s_mp_exptmod in integer.c, original winsize 6
[ 149064] HomeKit: Call s_mp_exptmod in integer.c, original winsize 5
!!! [ 149081] HomeKit: [Client 1073712724] Failed to compute SRP shared secret (code -2)
Free heap: 8880, HomeKit clients: 1
[ 149127] HomeKit: [Client 1073712724] Pair Setup Step 1/3
[ 149156] HomeKit: [Client 1073712724] Disconnected!
[ 149161] HomeKit: [Client 1073712724] Closing client connection
[ 149167] HomeKit: Free saved_preinit_pairing_context
[ 149172] HomeKit: [Client 0] Clear the pairing context
[ 149187] HomeKit: Preiniting pairing context
[ 149192] HomeKit: Using user-specified password: 111-11-111
[ 149212] HomeKit: Call s_mp_exptmod in integer.c, original winsize 6
[ 155760] HomeKit: Call s_mp_exptmod in integer.c, original winsize 5
[ 159105] HomeKit: Preinit pairing context success
Free heap: 10616, HomeKit clients: 0

@Max5040309
Copy link
Author

#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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant