jlusiardi / homekit_python

A python implementation to work as both HomeKit controller and accessory.
Apache License 2.0
223 stars 41 forks source link

BLE Error with Manufacturer Data on Nanoleaf Essentials #231

Open Zoneykid opened 2 years ago

Zoneykid commented 2 years ago

Hi, trying to pair with Nanoleaf Essentials and I get the following result. Not sure what to do about error with length of manufacturer data, I tried the timed writes edit as well but got the same result. This is using a radxa zero's built in bluetooth adapter.

homelab:~:% py homekit.discover_ble --adapter hci1 && py homekit.pair_ble -m d6:8b:89:xx:xx:xx -p 111-11-111 -f /home/kevin/durfee.homekitpairing -a nanobulb1 --log DEBUG --adapter hci1

Name: Nanoleaf A19 XXXX
MAC: xx:xx:xx:xx:xx:xx
Configuration number (cn): 1
Device ID (id): xx:xx:xx:xx:xx:xx
Compatible Version (cv): 2
Global State Number (s#): 2
Status Flags (sf): The accessory has not been paired with any controllers. (Flag: 1)
Category Identifier (ci): Lightbulb (Id: 5)

Name: Nanoleaf Strip XXXX
MAC: xx:xx:xx:xx:xx:xx
Configuration number (cn): 2
Device ID (id): xx:xx:xx:xx:xx:xx
Compatible Version (cv): 2
Global State Number (s#): 3
Status Flags (sf): The accessory has not been paired with any controllers. (Flag: 1)
Category Identifier (ci): Lightbulb (Id: 5)

2022-02-26 23:01:27,285 pair_ble.py:0046 DEBUG Using adapter "hci1".
2022-02-26 23:01:27,288 pair_ble.py:0066 DEBUG start pairing
2022-02-26 23:01:27,346 manufacturer_data.py:0034 DEBUG manufacturer specific data: 1006771e51fa6b6e
2022-02-26 23:01:27,364 manufacturer_data.py:0034 DEBUG manufacturer specific data: 021574278bdab64445208f0c720eaf0599350100b33ec5
2022-02-26 23:01:27,369 manufacturer_data.py:0034 DEBUG manufacturer specific data: 0f08c00adaa86600440b10020104
2022-02-26 23:01:27,378 manufacturer_data.py:0034 DEBUG manufacturer specific data: 10052118e90149
2022-02-26 23:01:27,383 manufacturer_data.py:0034 DEBUG manufacturer specific data: 0906031cc0a80003
2022-02-26 23:01:27,397 manufacturer_data.py:0034 DEBUG manufacturer specific data: 0c0e00e5aa33a67dbeec003ea465f1191006761d68f42d68
2022-02-26 23:01:27,406 manufacturer_data.py:0034 DEBUG manufacturer specific data: 1006131d66c0e858
2022-02-26 23:01:27,419 manufacturer_data.py:0034 DEBUG manufacturer specific data: 063101dfb1bc782d0c050003000202b623c094
2022-02-26 23:01:27,419 manufacturer_data.py:0043 DEBUG advertising interval 31
2022-02-26 23:01:27,420 manufacturer_data.py:0046 DEBUG error with length of manufacturer data
2022-02-26 23:01:27,420 manufacturer_data.py:0068 DEBUG remaining data: b623c094
2022-02-26 23:01:27,426 manufacturer_data.py:0034 DEBUG manufacturer specific data: 0c0e00761dda6289d96e38b31e1812881006401d1cea2728
2022-02-26 23:01:27,431 manufacturer_data.py:0034 DEBUG manufacturer specific data: 063101832c83cbe50d050002000102c4244078
2022-02-26 23:01:27,431 manufacturer_data.py:0043 DEBUG advertising interval 31
2022-02-26 23:01:27,432 manufacturer_data.py:0046 DEBUG error with length of manufacturer data
2022-02-26 23:01:27,432 manufacturer_data.py:0068 DEBUG remaining data: c4244078
2022-02-26 23:01:27,440 manufacturer_data.py:0034 DEBUG manufacturer specific data: 063101dfb1bc782d0c050003000202b623c094
2022-02-26 23:01:27,441 manufacturer_data.py:0043 DEBUG advertising interval 31
2022-02-26 23:01:27,441 manufacturer_data.py:0046 DEBUG error with length of manufacturer data
2022-02-26 23:01:27,441 manufacturer_data.py:0068 DEBUG remaining data: b623c094
2022-02-26 23:01:27,442 controller.py:0478 DEBUG connecting to device
2022-02-26 23:01:28,301 device.py:0093 DEBUG waiting for services to be resolved
2022-02-26 23:01:29,306 device.py:0103 DEBUG enumerating resolved services
2022-02-26 23:01:31,121 controller.py:0480 DEBUG connected to device
2022-02-26 23:01:31,121 __init__.py:0590 DEBUG services: [<homekit.controller.ble_impl.gatt.Service object at 0xffffb4f6afa0>, <homekit.controller.ble_impl.gatt.Service object at 0xffffb4f6af70>, <homekit.controller.ble_impl.gatt.Service object at 0xffffb4f6ad90>, <homekit.controller.ble_impl.gatt.Service object at 0xffffb4f6a4f0>, <homekit.controller.ble_impl.gatt.Service object at 0xffffb4f39d60>, <homekit.controller.ble_impl.gatt.Service object at 0xffffb4ec9670>, <homekit.controller.ble_impl.gatt.Service object at 0xffffb4ec37f0>, <homekit.controller.ble_impl.gatt.Service object at 0xffffb4f12550>]
2022-02-26 23:01:31,122 __init__.py:0595 DEBUG searched service: <homekit.controller.ble_impl.gatt.Service object at 0xffffb4ec37f0>
2022-02-26 23:01:31,123 __init__.py:0604 DEBUG char: 00000050-0000-1000-8000-0026bb765291 pairing.pairings
2022-02-26 23:01:31,123 __init__.py:0604 DEBUG char: 0000004f-0000-1000-8000-0026bb765291 pairing.features
2022-02-26 23:01:31,123 __init__.py:0604 DEBUG char: 0000004e-0000-1000-8000-0026bb765291 pairing.pair-verify
2022-02-26 23:01:31,123 __init__.py:0604 DEBUG char: 0000004c-0000-1000-8000-0026bb765291 pairing.pair-setup
2022-02-26 23:01:31,218 __init__.py:0604 DEBUG char: e604e95d-a759-4817-87d3-aa005083a0d1 protocol.service-id
2022-02-26 23:01:31,218 __init__.py:0618 DEBUG searched char: <homekit.controller.ble_impl.gatt.Characteristic object at 0xffffb4f12c40> 34
2022-02-26 23:01:31,218 controller.py:0484 DEBUG setup char: <homekit.controller.ble_impl.gatt.Characteristic object at 0xffffb4f12c40> <homekit.controller.ble_impl.device.Device object at 0xffffb6c7d130>
2022-02-26 23:01:31,219 __init__.py:0110 DEBUG #1 ios -> accessory: send SRP start request
2022-02-26 23:01:31,219 __init__.py:0626 DEBUG entering write function [
  <6, b'\x01'>,
  <0, b'\x01'>,
]
2022-02-26 23:01:31,220 __init__.py:0637 DEBUG sent 00020322000b000901010106060101000101
2022-02-26 23:01:32,221 __init__.py:0646 DEBUG reading characteristic
2022-02-26 23:01:33,463 __init__.py:0651 DEBUG control field: 2, tid: 3, status: 0, length: 413
2022-02-26 23:01:33,464 __init__.py:0662 DEBUG received 0203009d0101ff06010203ff0fd76bd2ad114f6bc048b4079bed4f36af58040efc0c2aab55551d274fb2c361f32f33f8b7f64bb8e1cb4c1f9d9160cb526befe3b3761c6a1fe6337c82314f770e461a4c229eadd6870c8bdc50e54e138d03e6b1bf75a9434226c4e9999f37da718c09b9b42f9e57b3f846d61e8c0a6c527e01f8add736920650a0e57488041729cf4aabbeafec9b06e7632353e988f2def1a9c75a66a6871ea54140f31f66e4f28297e9c9f65042ec1ff7e97568511c9159da5a855c67d1262a3462843f00a87058e87d8cfbe30a5fd768711e49af35f359c113b470774cbee06c28a5248d423808736d54aaa5681ed848d1c67e2efb54fa9d79fa28c377ce6f019adc74e5e4ad0381c97e756f62b5453ba79b0d26bee8c79c6409e0a3c3766ec228d72d83340f947a6f87973a2db8638bcdd362fd85abfa8914f25c085c03dd6a62979b198e4789ef9566d6062becb9c83f453f46f67de10fedebd71baa50cb6b76a78c270ed80def724214fea5fc4b54cd3947df81f11f085e160a80363102a0265b3465fe977acdbc021018c0ac6e026ab57e9a91ba450454a908
2022-02-26 23:01:33,464 __init__.py:0663 DEBUG decode 01ff06010203ff0fd76bd2ad114f6bc048b4079bed4f36af58040efc0c2aab55551d274fb2c361f32f33f8b7f64bb8e1cb4c1f9d9160cb526befe3b3761c6a1fe6337c82314f770e461a4c229eadd6870c8bdc50e54e138d03e6b1bf75a9434226c4e9999f37da718c09b9b42f9e57b3f846d61e8c0a6c527e01f8add736920650a0e57488041729cf4aabbeafec9b06e7632353e988f2def1a9c75a66a6871ea54140f31f66e4f28297e9c9f65042ec1ff7e97568511c9159da5a855c67d1262a3462843f00a87058e87d8cfbe30a5fd768711e49af35f359c113b470774cbee06c28a5248d423808736d54aaa5681ed848d1c67e2efb54fa9d79fa28c377ce6f019adc74e5e4ad0381c97e756f62b5453ba79b0d26bee8c79c6409e0a3c3766ec228d72d83340f947a6f87973a2db8638bcdd362fd85abfa8914f25c085c03dd6a62979b198e4789ef9566d6062becb9c83f453f46f67de10fedebd71baa50cb6b76a78c270ed80def724214fea5fc4b54cd3947df81f11f085e160a80363102a0265b3465fe977acdbc021018c0ac6e026ab57e9a91ba450454a908
2022-02-26 23:01:33,465 __init__.py:0667 DEBUG leaving write function [
  <TlvTypes.State, 2>,
  <TlvTypes.PublicKey, b'\x0f\xd7k\xd2\xad\x11Ok\xc0H\xb4\x07\x9b\xedO6\xafX\x04\x0e\xfc\x0c*\xabUU\x1d\'O\xb2\xc3a\xf3/3\xf8\xb7\xf6K\xb8\xe1\xcbL\x1f\x9d\x91`\xcbRk\xef\xe3\xb3v\x1cj\x1f\xe63|\x821Ow\x0eF\x1aL"\x9e\xad\xd6\x87\x0c\x8b\xdcP\xe5N\x13\x8d\x03\xe6\xb1\xbfu\xa9CB&\xc4\xe9\x99\x9f7\xdaq\x8c\t\xb9\xb4/\x9eW\xb3\xf8F\xd6\x1e\x8c\nlR~\x01\xf8\xad\xd76\x92\x06P\xa0\xe5t\x88\x04\x17)\xcfJ\xab\xbe\xaf\xec\x9b\x06\xe7c#S\xe9\x88\xf2\xde\xf1\xa9\xc7Zf\xa6\x87\x1e\xa5A@\xf3\x1ff\xe4\xf2\x82\x97\xe9\xc9\xf6PB\xec\x1f\xf7\xe9uhQ\x1c\x91Y\xdaZ\x85\\g\xd1&*4b\x84?\x00\xa8pX\xe8}\x8c\xfb\xe3\n_\xd7hq\x1eI\xaf5\xf3Y\xc1\x13\xb4pwL\xbe\xe0l(\xa5$\x8dB8\x08smT\xaa\xa5h\x1e\xd8H\xd1\xc6~.\xfbT\xfa\x9dy\xfa(\xc3w\xceo\xdct\xe5\xe4\xad\xc9~uob\xb5E;\xa7\x9b\r&\xbe\xe8\xc7\x9cd\t\xe0\xa3\xc3vn\xc2(\xd7-\x834\x0f\x94zo\x87\x97:-\xb8c\x8b\xcd\xd3b\xfd\x85\xab\xfa\x89\x14\xf2\\\x08\\\x03\xddjb\x97\x9b\x19\x8eG\x89\xef\x95f\xd6\x06+\xec\xb9\xc8?E?F\xf6}\xe1\x0f\xed\xeb\xd7\x1b\xaaP\xcbkv\xa7\x8c\'\x0e\xd8\r\xefrB\x14\xfe\xa5\xfcKT\xcd9G\xdf\x81\xf1\x1f\x08^\x16\n\x8061\x02\xa0&[4e\xfe\x97z\xcd\xbc'>,
  <TlvTypes.Salt, b'\x18\xc0\xacn\x02j\xb5~\x9a\x91\xbaE\x04T\xa9\x08'>,
]
2022-02-26 23:01:33,466 __init__.py:0127 DEBUG #3 ios -> accessory: send SRP verify request
2022-02-26 23:01:33,668 __init__.py:0626 DEBUG entering write function [
  <6, b'\x03'>,
  <3, b'\x05mS\x06\xbb\\\xef\xd7\xb0\xe1\xf64.yA[vGA7\x9f\xb8\t\xb7\x1ffV\xf6p\x1e]\xb2\x1a\x9fs\xbe\x01\'k\x86\xfc\x9e+\x16\xd0\x170\xd0\xa1]\x89UJq\xa2\xce\xa8\xe8Q\xdd\x1a(.\x8fw\xe2\xe5!\xaaMj2M\x15\x06\x1e\x840\xeb\xf9Q\x19\\\xe7\xe7\x81s"\xe03z1\x8f\xb8\x06\x89\x08\x9ek?\xdal\xbb\xeb\xbe\xca\xbb\xe5\xd9Hdz\xd1\x94u\xfd\x11,\xe2_n}\xe7\xc1&\x12,"\xc6\x187*\xdd\xee\x99\x9a\x1f\xbd1\x1d\xe4/\xba\x10I \xed\x06<6l\xa9\xe8\x13\x8c\x14\x14\xe4\xb2\xad\xa3\xaf\xd9k\xe3\xce\\\xac\xbd\x80\x98h\xf4\xc9,\xaa\xb1!\x14\x180d\xf3\xa7\xef,\xe0\x86\x17\xf8\xc6\x96\x1bs5\x848H\x91\xb5\xa1\xb0\xdd\xf6\xdb-\x82\xf5\xa5\xe9\x9d\xdc\x8b\x9e1#0\xf4\xc1\xd2\xf5\xf3\x14N\xd2\xa2Q\x1eo\xb1d\xc5v8\xc8J6V\xab\xe0e;r\xdc[bzo\xe8b\x9f\xc3\x96\xde\xedd+j\xe9\xce\xe8m\x0e\x8d\xb4\tGFX\x85a\x8a\xb3\x0f\xc7&\x157u\x8fI\x0e4\x1a\x97\x12\xddxx\xd7q\xfb\xb5ha\x8aN4N\x9d\xe7/\x9a\xa3Tg~#H\x07\xa6\xd15\xc6\x0bu>]f\x8f`\xfe\xd9pf\x01\x9d_\x85*\xc4\x04:\x95$\xa6y\xa9#\xe7\x8e(E*\xbb<azw1 \xb1\xdd>\xe3\x18[5\xe5l\x1cPr\x08s\xb7\x14}l\x06\xc6nG\xf4}\n\xba\x0b\xa9\x01\x15z\xb1\xc3'>,
  <4, b'\xd97\x8e3:\xf1x\x17\xb2w\x9b\x8d-\xc1\xe8\xc4Q\xf74<\x15\xa2\xacg\xcf6\xc8j= \xa3C\xbd5\xb0\x84B\xe3\xd8-\xcf\xbe\xa6\xe5\x01\xb82\xd10\xe1\xc6\xc9{\x07>\x0b\xb2U\x863\xb1-\xfd\xc7'>,
]
2022-02-26 23:01:33,669 __init__.py:0637 DEBUG sent 0002252200d00109010101ff06010303ff056d5306bb5cefd7b0e1f6342e79415b764741379fb809b71f6656f6701e5db21a9f73be01276b86fc9e2b16d01730d0a15d89554a71a2cea8e851dd1a282e8f77e2e521aa4d6a324d15061e8430ebf951195ce7e7817322e0337a318fb80689089e6b3fda6cbbebbecabbe5d948647ad19475fd112ce25f6e7de7c126122c22c618372addee999a1fbd311de42fba104920ed063c366ca9e8138c1414e4b2ada3afd96be3ce5cacbd809868f4c92caab12114183064f3a7ef2ce08617f8c6961b733584384891b5a1b0ddf6db2d82f5a5e99ddc8b9e312330f4c1d2f5f3144ed2a2511e6fb164c57638c84a3656abe0653b72dc5b627a6fe86201ca9fc396deed0381642b6ae9cee86d0e8db40947465885618ab30fc7261537758f490e341a9712dd7878d771fbb568618a4e344e9de72f9aa354677e234807a6d135c60b753e5d668f60fed97066019d5f852ac4043a9524a679a923e78e28452abb3c617a773120b1dd3ee3185b35e56c1c50720873b7147d6c06c66e47f47d0aba0ba901157ab1c30440d9378e333af17817b2779b8d2dc1e8c451f7343c15a2ac67cf36c86a3d20a343bd35b08442e3d82dcfbea6e501b832d130e1c6c97b073e0bb2558633b12dfdc7
2022-02-26 23:01:34,672 __init__.py:0646 DEBUG reading characteristic
2022-02-26 23:01:34,675 device.py:0109 DEBUG read failed: <homekit.controller.ble_impl.gatt.Characteristic object at 0xffffb4f12c40> Not connected
object of type 'NoneType' has no len()
2022-02-26 23:01:34,675 pair_ble.py:0075 DEBUG object of type 'NoneType' has no len()
Traceback (most recent call last):
  File "/home/kevin/.local/lib/python3.9/site-packages/homekit/pair_ble.py", line 68, in <module>
    finish_pairing(pin_function())
  File "/home/kevin/.local/lib/python3.9/site-packages/homekit/controller/controller.py", line 505, in finish_pairing
    response = write_fun(request, expected)
  File "/home/kevin/.local/lib/python3.9/site-packages/homekit/controller/ble_impl/__init__.py", line 644, in write
    while len(data) == 0:
TypeError: object of type 'NoneType' has no len()
homelab:~:% 
jlusiardi commented 2 years ago

I have a suspicion, that characteristic.read_value() returns None instead of an empty list. Can you try with a special branch of this project? It is called fix_231.

Zoneykid commented 2 years ago

One thing I forgot to mention is I kept getting the following error File "/home/kevin/homekitble/homekit_python-timed_write_ble/homekit/pair_ble.py", line 72, in <module> finish_pairing = controller.start_pairing_ble(args.alias, args.mac, args.adapter, args.auth_method) File "/home/kevin/homekitble/homekit_python-timed_write_ble/homekit/controller/controller.py", line 583, in start_pairing_ble pair_method = self._get_pair_method(auth_method, feature_flags) File "/home/kevin/homekitble/homekit_python-timed_write_ble/homekit/controller/controller.py", line 364, in _get_pair_method raise PairingAuthError(f'auth_method: invalid value "{str(auth_method)}"') homekit.exceptions.PairingAuthError: auth_method: invalid value "sw"

Which I was able to resolve with some help by modifying pair_ble.py to change line 72 from args.auth_method to ['auto', 'hw', 'sw'].index(args.auth_method)

As for the fix_231 branch, I get this blelog.txt

jlusiardi commented 2 years ago

Ok, so you already used the master branch in the first place? Could you please also give it a shot with 0.19.0?

jlusiardi commented 2 years ago

Which I was able to resolve with some help by modifying pair_ble.py to change line 72 from args.auth_method to ['auto', 'hw', 'sw'].index(args.auth_method)

I'll have a quick look

Zoneykid commented 2 years ago

Ok, so you already used the master branch in the first place? Could you please also give it a shot with 0.19.0?

The build that gets installed through pip is 0.19.0, and was the first one I tried, then the timed write branch, just now I also grabbed the master and installed that manually (pip install showed 0.18.0), which gave me the same error.

`2022-02-27 22:10:52,692 init.py:0658 DEBUG sent 00021a2200d00109010101ff06010303ffb4dfd90614fd89654c26d3acfcbba916bd24102220609fdcf8c9af0469c579f2ec98ea4aa7f68d0d580b80300df06f8e23b4ec7798b7e402abc033e7d4f2661a661365d0b6a76e4689edda359c7eca509bb6a51fa7ad5916a84de71b8fe45c54178ff577431116c31d0728247220f13f6cd44530b4c3b54e6fe1b1b550f9852da943ad35854d119938c56f239308abae292adc37aa7d19be3e9d2bea544382804507783b5a98fc7f2829efa247883ac431e23beb643172da0c1e1a06eb758606599b33a282c63f4777dc9923d1513c2bc945a5780e3d5b91b77eddec9e754c5f6904faef7ca3daf9e3c7fe3ec522c3385e12ad0319f78b6d9f1801cadc98fcd4840381c16962527e24c9ff5a833c10f9b2d3aef02b266a792941a1511eba56497ab56bbecf490557795c66b11f1e41fa2558db88085edc1f463506c505266c7cea5feb16d5e88a7d8df84c4f5ad2650d896203475bf67bf3adfa2cea14309e3cd714b21bba650a709d87c81a83333edb27b6dd1e07da1b729777902eed619687e634d01304400148ab1672f68a850c427433199e033c1dd269c52868cbe48173d162c7604b81b9a46ba5ef9cbf4d368b8466548d5cac6b84df9907c03cbe3b73f31305f00dd2

2022-02-27 22:10:53,696 init.py:0667 DEBUG reading characteristic

2022-02-27 22:10:53,698 device.py:0112 DEBUG read failed: 0000004c-0000-1000-8000-0026bb765291 Not connected object of type 'NoneType' has no len()

2022-02-27 22:10:53,698 pair_ble.py:0080 DEBUG object of type 'NoneType' has no len() Traceback (most recent call last): File "/home/kevin/.local/lib/python3.9/site-packages/homekit/pair_ble.py", line 73, in finish_pairing(pin_function()) File "/home/kevin/.local/lib/python3.9/site-packages/homekit/controller/controller.py", line 609, in finish_pairing response = write_fun(request, expected) File "/home/kevin/.local/lib/python3.9/site-packages/homekit/controller/ble_impl/init.py", line 665, in write while len(data) == 0: TypeError: object of type 'NoneType' has no len()`

Part of me also wonders if this might just be something specific to Nanoleaf as even when I use nrfConnect on my phone or the nrf BLE tool to try and read profiles it'll disonnect me pretty quick. And should the manufacturer data be malformed like that? Could it potentially even be interference from neighboring bulbs or devices?