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

Trying on a Honor 4 Band #1

Closed
JulienMaille opened this issue Sep 1, 2019 · 5 comments
Closed

Trying on a Honor 4 Band #1

JulienMaille opened this issue Sep 1, 2019 · 5 comments

Comments

@JulienMaille
Copy link

Ok so I'm a total newbie with BLE devices. Here is what I got after a few attempts. It looks like I had to turn bluetooth off on my phone and have the band in an "unpaired" state.

DEBUG:asyncio:Using selector: SelectSelector
DEBUG:bleak.backends.dotnet.discovery:Received F4:BF:80:5B:DA:9B: Unknown.
DEBUG:bleak.backends.dotnet.discovery:Received C8:D0:83:C2:CB:7B: Unknown.
DEBUG:bleak.backends.dotnet.discovery:Received 3A:A9:D6:34:D7:C8: Unknown.
DEBUG:bleak.backends.dotnet.discovery:Received F4:BF:80:5B:DA:9B: Unknown.
DEBUG:bleak.backends.dotnet.discovery:Could not remove event handlers: unknown event handler...
DEBUG:bleak.backends.dotnet.discovery:Received 3A:A9:D6:34:D7:C8: Unknown.
DEBUG:bleak.backends.dotnet.discovery:3 devices found. Watcher status: 3.
DEBUG:bleak.backends.dotnet.discovery:Received C8:D0:83:C2:CB:7B: Unknown.
DEBUG:bleak.backends.dotnet.discovery:Received F4:BF:80:5B:DA:9B: Unknown.
DEBUG:bleak.backends.dotnet.client:Connecting to BLE device @ F4:BF:80:5B:DA:9B
DEBUG:bleak.backends.dotnet.client:Get Services...
Traceback (most recent call last):
[...]
  File \Python\Python37\lib\site-packages\bleak\backends\dotnet\client.py", line 240, in get_services
    "Could not get GATT characteristics for {0}.".format(service)
bleak.exc.BleakDotNetTaskError: Could not get GATT characteristics for Windows.Devices.Bluetooth.GenericAttributeProfile.GattDeviceService.
@JulienMaille
Copy link
Author

JulienMaille commented Sep 1, 2019

Here is what I get with LightBlue
Screenshot_20190901-103752_LightBlue

@zyv
Copy link
Owner

zyv commented Sep 1, 2019

Hi @Nefast, sorry, but I can't be of much help here... it looks to me as if there is nothing wrong about what you are doing, other than using Windows ;-)

The library that I'm using for BLE communication (Bleak) seems to be unable to enumerate services on your device on Windows. I searched their bug tracker and the only relevant issue I could find was this one: hbldh/bleak#60 - not sure if this is the same problem. I don't have Windows and can't really test my demo there. On macOS it seems to work... Bleak also supports Linux, so if you have Linux, maybe you could try if it's working any better there.

Unfortunately, there basically aren't any cross-platform Python packages for BLE communication other than Bleak that I could find. All other packages are either Linux (BlueZ) or macOS (CoreBluetooth) specific, and nobody really seems to care about Windows... so I picked Bleak and hoped it would work for everybody, whereas I can do my development on macOS. Apparently not so easy...

@JulienMaille
Copy link
Author

I'll see if adding delays/retry helps. However the error code mentioned in your links is different.

@JulienMaille
Copy link
Author

@zyv Ok so I simply commented out the exception and it looks like it goes through

DEBUG:bleak.backends.dotnet.client:Connecting to BLE device @ F4:BF:80:5B:DA:9B
DEBUG:bleak.backends.dotnet.client:Get Services...
DEBUG:bleak.backends.dotnet.client:Connection successful.
INFO:lpv2:State: BandState.Connected
DEBUG:lpv2:State: BandState.RequestedLinkParams, sending: 5A 00 0B 00 01 01 01 00 02 00 03 00 04 00 F1 3B
DEBUG:bleak.backends.dotnet.client:Write Characteristic 0000fe01-0000-1000-8000-00805f9b34fb : b'Z\x00\x0b\x00\x01\x01\x01\x00\x02\x00\x03\x00\x04\x00\xf1;'
DEBUG:lpv2:Waiting for state: BandState.ReceivedLinkParams...
DEBUG:lpv2:State: BandState.RequestedLinkParams, received from '0000fe02-0000-1000-8000-00805f9b34fb': 5A 00 26 00 01 01 01 01 02 02 02 00 FE 03 02 00 F4 04 02 00 0A 05 12 00 01 8B 4A 72 A5 82 CE D5 74 9A B6 57 EA 93 1A 81 9D DD 1B
DEBUG:lpv2:Parsed: Packet(service_id=1, command_id=1, command=Command(tlvs=[TLV(tag=1, value=bytes.fromhex('02')), TLV(tag=2, value=bytes.fromhex('00 FE')), TLV(tag=3, value=bytes.fromhex('00 F4')), TLV(tag=4, value=bytes.fromhex('00 0A')), TLV(tag=5, value=bytes.fromhex('00 01 8B 4A 72 A5 82 CE D5 74 9A B6 57 EA 93 1A 81 9D'))]))
INFO:lpv2:Negotiated link parameters: 2, 254, 244, 10, 1, 8B 4A 72 A5 82 CE D5 74 9A B6 57 EA 93 1A 81 9D

@zyv
Copy link
Owner

zyv commented Sep 1, 2019

@Nefast oh wow, that sounds great - thanks for the info! Apparently it's indeed a bug in the BLE communication library, but since I don't use their service discovery functionality and communicate directly with proprietary Huawei service, simply commenting out the exception suffices.

I presume you trimmed the log, because it just shows the first communication step (link negotiation). However, if it runs until the end without any errors and the last entry is the command sent to service 5 (time) without answer, then you are able to set time as well ;-) more to come...

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