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

Pairing issues with updated esp-homekit library #8

Open
renandw opened this issue Dec 22, 2022 · 7 comments
Open

Pairing issues with updated esp-homekit library #8

renandw opened this issue Dec 22, 2022 · 7 comments

Comments

@renandw
Copy link

renandw commented Dec 22, 2022

Hello Maxim,
Sorry to trouble you once more...

Since updated to iOS 16.2, the I was having some connection issues with my accessories. Also I've damaged my previous PC and needed to build the environment again. Also I hoped that updating to the latest commits helped somehow.
But I faced a different issue when pairing.

!!! HomeKit: Characteristic value format is different from characteristic format

Of course I thought that I messed something and tried the code in this repository but with updates in "esp-homekit-demo" components libraries.

And I realized that every accessories with 2 services or more is not working.

The log is here:

>>> wifi_config: Connected to WiFi network
station: aa:1a:05:97:92:6c leave, AID = 1
rm match
bcn 0
del if1
mode : sta(e0:98:06:85:92:09)
Function called without core lock
>>> HomeKit: Starting server
>>> HomeKit: Formatting HomeKit storage at 0x7a000
>>> HomeKit: Generated new accessory ID: DE:F1:85:38:63:27
>>> HomeKit: Generated new accessory key
>>> HomeKit: Configuring mDNS
HomeKit: adding mDNS TXT record md=Basic
HomeKit: adding mDNS TXT record pv=1.0
HomeKit: adding mDNS TXT record id=DE:F1:85:38:63:27
HomeKit: adding mDNS TXT record c#=1
HomeKit: adding mDNS TXT record s#=1
HomeKit: adding mDNS TXT record ff=0
HomeKit: adding mDNS TXT record sf=1
HomeKit: adding mDNS TXT record ci=9
>>> wifi_config: Stopping HTTP server
>>> wifi_config: Stopping DNS server
mDNS: Delaying probe until IP is acquired
Got IP, resuming mDNS
mDNS: Probing 1 Fujitsu AC-859209
mDNS: Probing 1 Fujitsu AC-859209
mDNS: Probing 2 Fujitsu AC-859209
mDNS: Probing 3 Fujitsu AC-859209
mDNS: Probe successful, announcing Fujitsu AC-859209 TXT md=Basic pv=1.0 id=DE:F1:85:38:63:27 c#=1 s#=1 ff=0 sf=1 ci=9 
mDNS: Announcing 1 Fujitsu AC-859209
mDNS: Announcing 2 Fujitsu AC-859209
mDNS: Announcing 3 Fujitsu AC-859209
mDNS: Announcing 4 Fujitsu AC-859209
>>> HomeKit: [Client 1] Got new client connection from 192.168.0.125
>>> HomeKit: [Client 1] Pair Setup Step 1/3
>>> HomeKit: [Client 1] Pair Setup Step 2/3
>>> HomeKit: [Client 1] Pair Setup Step 3/3
>>> HomeKit: Added pairing with E5E998A5-F7EC-4B7F-BDA9-3FCA70490519
>>> HomeKit: Configuring mDNS
HomeKit: adding mDNS TXT record md=Basic
HomeKit: adding mDNS TXT record pv=1.0
HomeKit: adding mDNS TXT record id=DE:F1:85:38:63:27
HomeKit: adding mDNS TXT record c#=1
HomeKit: adding mDNS TXT record s#=1
HomeKit: adding mDNS TXT record ff=0
HomeKit: adding mDNS TXT record sf=0
HomeKit: adding mDNS TXT record ci=9
>>> HomeKit: [Client 1] Successfully paired
>>> HomeKit: [Client 1] Closing client connection from 192.168.0.125
>>> HomeKit: [Client 1] Got new client connection from 192.168.0.125
mDNS: Probing 1 Fujitsu AC-859209
>>> HomeKit: [Client 1] Pair Verify Step 1/2
>>> HomeKit: [Client 1] Pair Verify Step 2/2
>>> HomeKit: [Client 1] Found pairing with E5E998A5-F7EC-4B7F-BDA9-3FCA70490519
>>> HomeKit: [Client 1] Verification successful, secure session established
>>> HomeKit: [Client 1] Get Accessories
!!! HomeKit: Characteristic value format is different from characteristic format
>>> HomeKit: [Client 1] Closing client connection from 192.168.0.125
mDNS: Probing 2 Fujitsu AC-859209
mDNS: Probing 3 Fujitsu AC-859209
mDNS: Probe successful, announcing Fujitsu AC-859209 TXT md=Basic pv=1.0 id=DE:F1:85:38:63:27 c#=1 s#=1 ff=0 sf=0 ci=9 
mDNS: Announcing 1 Fujitsu AC-859209
>>> HomeKit: [Client 1] Got new client connection from 192.168.0.125
>>> HomeKit: [Client 1] Pair Verify Step 1/2
>>> HomeKit: [Client 1] Closing client connection from 192.168.0.125
mDNS: Announcing 2 Fujitsu AC-859209
mDNS: Announcing 3 Fujitsu AC-859209
mDNS: Announcing 4 Fujitsu AC-859209

