maximkulkin / esp-homekit-demo

Demo of Apple HomeKit accessory server library
MIT License
809 stars 233 forks source link

Unable to complete pairing #227

Closed kunjal83 closed 4 years ago

kunjal83 commented 5 years ago

Hi, While trying to pair the device, program all of a sudden closes the connection after "Get Accessories".

Can someone please help on how do i troubleshoot this?

Screenshot 2019-06-16 at 12 05 50 PM

Thanks, Kunjal

toshibochan commented 4 years ago

@kunjal83 I having this same problem. did you fix this problem?

kunjal83 commented 4 years ago

@toshibochan, that was happening due to Pin2 going low. Was some hardware related issue. Please do check the voltage at the pins.

toshibochan commented 4 years ago

@kunjal83 what you did to fix?

toshibochan commented 4 years ago

pin 2 mean gpio2?

kunjal83 commented 4 years ago

Yes sorry... Yes i meant GPIO2. Ensure it is high always

Cheers, Kunjal Cell: +91 9987274445

On Sun, 24 Nov 2019 at 14:32, toshibochan notifications@github.com wrote:

pin 2 mean gpio2?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/maximkulkin/esp-homekit-demo/issues/227?email_source=notifications&email_token=AG4N55QHIQKEYRQC3ZNJ2TLQVI7K7A5CNFSM4HYQRFT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFAGYHI#issuecomment-557870109, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG4N55T72JOCYMV7L7EGKWDQVI7K7ANCNFSM4HYQRFTQ .

toshibochan commented 4 years ago

high is 0 or 1?

toshibochan commented 4 years ago

include

include

include <espressif/esp_wifi.h>

include <espressif/esp_sta.h>

include <esp/uart.h>

include

include

include

include

include <homekit/homekit.h>

include <homekit/characteristics.h>

include "wifi.h"

include "WS2812FX/WS2812FX.h"

define LED_RGB_SCALE 255 // this is the scaling factor used for color conversion

define LED_COUNT 50 // this is the number of WS2812B leds on the strip

define LED_INBUILT_GPIO 2 // this is the onboard LED used to show on/off only

// Global variables float led_hue = 0; // hue is scaled 0 to 360 float led_saturation = 100; // saturation is scaled 0 to 100 float led_brightness = 33; // brightness is scaled 0 to 100 bool led_on = false; // on is boolean on or off bool led_on_value = (bool)0; // this is the value to write to GPIO for led on (0 = GPIO low)

float fx_hue = 64; // hue is scaled 0 to 360 float fx_saturation = 50; // saturation is scaled 0 to 100 float fx_brightness = 50; // brightness is scaled 0 to 100 bool fx_on = true;

//http://blog.saikoled.com/post/44677718712/how-to-convert-from-hsi-to-rgb-white static void hsi2rgb(float h, float s, float i, ws2812_pixel_t* rgb) { int r, g, b;

while (h < 0) { h += 360.0F; };     // cycle h around to 0-360 degrees
while (h >= 360) { h -= 360.0F; };
h = 3.14159F*h / 180.0F;            // convert to radians.
s /= 100.0F;                        // from percentage to ratio
i /= 100.0F;                        // from percentage to ratio
s = s > 0 ? (s < 1 ? s : 1) : 0;    // clamp s and i to interval [0,1]
i = i > 0 ? (i < 1 ? i : 1) : 0;    // clamp s and i to interval [0,1]
i = i * sqrt(i);                    // shape intensity to have finer granularity near 0

if (h < 2.09439) {
    r = LED_RGB_SCALE * i / 3 * (1 + s * cos(h) / cos(1.047196667 - h));
    g = LED_RGB_SCALE * i / 3 * (1 + s * (1 - cos(h) / cos(1.047196667 - h)));
    b = LED_RGB_SCALE * i / 3 * (1 - s);
}
else if (h < 4.188787) {
    h = h - 2.09439;
    g = LED_RGB_SCALE * i / 3 * (1 + s * cos(h) / cos(1.047196667 - h));
    b = LED_RGB_SCALE * i / 3 * (1 + s * (1 - cos(h) / cos(1.047196667 - h)));
    r = LED_RGB_SCALE * i / 3 * (1 - s);
}
else {
    h = h - 4.188787;
    b = LED_RGB_SCALE * i / 3 * (1 + s * cos(h) / cos(1.047196667 - h));
    r = LED_RGB_SCALE * i / 3 * (1 + s * (1 - cos(h) / cos(1.047196667 - h)));
    g = LED_RGB_SCALE * i / 3 * (1 - s);
}

rgb->red = (uint8_t) r;
rgb->green = (uint8_t) g;
rgb->blue = (uint8_t) b;
rgb->white = (uint8_t) 0;           // white channel is not used

}

static void wifi_init() { struct sdk_station_config wifi_config = { .ssid = WIFI_SSID, .password = WIFI_PASSWORD, };

sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_set_config(&wifi_config);
sdk_wifi_station_connect();

}

void led_identify_task(void *_args) { // initialise the onboard led as a secondary indicator (handy for testing) gpio_enable(LED_INBUILT_GPIO, GPIO_OUTPUT);

for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
        gpio_write(LED_INBUILT_GPIO, (int)led_on_value);
        vTaskDelay(100 / portTICK_PERIOD_MS);
        gpio_write(LED_INBUILT_GPIO, 1 - (int)led_on_value);
        vTaskDelay(100 / portTICK_PERIOD_MS);
    }
    vTaskDelay(250 / portTICK_PERIOD_MS);
}

gpio_write(LED_INBUILT_GPIO, 1 - (int)led_on_value);

vTaskDelete(NULL);

}

