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

Put_characteristic takes to long #21

Closed
raufis27 opened this Issue May 3, 2018 · 11 comments

Comments

Projects
None yet
4 participants
@raufis27

raufis27 commented May 3, 2018

I guess it is because program has to search for MAC address and talk to it. Any chance that we can interact with accessory by IP or somehow optimize code to make it faster.

Thank you!

@nickpl456

This comment has been minimized.

nickpl456 commented May 3, 2018

I agree that the Zeroconfig, although nice for people that might have constantly changing IPs, is time consuming. I've slightly modified the program to read IP address and Port from the pairing data file however the way I did it is a very hacky and ugly way that I would not suggest anyone else do...

But I would suggest that when pairing the IP and Port get stored in the pairing data file and then either make a command line switch to use that instead of Zeroconfig or only fall back to Zeroconfig if the device cannot be reached on the stored address.

The lag time before a command is executed is cut by almost half for me using an IP address directly.

@raufis27

This comment has been minimized.

raufis27 commented May 3, 2018

Could you please share your modification?

@sberryman

This comment has been minimized.

sberryman commented May 3, 2018

👍🏻 I would also like to see it store and use the IP address

@sberryman sberryman referenced this issue May 3, 2018

Closed

Broken Pipe #22

@nickpl456

This comment has been minimized.

nickpl456 commented May 3, 2018

@raufis27 Like I said it's bad, more of a proof of concept than anything. The command-line switch opinion I described and letting python manage the pairing data file is much more sustainable long term I think, but here it is:

First in the pairing data file add these lines:

"port": "80",
"ip": "192.168.42.70"

Obviously replacing the IP and Port info with what's correct for your device. Make sure you fix the commas, so my complete pairing data file looks like this now (the order doesn't matter, just make sure the commas are right):

{
    "AccessoryPairingID": "3A:99:D4:DF:3C:A7",
    "AccessoryLTPK": "ce5b45fbbf2f1869c4bb8323d62beafee6418cf2e0ad13b8f4f3c4ef39f95113",
    "iOSDeviceLTPK": "e9ed0349cf52e3b00bc85000341c008b87f1e6b82deea6199b968c2ce801a387",
    "iOSDeviceLTSK": "c5aa496411f0929b25ad0b4a5a27fd23aad701974423fb7fea372d49793903db",
    "iOSPairingId": "7826de9d-ade1-4a47-94cd-902e2ccf05c0",
    "port": "80",
    "ip": "192.168.42.70"
}

Then in put_characteristic.py comment out these lines:

   deviceId = pairing_data['AccessoryPairingID']
    connection_data = find_device_ip_and_port(deviceId)
    if connection_data is None:
        print('Device {id} not found'.format(id=deviceId))
        sys.exit(-1)

and in their place add:

    connection_data = {}
    connection_data['ip'] = pairing_data['ip']
    connection_data['port'] = pairing_data['port']

So that section of put_characteristic.py should look like:

    connection_data = {}
    connection_data['ip'] = pairing_data['ip']
    connection_data['port'] = pairing_data['port']

    """deviceId = pairing_data['AccessoryPairingID']

    connection_data = find_device_ip_and_port(deviceId)
    if connection_data is None:
        print('Device {id} not found'.format(id=deviceId))
        sys.exit(-1)
    """

Of course this change only affects the put_characteristic command

@raufis27

This comment has been minimized.

raufis27 commented May 3, 2018

@nickpl456 thank you.

@jlusiardi

This comment has been minimized.

Owner

jlusiardi commented May 3, 2018

I did some quick profiling and it looks like that there 2 slow parts:

  • Zeroconf to find the device (can handled by caching the ip and only searching by mac if the ip seems to have changed)
  • Generating the session keys (these have to be created on each new connection, so not as easy as we would have to have the script keep runnig)

profile

@raufis27

This comment has been minimized.

raufis27 commented May 3, 2018

I think ‘fixing” zoreconf to use IP should be enough. After patching put_Char. my device’s responce is identical to native homekit app.

@jlusiardi

This comment has been minimized.

Owner

jlusiardi commented May 4, 2018

I guess this depends on your homekit device as well. But storing also IP and port in the pairing file will do no harm. I'll get to that on the weekend.

@jlusiardi

This comment has been minimized.

Owner

jlusiardi commented May 5, 2018

I committed to a new branch.
Can someone check if this speeds up for u as well?

@raufis27

This comment has been minimized.

raufis27 commented May 5, 2018

I can confirm that new branch works faster with IP.

@jlusiardi

This comment has been minimized.

Owner

jlusiardi commented May 5, 2018

Merged into master

@jlusiardi jlusiardi closed this May 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment