Arduino-HomeKit-ESP8266 icon indicating copy to clipboard operation
Arduino-HomeKit-ESP8266 copied to clipboard

Already paired

Open spuggy0919 opened this issue 4 years ago • 1 comments
trafficstars

HW wemos d1 r1 Example2_switch iOS 14.6

When programmed into wemos at first, the home will recognize the switch accessory, then delete the switch accessory in iOS home app, then failed to pair again. the accessary key is not renew. Then it did not pair in new run.

possible reason: In Arduino_homekit_server.cpp -> homekit_server_init modified the routine void homekit_server_init(homekit_server_config_t *config) {

// r=-1; modified this line , enable and disable, can reinitialize key, let pair in new cycle. it may help to find root cause if (r) { if (r < 0) { INFO("Resetting HomeKit storage"); homekit_storage_reset(); }

	homekit_accessory_id_generate(server->accessory_id);
	homekit_storage_save_accessory_id(server->accessory_id);

	homekit_accessory_key_generate(&server->accessory_key);
	homekit_storage_save_accessory_key(&server->accessory_key);
} else {
	INFO("Using existing accessory ID: %s", server->accessory_id);
}

Log: [OLD] ESP32 Board MAC Address: 5C:CF:7F:83:E1:8B. // I try to change Mac, not work [NEW] ESP32 Board MAC Address: 5C:CF:7F:83:E1:8B WiFi connecting... .................................. WiFi connected, IP: 192.168.1.102

[ 5314] HomeKit: Update the CPU to run at 160MHz [ 5322] HomeKit: PASSWORD=111-11-111 [ 5326] HomeKit: Starting server [ 5329] HomeKit: ServerID=1073677592 [ 5333] HomeKit: ServerKey=96 [ 5336] HomeKit: Using existing accessory ID: A7:10:81:9F:B3:10 [ 5342] HomeKit: Pair 144 [ 5345] HomeKit: Found admin pairing with B36C4F99-E996-43DA-B8E4-0F57004E9437, disabling pair setup // no pairing [ 5354] HomeKit: Configuring MDNS [ 5359] HomeKit: MDNS begin: Switch, IP: 192.168.1.102 [ 5366] HomeKit: Init server over Free heap: 44616, HomeKit clients: 0 Free heap: 45168, HomeKit clients: 0

[OLD] ESP32 Board MAC Address: 5C:CF:7F:83:E1:8B. // insert r=-1 to reinitialize accessary id [NEW] ESP32 Board MAC Address: 5C:CF:7F:83:E1:8B WiFi connecting... .................................. WiFi connected, IP: 192.168.1.102

[ 5315] HomeKit: Update the CPU to run at 160MHz [ 5322] HomeKit: PASSWORD=111-11-111 [ 5326] HomeKit: Starting server [ 5329] HomeKit: ServerID=1073677592 [ 5333] HomeKit: ServerKey=96 [ 5336] HomeKit: Resetting HomeKit storage [ 5341] HomeKit: Formatting HomeKit storage at 0x3fb000 [ 5374] HomeKit: Generated new accessory ID: 50:AD:C9:91:65:43 [ 5431] HomeKit: Generated new accessory key [ 5436] HomeKit: Pair 144 [ 5440] HomeKit: Preiniting pairing context [ 5444] HomeKit: Using user-specified password: 111-11-111 [ 5464] HomeKit: Call s_mp_exptmod in integer.c, original winsize 6 [ 12196] HomeKit: Call s_mp_exptmod in integer.c, original winsize 5 [ 15613] HomeKit: Preinit pairing context success [ 15618] HomeKit: Configuring MDNS [ 15623] HomeKit: MDNS begin: Switch, IP: 192.168.1.102 [ 15630] HomeKit: Init server over Free heap: 41424, HomeKit clients: 0

�⸮��⸮⸮⸮⸮�⸮�⸮⸮⸮⸮⸮⸮⸮�⸮⸮⸮⸮ [OLD] ESP32 Board MAC Address: 5C:CF:7F:83:E1:8B. // delete r=-1, normal pairing, again [NEW] ESP32 Board MAC Address: 5C:CF:7F:83:E1:8B WiFi connecting... .................................. WiFi connected, IP: 192.168.1.102