void led_identify(homekit_value_t _value) { // printf("LED identify\n"); xTaskCreate(led_identify_task, "LED identify", 128, NULL, 2, NULL); }

homekit_value_t led_on_get() { return HOMEKIT_BOOL(led_on); }

void led_on_set(homekit_value_t value) { if (value.format != homekit_format_bool) { // printf("Invalid on-value format: %d\n", value.format); return; }

led_on = value.bool_value;

if (led_on) {
    WS2812FX_setBrightness((uint8_t)floor(led_brightness*2.55));

} else {
    WS2812FX_setBrightness(0);
}

}

homekit_value_t led_brightness_get() { return HOMEKIT_INT(led_brightness); }

void led_brightness_set(homekit_value_t value) { if (value.format != homekit_format_int) { // printf("Invalid brightness-value format: %d\n", value.format); return; } led_brightness = value.int_value;

WS2812FX_setBrightness((uint8_t)floor(led_brightness*2.55));

}

homekit_value_t led_hue_get() { return HOMEKIT_FLOAT(led_hue); }

void led_hue_set(homekit_value_t value) { if (value.format != homekit_format_float) { // printf("Invalid hue-value format: %d\n", value.format); return; } led_hue = value.float_value;

ws2812_pixel_t rgb = { { 0, 0, 0, 0 } };
hsi2rgb(led_hue, led_saturation, 100, &rgb);

WS2812FX_setColor(rgb.red, rgb.green, rgb.blue);

}

homekit_value_t led_saturation_get() { return HOMEKIT_FLOAT(led_saturation); }

void led_saturation_set(homekit_value_t value) { if (value.format != homekit_format_float) { // printf("Invalid sat-value format: %d\n", value.format); return; } led_saturation = value.float_value;

ws2812_pixel_t rgb = { { 0, 0, 0, 0 } };
hsi2rgb(led_hue, led_saturation, 100, &rgb);

WS2812FX_setColor(rgb.red, rgb.green, rgb.blue);

}

homekit_value_t fx_on_get() { return HOMEKIT_BOOL(fx_on); }

void fx_on_set(homekit_value_t value) { if (value.format != homekit_format_bool) { // printf("Invalid on-value format: %d\n", value.format); return; } fx_on = value.bool_value;

if (fx_on) {
    WS2812FX_setMode360(fx_hue);
} else {
    WS2812FX_setMode360(0);
}

}

homekit_value_t fx_brightness_get() { return HOMEKIT_INT(fx_brightness); }

void fx_brightness_set(homekit_value_t value) { if (value.format != homekit_format_int) { // printf("Invalid brightness-value format: %d\n", value.format); return; } fx_brightness = value.int_value;

if (fx_brightness > 50) {
    uint8_t fx_speed = fx_brightness - 50;
    WS2812FX_setSpeed(fx_speed*5.1);
    WS2812FX_setInverted(true);
} else {
    uint8_t fx_speed = abs(fx_brightness - 51);
    WS2812FX_setSpeed(fx_speed*5.1);
    WS2812FX_setInverted(false);
}

}

homekit_value_t fx_hue_get() { return HOMEKIT_FLOAT(fx_hue); }

void fx_hue_set(homekit_value_t value) { if (value.format != homekit_format_float) { // printf("Invalid hue-value format: %d\n", value.format); return; } fx_hue = value.float_value;

WS2812FX_setMode360(fx_hue);

}

homekit_value_t fx_saturation_get() { return HOMEKIT_FLOAT(fx_saturation); }

void fx_saturation_set(homekit_value_t value) { if (value.format != homekit_format_float) { // printf("Invalid hue-value format: %d\n", value.format); return; } fx_saturation = value.float_value;
}

homekit_characteristic_t name = HOMEKITCHARACTERISTIC(NAME, "Chihiro");

homekit_accessory_t accessories[] = { HOMEKIT_ACCESSORY(.id = 1, .category = homekit_accessory_category_lightbulb, .services = (homekit_service_t[]) { HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics = (homekit_characteristic_t[]) { &name, HOMEKIT_CHARACTERISTIC(MANUFACTURER, "Generic"), HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "137A2BABF19D"), HOMEKIT_CHARACTERISTIC(MODEL, "LEDStripFX"), HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "0.1"), HOMEKIT_CHARACTERISTIC(IDENTIFY, led_identify), NULL }), HOMEKIT_SERVICE(LIGHTBULB, .primary = true, .characteristics = (homekit_characteristic_t[]) { HOMEKIT_CHARACTERISTIC(NAME, "Chihiro"), HOMEKIT_CHARACTERISTIC( ON, true, .getter = led_on_get, .setter = led_on_set ), HOMEKIT_CHARACTERISTIC( BRIGHTNESS, 100, .getter = led_brightness_get, .setter = led_brightness_set ), HOMEKIT_CHARACTERISTIC( HUE, 0, .getter = led_hue_get, .setter = led_hue_set ), HOMEKIT_CHARACTERISTIC( SATURATION, 0, .getter = led_saturation_get, .setter = led_saturation_set ), NULL }), HOMEKIT_SERVICE(LIGHTBULB, .primary = true, .characteristics = (homekit_characteristic_t*[]) { HOMEKIT_CHARACTERISTIC(NAME, "Chihiro FX"), HOMEKIT_CHARACTERISTIC( ON, true, .getter = fx_on_get, .setter = fx_on_set ), HOMEKIT_CHARACTERISTIC( BRIGHTNESS, 100, .getter = fx_brightness_get, .setter = fx_brightness_set ), HOMEKIT_CHARACTERISTIC( HUE, 0, .getter = fx_hue_get, .setter = fx_hue_set ), HOMEKIT_CHARACTERISTIC( SATURATION, 0, .getter = fx_saturation_get, .setter = fx_saturation_set ), NULL }), NULL }), NULL };

homekit_server_config_t config = { .accessories = accessories, .password = "111-11-111" };

void user_init(void) { // uart_set_baud(0, 115200);

// This example shows how to use same firmware for multiple similar accessories
// without name conflicts. It uses the last 3 bytes of accessory's MAC address as
// accessory name suffix.
uint8_t macaddr[6];
sdk_wifi_get_macaddr(STATION_IF, macaddr);
int name_len = snprintf(NULL, 0, "Chihiro-%02X%02X%02X", macaddr[3], macaddr[4], macaddr[5]);
char *name_value = malloc(name_len + 1);
snprintf(name_value, name_len + 1, "Chihiro-%02X%02X%02X", macaddr[3], macaddr[4], macaddr[5]);
name.value = HOMEKIT_STRING(name_value);

wifi_init();
WS2812FX_init(LED_COUNT);
homekit_server_init(&config);

led_identify(HOMEKIT_INT(led_brightness));

}

toshibochan commented 4 years ago

I can see this is set to 1

for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { gpio_write(LED_INBUILT_GPIO, (int)led_on_value); vTaskDelay(100 / portTICK_PERIOD_MS); gpio_write(LED_INBUILT_GPIO, 1 - (int)led_on_value); vTaskDelay(100 / portTICK_PERIOD_MS); } vTaskDelay(250 / portTICK_PERIOD_MS); }

gpio_write(LED_INBUILT_GPIO, 1 - (int)led_on_value);

vTaskDelete(NULL);

toshibochan commented 4 years ago

im trying to pair Wemos D1 mini but >>> HomeKit: [Client 5] Closing client connection

HomeKit: Got new client connection: 4 HomeKit: [Client 4] Pair Setup Step 1/3 HomeKit: Got new client connection: 5 HomeKit: [Client 4] Closing client connection HomeKit: [Client 5] Pair Setup Step 1/3 HomeKit: [Client 5] Closing client connection

maccoylton commented 4 years ago

Can you pull the latest version of esp-homekit, build and test again, it will give some extra info to potentially help diagnose

d4rkmen commented 4 years ago

Here is detailed log of pairing process on ESP8266. Connections were closed a few times before it become paired

>>> HomeKit: Starting server
>>> HomeKit: Using existing accessory ID: E8:EC:BC:93:02:CF
>>> HomeKit: Configuring mDNS
>>> homekit_run_server: Staring HTTP server
>>> HomeKit: Got new client connection: 1 from 192.168.1.33
>>> homekit_client_process: [Client 1] Got 131 incomming data
>>> homekit_server_on_pair_setup: Pair Setup
>>> homekit_server_on_pair_setup: Free heap: 48900
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 0 value (1 bytes): \x00
>>> tlv_debug: Type 6 value (1 bytes): \x01
>>> HomeKit: [Client 1] Pair Setup Step 1/3
>>> homekit_server_on_pair_setup: Free heap: 48816
>>> crypto_srp_new: Initializing SRP
>>> homekit_server_on_pair_setup: [Client 1] Initializing crypto
>>> homekit_server_on_pair_setup: Free heap: 48144
>>> homekit_server_on_pair_setup: [Client 1] Using user-specified password: 111-11-111
>>> crypto_srp_init: Generating salt
>>> crypto_srp_init: Setting SRP username
>>> crypto_srp_init: Setting SRP params
>>> crypto_srp_init: Setting SRP password
>>> crypto_srp_init: Getting SRP verifier
>>> crypto_srp_init: Setting SRP verifier
>>> crypto_srp_get_public_key: Calculating public key
>>> send_tlv_response: [Client 1] Sending TLV response
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 3 value (384 bytes): \xF3>\\\x0C\x06%\xA7\xB0\xBC>\xBB+\x83\xCAXE\xF5\xEC\x9AZ\x1F\xD6"\x19\xEF\x0AL\x1F\xE5=<+mJ3&\x
11\x08\xEBG\x07\xBC\x1A"!\x9C\xB7\x89u\x95\xBCp\x03\xC0\xEA\xDCC\x92\x985\x0D5/\x9A\x9EDg\xDE\x1F\xBD\xCA7\xC3\x17\x03RW\xD7\xBF\xAA\xD6\
xEB\xE53\x0C\xA1\xC5k\xD3\xA2\x98N\xB0\xDE\x12\xCD\xC7?\x17\x1E\x823V\xDB\xDE\xC6\xE2\x9E\xBC\x07\x99\x84\xFC\xB27W\x1A|\xFD\xE0\xB7\xBB\
xC1\x1A\xD1\xDF{AN\x1B\x94\xCB\xCA\x1B`\xAA\xA2\xCEU!\xF7~\x9C\xB7\xCF\xE2C\x86\xA1\x11=\xC8-,\xA7\xE9>\x05\x90\xE2\x04;xv\x82E\xFA}[\xEE
\x84fc\x9A\x97\xB9\x8C\xC9\x97\xFF\xBC\xDB\x8D\xFB\xCFB\x09c\xE2\x95\x84\\@!~v\x1C\xE9\xED\x9C\xE3b\x15y"\x00\x02' \xF28\xEB\x93\x0D\x1C\
xD7\xE9\x06\xC4'\x06\x03\x9D\x12\x9A\xDE\xCE1\xF6Q-\x91\xF5\xDD\xB8q\xEDUcL\xB3Z\xF9\xB5\x1C\xE16\xA1P*x\x86\x8C\xB9\xF2\xFE\x8E\xCA\xD7*
6\x1D\x01]\xCF\xCFR\xD48`HaQG7\x91Q\xF7\xB5\xAE5D\xDE\xA3sQ\xBE\xF8\xCE},u\x13\xC0HjbC\xE6\xEFS\xF7\xBCL\xB62\xFB\x81\\{{R\xCF\xC9\xEE\xE
5\xD5jU\x9D\xD0\x03\xE1?\xA5\xFA\x83\xC8\xDF\xEFN:\xFB{\xECv\xCE\x91\x07\x9C\x02\xFE.>\x8F!K\x8E\x82\xDBN\xEF\xFF\x0F1e\x96\xC7\xCC\x0B\x
1BB+g\xF0\xF7\x93\x8F\xF1(Yz\xF3\xF8R\xCC\xD8\xC91\xE2\xE8\xF3\x96\xF9
>>> tlv_debug: Type 2 value (16 bytes): \x05\x1D\x9D5\x83y\xD4l*4xa\x9B\xE1\xB2\xD4
>>> tlv_debug: Type 6 value (1 bytes): \x02
>>> client_send: [Client 1] Sending payload: HTTP/1.1 200 OK\x0D\x0AContent-Type: application/pairing+tlv8\x0D\x0AContent-Length: 409\x0D
\x0AConnection: keep-alive\x0D\x0A\x0D\x0A\x03\xFF\xF3>\\\x0C\x06%\xA7\xB0\xBC>\xBB+\x83\xCAXE\xF5\xEC\x9AZ\x1F\xD6"\x19\xEF\x0AL\x1F\xE5
=<+mJ3&\x11\x08\xEBG\x07\xBC\x1A"!\x9C\xB7\x89u\x95\xBCp\x03\xC0\xEA\xDCC\x92\x985\x0D5/\x9A\x9EDg\xDE\x1F\xBD\xCA7\xC3\x17\x03RW\xD7\xBF
\xAA\xD6\xEB\xE53\x0C\xA1\xC5k\xD3\xA2\x98N\xB0\xDE\x12\xCD\xC7?\x17\x1E\x823V\xDB\xDE\xC6\xE2\x9E\xBC\x07\x99\x84\xFC\xB27W\x1A|\xFD\xE0
\xB7\xBB\xC1\x1A\xD1\xDF{AN\x1B\x94\xCB\xCA\x1B`\xAA\xA2\xCEU!\xF7~\x9C\xB7\xCF\xE2C\x86\xA1\x11=\xC8-,\xA7\xE9>\x05\x90\xE2\x04;xv\x82E\
xFA}[\xEE\x84fc\x9A\x97\xB9\x8C\xC9\x97\xFF\xBC\xDB\x8D\xFB\xCFB\x09c\xE2\x95\x84\\@!~v\x1C\xE9\xED\x9C\xE3b\x15y"\x00\x02' \xF28\xEB\x93
\x0D\x1C\xD7\xE9\x06\xC4'\x06\x03\x9D\x12\x9A\xDE\xCE1\xF6Q-\x91\xF5\xDD\xB8q\xEDUcL\xB3Z\xF9\xB5\x1C\xE16\xA1P*x\x86\x8C\xB9\xF2\x03\x81
\xFE\x8E\xCA\xD7*6\x1D\x01]\xCF\xCFR\xD48`HaQG7\x91Q\xF7\xB5\xAE5D\xDE\xA3sQ\xBE\xF8\xCE},u\x13\xC0HjbC\xE6\xEFS\xF7\xBCL\xB62\xFB\x81\\{
{R\xCF\xC9\xEE\xE5\xD5jU\x9D\xD0\x03\xE1?\xA5\xFA\x83\xC8\xDF\xEFN:\xFB{\xECv\xCE\x91\x07\x9C\x02\xFE.>\x8F!K\x8E\x82\xDBN\xEF\xFF\x0F1e\
x96\xC7\xCC\x0B\x1BB+g\xF0\xF7\x93\x8F\xF1(Yz\xF3\xF8R\xCC\xD8\xC91\xE2\xE8\xF3\x96\xF9\x02\x10\x05\x1D\x9D5\x83y\xD4l*4xa\x9B\xE1\xB2\xD
4\x06\x01\x02
>>> homekit_client_process: [Client 1] Finished processing
>>> HomeKit: Got new client connection: 2 from 192.168.1.33
>>> HomeKit: [Client 1] Closing client connection
>>> HomeKit: Got new client connection: 1 from 192.168.1.33
>>> homekit_client_process: [Client 2] Got 131 incomming data
>>> homekit_server_on_pair_setup: Pair Setup
>>> homekit_server_on_pair_setup: Free heap: 46532
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 0 value (1 bytes): \x00
>>> tlv_debug: Type 6 value (1 bytes): \x01
>>> HomeKit: [Client 2] Pair Setup Step 1/3
>>> homekit_server_on_pair_setup: Free heap: 46448
>>> crypto_srp_new: Initializing SRP
>>> homekit_server_on_pair_setup: [Client 2] Initializing crypto
>>> homekit_server_on_pair_setup: Free heap: 45784
>>> homekit_server_on_pair_setup: [Client 2] Using user-specified password: 111-11-111
>>> crypto_srp_init: Generating salt
>>> crypto_srp_init: Setting SRP username
>>> crypto_srp_init: Setting SRP params
>>> crypto_srp_init: Setting SRP password
>>> crypto_srp_init: Getting SRP verifier
>>> crypto_srp_init: Setting SRP verifier
>>> crypto_srp_get_public_key: Calculating public key
>>> send_tlv_response: [Client 2] Sending TLV response
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 3 value (384 bytes): \x14\x18\xFE\x88b<hp\xE8\x0BF[\x89\xCDd\x05\xA6O\xD1D\xEF\x0B\x85\x9C|\xFD\xF8"\xCB\xA5\xE5z3\x9
4\xA3`\xE8J$\xFD8\x96G\xF0\xFF.;$\xE2\xE2n~@M\xB6U\xC9\x8B\x17R\x0AK\xDF\xA5\xFD\xC7_\x129:\x95J\xC0\xD0\xA9)I\x13K$:\xA2\xCCeq\xE2\x010\
xFC"\x84m{\x0DM\x1C!\xF7\xFD\x15\xAB2Z\xAD\xA1\x0F\xECr*\xD3\x8F\xAA\x04\x95\x0F\xA5\xEC2\xBE"x\xED\x85\xED\xA5\xA6wny~\x1B\xB2\xFA\xA3\x
8F~\xC7\xC3\x84\xE8M\x03K\xAC\xA8r\x02\xC3I\xAB<\x84\x0A\xCA5l\x9D\x9D6\xE6\xD2c\x19\x158\xEA\x8C& ^J\xFCj\xDF!\xA1\xCF\x1CN\x9E\xD6a8LG\
x9B\xA05\x07\xC5\x8C5\xDA\xC8\xFC\x02\xF8F\x01\x94\xC5\x18\xBA%v\x94Z\x80d\x9B\x1D\xA8\x15#$\xB5\x80h\xB2k\x19\x0E!\xB4\xD7\xC1pZ\xE8\xCC
i\xCE\xE1p\xF8K\xE9'\xBB\xDC?$@d&X0\x0A#\xE1\xEAaH\xB2\xA6_\x81\xB2\xECG\xAA\x1Bt3Y\xFF%\xE3\xBEs\xB0l\x8A\xC9\x9F\xA8\x1F\xA5\xF6\xFFq\x
B4U\xAC\xAC7:\x18 \xC9\xABkN\xA7\xBEA\xC7\xE6\xDE\xFE\xAC\xCE\xB47S\xF1\xE4F=\xF6\xF3\xB5\x81\xAC\x0C\xE3W\x1F\xF3)H\xBD\\\xDD\xCB^QGn\xF
7\xAC\xE7\x81\x02\x89\xA1\x90l\x0DQzX\x19rY\x0B\x1Bc\xA7\xE1\xB5\xEA\x8F\x1C\xEF\xFB\xED0\x0E\x06eV\x92\x11"\xBCA\xC9\x879\x00\xBB\x8C\xB
1\x19\xEF\xA0\xCF\xB3+\x93-\xB4\xC1
>>> tlv_debug: Type 2 value (16 bytes): \x86\x84\xDA\xC1Y\x1E\xDE\xF3o1\x9Ci\xC6"\x15|
>>> tlv_debug: Type 6 value (1 bytes): \x02
>>> client_send: [Client 2] Sending payload: HTTP/1.1 200 OK\x0D\x0AContent-Type: application/pairing+tlv8\x0D\x0AContent-Length: 409\x0D
\x0AConnection: keep-alive\x0D\x0A\x0D\x0A\x03\xFF\x14\x18\xFE\x88b<hp\xE8\x0BF[\x89\xCDd\x05\xA6O\xD1D\xEF\x0B\x85\x9C|\xFD\xF8"\xCB\xA5
\xE5z3\x94\xA3`\xE8J$\xFD8\x96G\xF0\xFF.;$\xE2\xE2n~@M\xB6U\xC9\x8B\x17R\x0AK\xDF\xA5\xFD\xC7_\x129:\x95J\xC0\xD0\xA9)I\x13K$:\xA2\xCCeq\
xE2\x010\xFC"\x84m{\x0DM\x1C!\xF7\xFD\x15\xAB2Z\xAD\xA1\x0F\xECr*\xD3\x8F\xAA\x04\x95\x0F\xA5\xEC2\xBE"x\xED\x85\xED\xA5\xA6wny~\x1B\xB2\
xFA\xA3\x8F~\xC7\xC3\x84\xE8M\x03K\xAC\xA8r\x02\xC3I\xAB<\x84\x0A\xCA5l\x9D\x9D6\xE6\xD2c\x19\x158\xEA\x8C& ^J\xFCj\xDF!\xA1\xCF\x1CN\x9E
\xD6a8LG\x9B\xA05\x07\xC5\x8C5\xDA\xC8\xFC\x02\xF8F\x01\x94\xC5\x18\xBA%v\x94Z\x80d\x9B\x1D\xA8\x15#$\xB5\x80h\xB2k\x19\x0E!\xB4\xD7\xC1p
Z\xE8\xCCi\xCE\xE1p\xF8K\xE9'\xBB\xDC?$@d&X0\x0A#\xE1\xEAaH\xB2\xA6\x03\x81_\x81\xB2\xECG\xAA\x1Bt3Y\xFF%\xE3\xBEs\xB0l\x8A\xC9\x9F\xA8\x
1F\xA5\xF6\xFFq\xB4U\xAC\xAC7:\x18 \xC9\xABkN\xA7\xBEA\xC7\xE6\xDE\xFE\xAC\xCE\xB47S\xF1\xE4F=\xF6\xF3\xB5\x81\xAC\x0C\xE3W\x1F\xF3)H\xBD
\\\xDD\xCB^QGn\xF7\xAC\xE7\x81\x02\x89\xA1\x90l\x0DQzX\x19rY\x0B\x1Bc\xA7\xE1\xB5\xEA\x8F\x1C\xEF\xFB\xED0\x0E\x06eV\x92\x11"\xBCA\xC9\x8
79\x00\xBB\x8C\xB1\x19\xEF\xA0\xCF\xB3+\x93-\xB4\xC1\x02\x10\x86\x84\xDA\xC1Y\x1E\xDE\xF3o1\x9Ci\xC6"\x15|\x06\x01\x02
>>> homekit_client_process: [Client 2] Finished processing
>>> HomeKit: Got new client connection: 3 from 192.168.1.33
>>> homekit_client_process: [Client 1] Got 131 incomming data
>>> homekit_server_on_pair_setup: Pair Setup
>>> homekit_server_on_pair_setup: Free heap: 41304
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 0 value (1 bytes): \x00
>>> tlv_debug: Type 6 value (1 bytes): \x01
>>> HomeKit: [Client 1] Pair Setup Step 1/3
>>> homekit_server_on_pair_setup: Free heap: 41212
>>> HomeKit: [Client 1] Refusing to pair: another pairing in progress
>>> send_tlv_response: [Client 1] Sending TLV response
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 6 value (1 bytes): \x02
>>> tlv_debug: Type 7 value (1 bytes): \x07
>>> client_send: [Client 1] Sending payload: HTTP/1.1 200 OK\x0D\x0AContent-Type: application/pairing+tlv8\x0D\x0AContent-Length: 6\x0D\x
0AConnection: keep-alive\x0D\x0A\x0D\x0A\x06\x01\x02\x07\x01\x07
>>> homekit_client_process: [Client 1] Finished processing
>>> homekit_client_process: [Client 3] Got 131 incomming data
>>> homekit_server_on_pair_setup: Pair Setup
>>> homekit_server_on_pair_setup: Free heap: 41340
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 0 value (1 bytes): \x00
>>> tlv_debug: Type 6 value (1 bytes): \x01
>>> HomeKit: [Client 3] Pair Setup Step 1/3
>>> homekit_server_on_pair_setup: Free heap: 41248
>>> HomeKit: [Client 3] Refusing to pair: another pairing in progress
>>> send_tlv_response: [Client 3] Sending TLV response
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 6 value (1 bytes): \x02
>>> tlv_debug: Type 7 value (1 bytes): \x07
>>> client_send: [Client 3] Sending payload: HTTP/1.1 200 OK\x0D\x0AContent-Type: application/pairing+tlv8\x0D\x0AContent-Length: 6\x0D\x
0AConnection: keep-alive\x0D\x0A\x0D\x0A\x06\x01\x02\x07\x01\x07
>>> homekit_client_process: [Client 3] Finished processing
>>> HomeKit: [Client 1] Closing client connection
>>> HomeKit: [Client 2] Closing client connection
>>> HomeKit: [Client 3] Closing client connection
>>> HomeKit: Got new client connection: 1 from 192.168.1.33
>>> homekit_client_process: [Client 1] Got 131 incomming data
>>> homekit_server_on_pair_setup: Pair Setup
>>> homekit_server_on_pair_setup: Free heap: 48732
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 0 value (1 bytes): \x00
>>> tlv_debug: Type 6 value (1 bytes): \x01
>>> HomeKit: [Client 1] Pair Setup Step 1/3
>>> homekit_server_on_pair_setup: Free heap: 48648
>>> crypto_srp_new: Initializing SRP
>>> homekit_server_on_pair_setup: [Client 1] Initializing crypto
>>> homekit_server_on_pair_setup: Free heap: 47976
>>> homekit_server_on_pair_setup: [Client 1] Using user-specified password: 111-11-111
>>> crypto_srp_init: Generating salt
>>> crypto_srp_init: Setting SRP username
>>> crypto_srp_init: Setting SRP params
>>> crypto_srp_init: Setting SRP password
>>> crypto_srp_init: Getting SRP verifier
>>> crypto_srp_init: Setting SRP verifier
>>> crypto_srp_get_public_key: Calculating public key
>>> send_tlv_response: [Client 1] Sending TLV response
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 3 value (384 bytes): \xBA\xD9\x1A\xF3\x06\xAD\xEC\xEBm\x0D6\xE6\xF9\x1Cj\x8Et9H\xB1\xFFg"t\xF5\xBD/\xB1\xAE|\x0B\x9C\
xEF\x04d\xBC\xBEae+\xBBp\xCBi\xB6i\x99\xC7\xB0\x03\xE2*%y\xA0\x9B\x95h\xAB\x0Dz\xA6c\xAA\x98\x89\xB1\xE0\x91e=`y$\x02\\\x1E\xEF\xB8\x88K
G\x9A\xE4u\xACp\xADs\xB9JK\xE8\xEE\xE6\x83\xB9\xC9b\x83\xFF\xEB\xF1\xA8\x82x\x07\xE0\xAB\xAD#\x00\xF21+\x18(@H\xFFs\x86\xBA\xC7M2\xDDG\x1
7\x8CT\x99\xA1WPh\x19\xD5J\xF4\x04K\xC0\xB3\x0D K\xA6\x10<\\Y\x83\x87qQ=]f\xBE[\xFC\xE3\x0B\xD85~g1\xDD\xE4\x1D\xAA\x8B\xFF%}\x86b\xF5\x1
B\xC3+~\xA3C\x8B\xC6\xDC\xD3\xC2\x01\xFDF{\xE0\xB6\x0E\x89\x10\xC8\x16\xA3,\x83\xD5.\x85yb\xF7\xB2\x1C\xE1\x0D\xB6\x84U\x0A\xB06\xF2s\x9C
\xA5\xE4\xD9dXuMc\xFCu\xDE\x97\xEC\x97L\xAC\xB12\x02\xB0EO;^\x0F\xE5\xB4\xB1:\x0F9\xC2\xAF\x88r\xD1\x8D\xC81\xAB\xB1\xBEF\xF1\xB2\x8Bn7\
x87\xE5L\\|\xB5\xB4\xF6\x91G\xE4\xE0\x09\xF9L\xD6\xFA\xE9\xECJ\xCBd\xB9\xA2\x99\x1E\x9F|\xBB;\xAA\x86\xDC\x9D\x10!?\x95\xC0\xF1\x8C\xDD8
\xD4[\xDD\xEB\xF3\x9A,\xD0tx\xD9{\x88\x91\x01\xAF\x92\xFB\xE7\xFC\xC8<\xED\xF0\xEC\xF8\xAA\xA5\x18\xC43\xE3:\xDF\xAFR\x86C\x09\x17G\xB2\x
9D\xC5\x9B~\xF65\x1F\x86\x11\x1A\x187\xABY\x8D=\xFF`\xEF\x0E\xE8\xE3\xA5\xA2
>>> tlv_debug: Type 2 value (16 bytes): \xA4\xC3\xC4=\xFD\x1B\x8A3\xD6\x16\xA0O\x90<\xD1\xD5
>>> tlv_debug: Type 6 value (1 bytes): \x02
>>> client_send: [Client 1] Sending payload: HTTP/1.1 200 OK\x0D\x0AContent-Type: application/pairing+tlv8\x0D\x0AContent-Length: 409\x0D
\x0AConnection: keep-alive\x0D\x0A\x0D\x0A\x03\xFF\xBA\xD9\x1A\xF3\x06\xAD\xEC\xEBm\x0D6\xE6\xF9\x1Cj\x8Et9H\xB1\xFFg"t\xF5\xBD/\xB1\xAE|
\x0B\x9C\xEF\x04d\xBC\xBEae+\xBBp\xCBi\xB6i\x99\xC7\xB0\x03\xE2*%y\xA0\x9B\x95h\xAB\x0Dz\xA6c\xAA\x98\x89\xB1\xE0\x91e=`y$\x02\\\x1E\xEF
\xB8\x88KG\x9A\xE4u\xACp\xADs\xB9JK\xE8\xEE\xE6\x83\xB9\xC9b\x83\xFF\xEB\xF1\xA8\x82x\x07\xE0\xAB\xAD#\x00\xF21+\x18(@H\xFFs\x86\xBA\xC7M
2\xDDG\x17\x8CT\x99\xA1WPh\x19\xD5J\xF4\x04K\xC0\xB3\x0D K\xA6\x10<\\Y\x83\x87qQ=]f\xBE[\xFC\xE3\x0B\xD85~g1\xDD\xE4\x1D\xAA\x8B\xFF%}\x8
6b\xF5\x1B\xC3+~\xA3C\x8B\xC6\xDC\xD3\xC2\x01\xFDF{\xE0\xB6\x0E\x89\x10\xC8\x16\xA3,\x83\xD5.\x85yb\xF7\xB2\x1C\xE1\x0D\xB6\x84U\x0A\xB06
\xF2s\x9C\xA5\xE4\xD9dXuMc\xFCu\xDE\x97\xEC\x97L\xAC\xB12\x02\xB0EO;^\x0F\xE5\xB4\xB1:\x03\x81\x0F9\xC2\xAF\x88r\xD1\x8D\xC81\xAB\xB1\xB
EF\xF1\xB2\x8Bn7\x87\xE5L\\|\xB5\xB4\xF6\x91G\xE4\xE0\x09\xF9L\xD6\xFA\xE9\xECJ\xCBd\xB9\xA2\x99\x1E\x9F|\xBB;\xAA\x86\xDC\x9D\x10!?\x95
\xC0\xF1\x8C\xDD8\xD4[\xDD\xEB\xF3\x9A,\xD0tx\xD9{\x88\x91\x01\xAF\x92\xFB\xE7\xFC\xC8<\xED\xF0\xEC\xF8\xAA\xA5\x18\xC43\xE3:\xDF\xAFR\x8
6C\x09\x17G\xB2\x9D\xC5\x9B~\xF65\x1F\x86\x11\x1A\x187\xABY\x8D=\xFF`\xEF\x0E\xE8\xE3\xA5\xA2\x02\x10\xA4\xC3\xC4=\xFD\x1B\x8A3\xD6\x16\x
A0O\x90<\xD1\xD5\x06\x01\x02
>>> homekit_client_process: [Client 1] Finished processing
>>> homekit_client_process: [Client 1] Got 584 incomming data
>>> homekit_server_on_pair_setup: Pair Setup
>>> homekit_server_on_pair_setup: Free heap: 45784
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 6 value (1 bytes): \x03
>>> tlv_debug: Type 3 value (384 bytes): \x1C\xBE\x80\xAA\x19\xF2%y7\xC3\xC5'\xF310\xA3d\x08\xE1\xCA\xF2\xD6\xF62\x01@Z\xDB-!\x10S\xE4\x1
5\xE2\xAA\xF9\x82a\xB2(\xE6Nt3\xB2\x91\xE8!\xA3u\xD9\xE6\xD7A\xAD\x10<\xB5\x8A\xACG;\xCBmg\x80\xAC\x1B=t\x94\x80\xBF\xEB\xFBSO1\xD7,t\x8
B\xC96\xA9\x8E\xA8\x0A\xB7\xD1\xED\x0D<"\xAC\xF5\xFA\xAB\xF9\xD2>9j\xEA\x1AQ\xF4\x1Dvz\x14\xC85\xAAEo5\x16\xE9x\xBF\xAA\x0D\xEA-\xB6nD\xC
C\xB5\xAF\xEA\xBF\x82f\x0E\xAE+`\xD1\x10\xB4\x81Qg\x90<\x08\x1EC#][\xB7\xB5\x89-\x89e\xB4\x89\xD2B\x10\xCFJ\x02\xBE\xA4s\x82\xDF$1M9\xD2E
\xC0\x9Fv\x0F\xC8\xEDrfBh\xD7T\x0D n\x14,\xEAu\x1E\xDA\x08\x0D:+O\xCD\xE5tVEu\xD8SE\x19\xC5\xA5 \x8Bz\xC5\xA7\xD7\xF09\xDC\xEF\x99s\xC4\x
89\xE4g5\xFB\x1Ao\xDF\xC8Z\x17@{6p\x0E*\xB9Thq\xEC\x0BN\xC4\x97j\x98\x05^\xAE\x82\x1C]\xF71\xCC\x0B\x8F\x13\xEA\xB9\xE2\x8E\xFB\x9Fa?\xC7
\xC3\xA0h\xA8\xE9\x82&\x9A\xB7\xF5\xFF)9\xC09\xAAk\xA0>\xD8H\xA5,\x127\xDD{#P\xEF\x101I\xC7\xE3\xB5\xF3C\x99\x0AC\x81\x1F\xA9\xB7\xC9\xD4
5)\x15\x0A<z\xF9\x96\x8DT\xFB\xE2W\xC0\xE7=#\xFF2b^\x8C\xF2rR\x97\xDET\x9C\x99\x07\xFA?\xEES1\xE8\x0A\xB1\xE1\x12R;M\x18\xED\xCC\xFF+\x98
\xAB\xA1l>\xD9z\xCD
>>> tlv_debug: Type 4 value (64 bytes): v\xFE\x9D\xA6m\x89s\xCF\xC3\xDD\xAF^\xBF\x9B\xD3>\xD0\xDA\x0C\x01\xB5\xC9\xD6Y\x8F_\x82\xEB9\x8BV
\x1C(hyq'\xBA\x84c\x10\xC4H\xD220\xD9\x8A\xED\xA1\xE7\xB6\xC6\xF3f\xAAe\x85\xCDam\xAE\x08L
>>> HomeKit: [Client 1] Pair Setup Step 2/3
>>> homekit_server_on_pair_setup: Free heap: 45216
>>> homekit_server_on_pair_setup: [Client 1] Computing SRP shared secret
>>> homekit_server_on_pair_setup: Free heap: 45216
>>> homekit_server_on_pair_setup: [Client 1] Verifying peer's proof
>>> homekit_server_on_pair_setup: Free heap: 45536
>>> homekit_server_on_pair_setup: [Client 1] Generating own proof
>>> send_tlv_response: [Client 1] Sending TLV response
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 6 value (1 bytes): \x04
>>> tlv_debug: Type 4 value (64 bytes): 5\xA0Qd\xCB\xAA\xD5\x08\x97\x0FJ"u\x85\x13\xBAL\x88\xDEk\x1D2'\xACm\xB2\xEF\xBF\x07\xE0\xD9V\xFE\
xEF\xA3\xD9\x17\x92?\xA5\x84\x86g \xF8\xB1\xB3\xF4\x0C\x1D!r%hs|\xED\xC8h\xB4qU`\xA6
>>> client_send: [Client 1] Sending payload: HTTP/1.1 200 OK\x0D\x0AContent-Type: application/pairing+tlv8\x0D\x0AContent-Length: 69\x0D\
x0AConnection: keep-alive\x0D\x0A\x0D\x0A\x06\x01\x04\x04@5\xA0Qd\xCB\xAA\xD5\x08\x97\x0FJ"u\x85\x13\xBAL\x88\xDEk\x1D2'\xACm\xB2\xEF\xBF
\x07\xE0\xD9V\xFE\xEF\xA3\xD9\x17\x92?\xA5\x84\x86g \xF8\xB1\xB3\xF4\x0C\x1D!r%hs|\xED\xC8h\xB4qU`\xA6
>>> homekit_client_process: [Client 1] Finished processing
>>> homekit_client_process: [Client 1] Got 286 incomming data
>>> homekit_server_on_pair_setup: Pair Setup
>>> homekit_server_on_pair_setup: Free heap: 46404
>>> tlv_debug: Got following TLV values:
>>> tlv_debug: Type 5 value (154 bytes): .\x87S}\xC5\x0D\xD7;.\xEC\xD2]\x88<.C\xB4\xA8r\xA0,\xB5\xB5\x14$Z\x8D\xB1\xDAH-\x88=\xF8\x1Ez\x0
B:6M\x80\xE1\xE3\x83\x80\xE0\x86\xAFQ3\xE7\x0EM\x175\xCD\xB3\x8F\x04\xBCkQ\x18\x8B\xDAK\xFC\xA6o?\xDD\xDE2\xDA]\x8EJ\xD8\x82\x84~\xFC/x*\
xE9\x0FM\xB3\xA3B\x19P\x9D\x86\x85\xB1\xEC\x00H\xD0\x12+%\xCA&\xE3]\xE2!?\xD7\xF3\xDB\xED\xC4\x1E\xF2\xC9\x89\xA1J\xFDK\x92 \xB9(\x91q\x8
A\x13\xE9\xE5\xDA(\xB8\xA8#\x06\x07U\xD4M\x0A\xEE\xDF,\x98E2\xD8\xCA\x12
>>> tlv_debug: Type 6 value (1 bytes): \x05
>>> HomeKit: [Client 1] Pair Setup Step 3/3
>>> homekit_server_on_pair_setup: Free heap: 46160
>>> homekit_server_on_pair_setup: [Client 1] Calculating shared secret
>>> homekit_server_on_pair_setup: [Client 1] Decrypting payload
>>> homekit_server_on_pair_setup: [Client 1] Importing device public key
>>> homekit_server_on_pair_setup: [Client 1] Calculating DeviceX
>>> homekit_server_on_pair_setup: [Client 1] Verifying device signature
>>> HomeKit: Added pairing with 8F39E629-B67E-44CD-81FD-E7D729CB0B77
toshibochan commented 4 years ago

how to start log?

d4rkmen commented 4 years ago

how to start log?

in sdk config set debug for homekit component

Can you pull the latest version of esp-homekit, build and test again, it will give some extra info to potentially help diagnose

i have used the latest sources and the log above shows there is a problem - connection drop after first pairing request

RavenSystem commented 4 years ago

With esp-open-rtos, can you try again using my modified mdnsresponder?

https://github.com/RavenSystem/esp-homekit-devices/blob/master/external_libs/homekit/src/mdnsresponder.h

https://github.com/RavenSystem/esp-homekit-devices/blob/master/external_libs/homekit/src/mdnsresponder.c

d4rkmen commented 4 years ago

@RavenSystem are you sure its related to pairing? Or its about remote access?

RavenSystem commented 4 years ago

Pairing.

d4rkmen commented 4 years ago

Located the problem: controller closes connection before got response due to long timeout. Fixed with sending http header before long-time crypto procedures, then body when data is ready Thanks for good library

toshibochan commented 4 years ago

@d4rkmen you can send request to fix the issue?

maccoylton commented 4 years ago

@d4rkmen did you submit a pull request for your proposed changes?

d4rkmen commented 4 years ago

Suming up a few days of tries: splitting request to parts not gives any effort. Problem seems different kind of. And seems its related to mdns. After some time (~2 mintures) the accessory stops discovering in home app. If pairind happen at the same time - controller makes retry (closes current connection, and starts new pairing context) I have no idea why this happens. I have tested other mdns library on mongoose-os and there is no such problems: accessory stays discoverable all the time (before paitring done) Any thoughts?

maximkulkin commented 4 years ago

@d4rkmen I wonder what firmware are you running so that you're getting pairing timeouts? Are you doing funny stuff in other threads?

d4rkmen commented 4 years ago

@maximkulkin its the latest ESP8266_RTOS_SDK + led example from this repo. Found temporary workaround: mdns setup before pairing. Will push PR for you, guys, to test if you like. Its now 10 / 10 success pairings for me.

maximkulkin commented 4 years ago

Try esp-open-rtos and see if the problem reproduces

d4rkmen commented 4 years ago

@maximkulkin i will (i saw there were changes on mdns last days) But I move from esp-open-rtos because ot this issue.

maximkulkin commented 4 years ago

I generally do not use ESP8266_RTOS_SDK, have only done one example as proof of concept and haven't tested it for long period of time, but esp-open-rtos works for me all the time, and if it doesn't work for you, you might be doing something wrong. mDNS code hasn't had any changes for a long time.

d4rkmen commented 4 years ago

Not sure why, but there were pairing and remote access problems on esp-open-rtos. Then I decided to check official SDK and I like it better. Just tested now on esp-open-rtos:

[MAC] >>> HomeKit: Got new client connection: 5 from 192.168.1.33
[MAC] >>> HomeKit: [Client 5] Pair Setup Step 1/3
[MAC] >>> HomeKit: Got new client connection: 6 from 192.168.1.33
[MAC] >>> HomeKit: [Client 5] Closing client connection
[MAC] >>> HomeKit: [Client 6] Pair Setup Step 1/3
[MAC] >>> HomeKit: Got new client connection: 5 from 192.168.1.33
[MAC] >>> HomeKit: [Client 5] Pair Setup Step 1/3
[MAC] >>> HomeKit: [Client 5] Refusing to pair: another pairing in progress
[MAC] >>> HomeKit: [Client 5] Closing client connection
[MAC] >>> HomeKit: [Client 6] Closing client connection

result: failed to pair (one of 3-4 pairings) - with workaround works ok, remote access not works :(

maximkulkin commented 4 years ago

What is your firmware? Try basic led example and see if it has same problems.