dauden1184 / RaspiNukiBridge

Simple Nuki Bridge implementation using asyncio
GNU General Public License v3.0
48 stars 19 forks source link

ERROR: Failed building wheel for aiohttp #26

Closed Felix313 closed 9 months ago

Felix313 commented 11 months ago

Hi all, trying to install this repo with python version 3.11.2 I'm getting an error: aiohttp/_websocket.c:198:12: fatal error: longintrepr.h: No such file or directory

I think its related to: https://github.com/aio-libs/aiohttp/issues/6600 but I dont know how to fix this. Tried installing with aoihttp==3.9.1 which works but then I get an error when trying to pair with the Nuki Lock.

Thank you for your help!

dauden1184 commented 11 months ago

Hi, Please use aoihttp==3.9.1 and post here the error you get when trying to pair

Felix313 commented 11 months ago

Hi @dauden1184, thanks for the quick response. Here is the error:

2023-11-29 18:06:23.871|I|main.py:278|Generatig keys for Nuki <_MAC_> 2023-11-29 18:06:23.872|I|main.py:282|bridge_public_key: <_public_key_> 2023-11-29 18:06:23.873|I|main.py:283|bridge_private_key: <_bridge_private_key_> Task exception was never retrieved future: <Task finished name='Task-1' coro=<Nuki.pair() done, defined at /home/pi/RaspiNukiBridge/RaspiNukiBridge/nuki.py:639> exception=SystemError("PY_SSIZE_T_CLEAN macro must be defined for '#' formats")> Traceback (most recent call last): File "/home/pi/RaspiNukiBridge/RaspiNukiBridge/nuki.py", line 643, in pair cmd = self._prepare_command(NukiCommand.REQUEST_DATA.value, payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/pi/RaspiNukiBridge/RaspiNukiBridge/nuki.py", line 269, in _prepare_command crc = crc16.crc16xmodem(message, 0xffff).to_bytes(2, "little") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

Felix313 commented 11 months ago

Coming to think of crc, it does give a deprication warning during install of requirements.txt but then installs just fine:

DEPRECATION: crc16 is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559 Running setup.py install for crc16 ... done

dauden1184 commented 11 months ago

Try with crc16==0.1.1

Felix313 commented 11 months ago

crc16==0.1.1 is being used. I only altered aoihttp==3.9.1 in requirements.txt. Everything else is untouched:

aiohttp==3.9.1 bleak==0.14.0 crc16==0.1.1 PyNaCl==1.3.0 PyYAML==6.0

dauden1184 commented 11 months ago

I'm running this with python 3.9.2, can you recreate the environment with this version and retry? In the next days I'll work to make it compatible with more recent python versions.

Felix313 commented 11 months ago

I created a python3.9 pyenv. Installation of requirements.txt ran without issues. When trying to pair I get a BleakDBusError - but its different from the one mentioned in the install instructions (I tried with bluez 5.50 and 5.66 - same error):

(nuki_pyenv39) pi@raspberrypi:~/RaspiNukiBridge/RaspiNukiBridge $ python3.9 . --pair MAC
2023-11-30 23:04:58.838|I|__main__.py:278|Generatig keys for Nuki MAC
2023-11-30 23:04:58.839|I|__main__.py:282|bridge_public_key: key
2023-11-30 23:04:58.840|I|__main__.py:283|bridge_private_key: key
2023-11-30 23:04:58.843|I|nuki.py:173|Stop scanning
2023-11-30 23:04:58.843|I|nuki.py:570|Nuki connecting
Task exception was never retrieved
future: <Task finished name='Task-1' coro=<Nuki.pair() done, defined at /home/pi/RaspiNukiBridge/RaspiNukiBridge/./nuki.py:639> exception=BleakDBusError('org.freedesktop.DBus.Error.UnknownObject', 'Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn\'t exist\n')>
Traceback (most recent call last):
  File "/home/pi/RaspiNukiBridge/RaspiNukiBridge/./nuki.py", line 644, in pair
    await self.connect()
  File "/home/pi/RaspiNukiBridge/RaspiNukiBridge/./nuki.py", line 571, in connect
    await self._client.connect()
  File "/home/pi/.pyenv/versions/nuki_pyenv39/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 112, in connect
    device = await BleakScannerBlueZDBus.find_device_by_address(
  File "/home/pi/.pyenv/versions/nuki_pyenv39/lib/python3.9/site-packages/bleak/backends/scanner.py", line 220, in find_device_by_address
    return await cls.find_device_by_filter(
  File "/home/pi/.pyenv/versions/nuki_pyenv39/lib/python3.9/site-packages/bleak/backends/scanner.py", line 249, in find_device_by_filter
    async with cls(detection_callback=apply_filter, **kwargs):
  File "/home/pi/.pyenv/versions/nuki_pyenv39/lib/python3.9/site-packages/bleak/backends/scanner.py", line 95, in __aenter__
    await self.start()
  File "/home/pi/.pyenv/versions/nuki_pyenv39/lib/python3.9/site-packages/bleak/backends/bluezdbus/scanner.py", line 155, in start
    assert_reply(reply)
  File "/home/pi/.pyenv/versions/nuki_pyenv39/lib/python3.9/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
**bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist**
Felix313 commented 11 months ago

Regarding

Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist`

I found this suggestion. I do use an external dongle that is set to hci1, so i tried the sample script:

import asyncio
from bleak import BleakScanner

async def main():
    devices = await BleakScanner(adapter="hci1").discover()
    for d in devices:
        print(d)

asyncio.run(main())

I get the same error message

bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist

dauden1184 commented 11 months ago

Weird, It seems the device is not being recognized by the system? what's the output of hciconfig?

Felix313 commented 11 months ago

Maybe sth to do with the pyenv?

output of hciconfig:

hci1:   Type: Primary  Bus: USB
        BD Address: 8C:88:2B:23:6A:24  ACL MTU: 1021:6  SCO MTU: 255:12
        UP RUNNING
        RX bytes:9257 acl:0 sco:0 events:284 errors:0
        TX bytes:35037 acl:0 sco:0 commands:246 errors:0

hci0:   Type: Primary  Bus: UART
        BD Address: 00:00:00:00:00:00  ACL MTU: 0:0  SCO MTU: 0:0
        DOWN
        RX bytes:0 acl:0 sco:0 events:0 errors:0
        TX bytes:42 acl:0 sco:0 commands:6 errors:0
Felix313 commented 10 months ago

Today I tried restalling everything on the RPI. Unfortunately I still get the same error message.

hciconfig looks the same:


hci1:   Type: Primary  Bus: USB
        BD Address: 8C:88:2B:23:6A:24  ACL MTU: 1021:6  SCO MTU: 255:12
        UP RUNNING
        RX bytes:2253 acl:0 sco:0 events:212 errors:0
        TX bytes:32121 acl:0 sco:0 commands:212 errors:0

hci0:   Type: Primary  Bus: UART
        BD Address: 00:00:00:00:00:00  ACL MTU: 0:0  SCO MTU: 0:0
        DOWN
        RX bytes:0 acl:0 sco:0 events:0 errors:0
        TX bytes:14 acl:0 sco:0 commands:2 errors:0

Any idea what I could try? Maybe install an old version of RPI OS that comes with Python3.9?

Felix313 commented 9 months ago

Still haven't been able to set it up :/ any help would be highly appreciated!

Felix313 commented 9 months ago

finally got everything working using the hacs integration from @ronengr: https://github.com/ronengr/hass_nuki_bt Was facing the same issue with the hacs solution at first - reason seems to be an unstable connection, where the nuki device can be found, but signal is too weak for pairing. Thank you @dauden1184 for your work and help!