[ 5314] HomeKit: Update the CPU to run at 160MHz [ 5321] HomeKit: PASSWORD=111-11-111 [ 5325] HomeKit: Starting server [ 5329] HomeKit: ServerID=1073677592 [ 5333] HomeKit: ServerKey=96 [ 5336] HomeKit: Using existing accessory ID: 50:AD:C9:91:65:43 [ 5342] HomeKit: Pair 144 [ 5345] HomeKit: Preiniting pairing context [ 5349] HomeKit: Using user-specified password: 111-11-111 [ 5370] HomeKit: Call s_mp_exptmod in integer.c, original winsize 6 [ 12088] HomeKit: Call s_mp_exptmod in integer.c, original winsize 5 [ 15521] HomeKit: Preinit pairing context success [ 15526] HomeKit: Configuring MDNS [ 15531] HomeKit: MDNS begin: Switch, IP: 192.168.1.102 [ 15538] HomeKit: Init server over Free heap: 41424, HomeKit clients: 0 Free heap: 41600, HomeKit clients: 0 [ 21112] HomeKit: Got new client: local 192.168.1.102:5556, remote 192.168.1.103:50019 [ 21122] HomeKit: [Client 1073683620] Pair Setup Step 1/3 [ 21261] HomeKit: [Client 1073683620] Pair Setup Step 2/3 [ 21276] HomeKit: Call s_mp_exptmod in integer.c, original winsize 6 [ 41416] HomeKit: Call s_mp_exptmod in integer.c, original winsize 5 Free heap: 40032, HomeKit clients: 1 [ 51431] HomeKit: [Client 1073683620] Pair Setup Step 3/3 [ 51479] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c [ 52913] HomeKit: Added pairing with B36C4F99-E996-43DA-B8E4-0F57004E9437 [ 53030] HomeKit: Free saved_preinit_pairing_context [ 53035] HomeKit: [Client 1073683620] Successfully paired [ 53195] HomeKit: [Client 1073683620] Disconnected! [ 53200] HomeKit: [Client 1073683620] Closing client connection [ 54246] HomeKit: Got new client: local 192.168.1.102:5556, remote 192.168.1.103:50020 [ 54256] HomeKit: [Client 1073677812] Pair Verify Step 1/2 [ 54868] HomeKit: Free heap: 42152 [ 55100] HomeKit: [Client 1073677812] Pair Verify Step 2/2 [ 55107] HomeKit: [Client 1073677812] Found pairing with B36C4F99-E996-43DA-B8E4-0F57004E9437 [ 55141] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c [ 56592] HomeKit: [Client 1073677812] Verification successful, secure session established [ 56600] HomeKit: Free heap: 42152 Free heap: 42288, HomeKit clients: 1 [ 56660] HomeKit: [Client 1073677812] Get Accessories [ 56844] HomeKit: [Client 1073677812] Update Characteristics [ 56906] HomeKit: [Client 1073677812] Update Characteristics [ 56939] HomeKit: [Client 1073677812] Update Characteristics [ 56970] HomeKit: [Client 1073677812] Get Characteristics Free heap: 42832, HomeKit clients: 1 [ 65262] HomeKit: [Client 1073677812] Update Characteristics Switch: ON Free heap: 42832, HomeKit clients: 1 [ 66776] HomeKit: [Client 1073677812] Update Characteristics Switch: OFF Free heap: 42736, HomeKit clients: 1 Free heap: 42832, HomeKit clients: 1

spuggy0919 avatar Jun 28 '21 01:06 spuggy0919

It seems no hw option to check whether it is paired , or it is need to pair again. Only one reset pin is not enough. we can setup another GPIO pin high/low to check it at boot time. Then the library implements one callback function to check this GPIO flag to decide whether paired or renew for pairing again.

HW implements software reset algorithm by press time (press long for pairing again , short time for reset)

  1. Press GPIO, trigger one timer start 5 sec counter
  2. timer check if GPIO low, reset immediately.
  3. timer after 5 sec, reset Homekit accessary
  4. at boot time check GPIO , and callback function to set this flag for Library, if GPIO is active then renew for pairing, otherwise normal reset

spuggy0919 avatar Jul 08 '21 14:07 spuggy0919