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

little problem on macOS #6

Open
bubez81 opened this issue Jul 26, 2022 · 22 comments
Open

little problem on macOS #6

bubez81 opened this issue Jul 26, 2022 · 22 comments

Comments

@bubez81
Copy link

bubez81 commented Jul 26, 2022

Hello! great I sow the bleak integration.
Unfortunately there is a problem on macOS:
I receive errors: [custom_components.delonghi_primadonna.device] BleakError: Device with address 00:A0:50:1D:99:27 was not found and it's related to https://bleak.readthedocs.io/en/latest/backends/macos.html

#hbldh/bleak#252

@Arbuzov
Copy link
Owner

Arbuzov commented Jul 30, 2022

Got familuar problem on Linux. Looks like this integration conflicts with the other bluetooth.

Checking.

@Arbuzov
Copy link
Owner

Arbuzov commented Jul 31, 2022

Could you please check?
1.1.1
I have added BLE discovery as it was recommended by the Home Assistant community.

@bubez81
Copy link
Author

bubez81 commented Jul 31, 2022

Sure, but I can't see difference...I use this MAC address: 8BB8F40D-4437-3E11-9FEE-97D8C0584A48 because bleak on my Mac can discover only this tipe of ids:
Schermata 2022-07-31 alle 21 55 28
I can see a connection too:
Schermata 2022-07-31 alle 21 55 50

But home assistant:
2022-07-31 21:56:28 WARNING (MainThread) [custom_components.delonghi_primadonna.device] BleakError: Characteristic 00002a00-0000-1000-8000-00805f9b34fb was not found!

This is what I found on the documentation:
mac_addr = (
"24:71:89:cc:09:05"
if platform.system() != "Darwin"
else "243E23AE-4A99-406C-B317-18F1BD7B4CBE"
)

@Arbuzov
Copy link
Owner

Arbuzov commented Aug 2, 2022

That`s interesting. Could you please check if devices are connected? If it is plugin will not establish connection.

@bubez81
Copy link
Author

bubez81 commented Aug 3, 2022

what do you mean? when the plugin establishes the connection i can see that the mac connects to the machine obviously

I tried with a python script:
python3 service_explorer.py INFO:__main__:Connected: True INFO:__main__:[Service] 00035b03-58e6-07dd-021a-08123a000300 (Handle: 14): Unknown INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a000301 (Handle: 15): Unknown (read,write,indicate), Value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' INFO:__main__: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 17): Client Characteristic Configuration) | Value: b'\x00\x00' INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a0003ff (Handle: 18): Unknown (read,write), Value: b'\x00'

this is the script:
https://github.com/hbldh/bleak/blob/develop/examples/service_explorer.py

@bubez81
Copy link
Author

bubez81 commented Aug 3, 2022

if I perform a scan on a different machine (raspberry 4) the characteristics are more:

INFO:__main__:Connected: True INFO:__main__:[Service] 00001801-0000-1000-8000-00805f9b34fb (Handle: 10): Generic Attribute Profile INFO:__main__: [Characteristic] 00002a05-0000-1000-8000-00805f9b34fb (Handle: 11): Service Changed (indicate), Value: None INFO:__main__: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 13): Client Characteristic Configuration) | Value: b'\x02\x00' INFO:__main__:[Service] 00035b03-58e6-07dd-021a-08123a000300 (Handle: 14): Unknown INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a000301 (Handle: 15): Unknown (read,write,indicate), Value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' INFO:__main__: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 17): Client Characteristic Configuration) | Value: b'\x00\x00' INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a0003ff (Handle: 18): Unknown (read,write), Value: b'\x00'

@bubez81
Copy link
Author

bubez81 commented Aug 3, 2022

Maybe it's a bleak version problem, it's possible to use the new one?

@bubez81
Copy link
Author

bubez81 commented Aug 9, 2022

ok I was wrong, the problem is that on mac it is as if the device were registered twice so after the integration has been added it is no longer possible, even from the same mac, to communicate with the machine. I admit that I really don't know how to solve this problem

@Arbuzov
Copy link
Owner

Arbuzov commented Aug 12, 2022

The new version of HA can partially solve it. They added kinda Bluetooth device manager.
But, if you initiate bt session by the other software it will not help, cause coffee machine supports only one bt connection at once.

@bubez81
Copy link
Author

bubez81 commented Aug 12, 2022

yes I'll try with the new version, with the raspberry no problem at all...with the MAC it seems as if it made two connections, one when I add the integration to HA and one when I try to use it and when I try to use it it does not find it because it is already used.
(obviously when I try with the mac I turn off the raspberry)

@bubez81
Copy link
Author

bubez81 commented Aug 12, 2022

in fact if I try to scan without adding the integration I can see from the Mac the Characteristics :
python3 service_explorer.py INFO:__main__:Connected: True INFO:__main__:[Service] 00035b03-58e6-07dd-021a-08123a000300 (Handle: 14): Unknown INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a000301 (Handle: 15): Unknown (read,write,indicate), Value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' INFO:__main__: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 17): Client Characteristic Configuration) | Value: b'\x00\x00' INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a0003ff (Handle: 18): Unknown (read,write), Value: b'\x00'

then if I add the integration a can't perform the scan anymore....from THE SAME MACHINE...it's very strange....

@bubez81
Copy link
Author

bubez81 commented Aug 12, 2022

however I noticed that there is no discovery by HA and I have to add the machine by hand, maybe that's the problem

@Arbuzov
Copy link
Owner

Arbuzov commented Aug 24, 2022

however I noticed that there is no discovery by HA and I have to add the machine by hand, maybe that's the problem

Yes, that`s a next feature in this project. Autodiscovery and status parsing.