Can you help me to get in the right path?
Thanks in advance

@renandw
Copy link
Author

renandw commented Dec 23, 2022

I compiled with esp-homekit @ 0f8dd68 and wolfssi @ 790b040
Also, I’ve created a new home in home.app
Now it’s working.
Still debugging some code, don’t know if it was ios16.2 new home architecture.
Anyway. Thanks

@renandw renandw closed this as completed Dec 23, 2022
@renandw renandw reopened this Jan 14, 2023
@renandw
Copy link
Author

renandw commented Jan 14, 2023

After having everything working I started to debugging my code. Updated to the lattes version of the repository.
Changed the HOMEKIT ACCESSORY section to this.

homekit_accessory_t *accessories[] = {
        HOMEKIT_ACCESSORY(.id=1, .category=homekit_accessory_category_bridge, .services=(homekit_service_t*[]) {
          HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]) {
          &name,
          &manufacturer,
          &serial,
          &model,
          &revision,
          HOMEKIT_CHARACTERISTIC(IDENTIFY, BS53EXTAC_identify),
          NULL
      }),
      NULL
    }),
    HOMEKIT_ACCESSORY(.id=2, .category=homekit_accessory_category_thermostat, .services=(homekit_service_t*[]){
            HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]){
              HOMEKIT_CHARACTERISTIC(NAME, "Ar Condicionado EXTAC"),
              HOMEKIT_CHARACTERISTIC(IDENTIFY, BS53EXTAC_identify),
              NULL
            }),
            HOMEKIT_SERVICE(THERMOSTAT, .primary=true, .characteristics=(homekit_characteristic_t*[]) {
                    HOMEKIT_CHARACTERISTIC(NAME, "Ar Condicionado EXTAC"),
                    &current_humidity,
                    &current_temperature,
                    &target_temperature,
                    &current_state,
                    &target_state,
                    &units,
                    &ota_trigger,
                    NULL
                }),
                NULL,
              }),
    /*                HOMEKIT_SERVICE(FAN2, .characteristics=(homekit_characteristic_t*[]) {
                    HOMEKIT_CHARACTERISTIC(NAME, "Fan"),
                    &fan_active,
                    &fan_rotation_speed,
                    &fan_swing_mode,
                    NULL
            }),
            NULL
    }), */
        HOMEKIT_ACCESSORY(.id=3, .category=homekit_accessory_category_sensor, .services=(homekit_service_t*[]) {
                HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]) {
                  HOMEKIT_CHARACTERISTIC(NAME, "Porta Suíte"),
                  HOMEKIT_CHARACTERISTIC(IDENTIFY, BS53EXTAC_identify),
                        NULL
                }),
                HOMEKIT_SERVICE(CONTACT_SENSOR, .primary=true, .characteristics=(homekit_characteristic_t*[]) {
                        HOMEKIT_CHARACTERISTIC(NAME, "Porta Suíte"),
                        &door_open_detected,
                        NULL
                }),
                NULL
        }),
        HOMEKIT_ACCESSORY(.id=4, .category=homekit_accessory_category_switch, .services=(homekit_service_t*[]){
                HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]){
                        HOMEKIT_CHARACTERISTIC(NAME, "Lampada 1"),
                        HOMEKIT_CHARACTERISTIC(IDENTIFY, BS53EXTAC_identify),
                        NULL
                }),
                HOMEKIT_SERVICE(LIGHTBULB, .primary=true, .characteristics=(homekit_characteristic_t*[]){
                        HOMEKIT_CHARACTERISTIC(NAME, "Lampada 1"),
                        &lightbulb_on_1,
                        NULL
                }),
                NULL
        }),
        HOMEKIT_ACCESSORY(.id=5, .category=homekit_accessory_category_switch, .services=(homekit_service_t*[]){
                HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]){
                        HOMEKIT_CHARACTERISTIC(NAME, "Lampada 2"),
                        HOMEKIT_CHARACTERISTIC(IDENTIFY, BS53EXTAC_identify),
                        NULL
                }),
                HOMEKIT_SERVICE(LIGHTBULB, .primary=true, .characteristics=(homekit_characteristic_t*[]){
                        HOMEKIT_CHARACTERISTIC(NAME, "Lampada 2"),
                        &lightbulb_on_2,
                        NULL
                }),
                NULL
        }),
        HOMEKIT_ACCESSORY(.id=6, .category=homekit_accessory_category_switch, .services=(homekit_service_t*[]){
                HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]){
                        HOMEKIT_CHARACTERISTIC(NAME, "Lampada 3"),
                        HOMEKIT_CHARACTERISTIC(IDENTIFY, BS53EXTAC_identify),
                        NULL
                }),
                HOMEKIT_SERVICE(LIGHTBULB, .primary=true, .characteristics=(homekit_characteristic_t*[]){
                        HOMEKIT_CHARACTERISTIC(NAME, "Lampada 3"),
                        &lightbulb_on_3,
                        NULL
                }),
                NULL
        }),
        NULL
}; 