@bubez81
Copy link
Author

bubez81 commented Aug 25, 2022

maybe this will solve the problem

@bubez81
Copy link
Author

bubez81 commented Sep 7, 2022

nothing...it's like it makes two connections on macOS...can't understand...it's a bleak and coreBluetooth problem...on the raspberry no issues

@Arbuzov
Copy link
Owner

Arbuzov commented Sep 10, 2022

On my experience bleak is a little bit raw. I got some issues then started bleak in the Docker HA.
Try to exec this in your environment:

import asyncio
import binascii
import uuid
from bleak import BleakClient, BleakScanner
from bleak.exc import BleakError

MAC = "00:A0:50:82:75:CA"
NAME_CHARACTERISTIC = '00002A00-0000-1000-8000-00805F9B34FB'
GENERAL_SERVICE = '00001801-0000-1000-8000-00805f9b34fb'

async def main(ble_address: str):
    device = await BleakScanner.find_device_by_address(ble_address, timeout=20.0)
    async with BleakClient(device) as client:
        services = await client.get_services()
        print("Services:")
        for service in services:
            print(service)
        value = bytes(await client.read_gatt_char(uuid.UUID(NAME_CHARACTERISTIC))).decode('utf-8')
        print(value)

asyncio.run(main(MAC))

if got an issue submit it to the bleak project

@bubez81
Copy link
Author

bubez81 commented Sep 10, 2022

ok...no sense:
(homeassistant) michele@perlhof  ~  python3 service_explorer.py INFO:__main__:Connected: True INFO:__main__:[Service] 00035b03-58e6-07dd-021a-08123a000300 (Handle: 14): Unknown INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a000301 (Handle: 15): Unknown (read,write,indicate), Value: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' INFO:__main__: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 17): Client Characteristic Configuration) | Value: b'\x00\x00' INFO:__main__: [Characteristic] 00035b03-58e6-07dd-021a-08123a0003ff (Handle: 18): Unknown (read,write), Value: b'\x00'

but

(homeassistant) michele@perlhof  ~  python3 provadimamica.py Services: 00035b03-58e6-07dd-021a-08123a000300 (Handle: 14): Unknown Traceback (most recent call last): File "/Users/michele/provadimamica.py", line 21, in <module> asyncio.run(main(MAC)) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete return future.result() File "/Users/michele/provadimamica.py", line 18, in main value = bytes(await client.read_gatt_char(uuid.UUID(NAME_CHARACTERISTIC))).decode('utf-8') File "/opt/homeassistant/lib/python3.10/site-packages/bleak/backends/corebluetooth/client.py", line 262, in read_gatt_char raise BleakError("Characteristic {} was not found!".format(char_specifier)) bleak.exc.BleakError: Characteristic 00002a00-0000-1000-8000-00805f9b34fb was not found!

@bubez81
Copy link
Author

bubez81 commented Jan 4, 2023

I think there is a correlation here hbldh/bleak#1189 (comment)

@codyc1515
Copy link
Contributor

Was this solved, @bubez81? I think BLE support on macOS with HA is not great generally (not specific to this plug-in).

@bubez81
Copy link
Author

bubez81 commented Oct 24, 2023

Solved with an esp32 😂

@codyc1515
Copy link
Contributor

Great - same here. Can you please close the ticket?

Arbuzov pushed a commit that referenced this issue Oct 25, 2023
@bubez81
Copy link
Author

bubez81 commented Oct 25, 2023

Not sure if it's right to close the thicket...I have to try whitout the esp32

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

3 participants