I got everything working except the FAN2 service. So I commented it out.
I looked in other repositories, changed a few things but it doesn't work.

Sorry to bother you once more, if you have any insights would be great.

Thanks in advance

@renandw
Copy link
Author

renandw commented Apr 6, 2023

After a bit of research, I commented out the "&fan_rotation_speed,"
And the fan worked.
So I started to dig a little bit on it. But I still cannot find the answer to this problem.

homekit_value_t ac_speed_get() {
  switch (AC.fan) {
  case ac_fan_auto:
    return HOMEKIT_FLOAT(50);
  case ac_fan_low:
    return HOMEKIT_FLOAT(33);
  case ac_fan_med:
    return HOMEKIT_FLOAT(67);
  case ac_fan_high:
    return HOMEKIT_FLOAT(100);
  default:
    return HOMEKIT_FLOAT(0);
  }
}

void ac_speed_set(homekit_value_t value) {
  if ((xEventGroupGetBits(sync_flags) & SYNC_FLAGS_UPDATE) == 0)
    return;
  float input = value.float_value;
  if (input >= 67) {
    ac_rotation_speed.value = HOMEKIT_FLOAT(100);
    AC.fan = ac_fan_high;
  } else if (input >= 33) {
    ac_rotation_speed.value = HOMEKIT_FLOAT(67);
    AC.fan = ac_fan_med;
  } else if (input > 0) {
    ac_rotation_speed.value = HOMEKIT_FLOAT(33);
    AC.fan = ac_fan_low;
  } else {
    ac_rotation_speed.value = HOMEKIT_FLOAT(0);
    ac_active.value = HOMEKIT_BOOL(false);
    AC.active = false;
  }

in this repository (https://github.com/Fonger/esp-homekit-sanyo-cooler/blob/3679ec435d14aadcf13d265b6ffe604adaafcffe/src/homekit_callback.c), the accessory with the ac_rotation_speed - once it uses a HEATER_COOLER service (similar to the &fan_rotation_speed, in FAN2 service). I had no issues.
but I didn't find the bug in the esp-ir-thermostat approach in the rotation_speed.

Anyway. I will keep looking for answers.
Thanks in advance

@maximkulkin
Copy link
Owner

Just show definition for fan_rotation_speed characteristic

@renandw
Copy link
Author

renandw commented Apr 13, 2023

Hi maxim. thanks for responding :)

A few months ago I updated to the latest esp-homekit commits.
I use the esp-ir-thermostat main.c file as an example for my accessories. And it started to notice that when I've tried to pair, I got an error: HomeKit: Characteristic value format is different from characteristic format.
But when I use esp-homekit @ 0f8dd68, it worked fine.

and then I started debugging the code. And noticed that whenever I used the FAN2 service with the fan_rotation_speed characteristic I got the error. But it is basically the same of yours in main.c.
So I started to use the thermostat example without the FAN2 service. I still can control the AC to turn on, off or heat. And all the automation. But, as expected, without the speed control.

I started to tweak a few things in the code and noticed that when I change to this, it pairs. But I still tweaking the update_state(); and the void ir_rx_task(void *_args) to work with it.

homekit_characteristic_t fan_rotation_speed = HOMEKIT_CHARACTERISTIC_(
                                                              ROTATION_SPEED,
                                                                      1,
                                                                      .callback=HOMEKIT_CHARACTERISTIC_CALLBACK(fan_rotation_speed_callback),
                                                                      .format = homekit_format_uint8,
                                                                      .unit = homekit_unit_none,
                                                                      .min_value = (float[]) {0},
                                                                      .max_value = (float[]) {4},

I don't know if I am making myself clear.
But try to compile and pair the thermostat accessory with the newest esp-homekit.
Thanks in advance

@maximkulkin
Copy link
Owner

So the error you're getting is because you have difference in the type of value you assign to characteristic (or return from a custom getter if you use one) and the type of the characteristic itself. Like in the code sample above you override ROTATION_SPEED characteristic format to be homekit_format_uint8, but in previous code samples you posted you set it as HOMEKIT_FLOAT().

Revision 0f8dd68 was LONG time ago and there were many changes since then and it's hard to trace why it wouldn't work. IMO it's easier to figure out why it does not work now than to figure out why it worked before.

@renandw
Copy link
Author

renandw commented Apr 13, 2023

That’s the point that I am trying to say.
I only get the error, with the code in main.c from esp-ir-thermostat.

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

2 participants