JorgePe / BOOSTreveng

Reverse engineering the LEGO BOOST Hub
MIT License
167 stars 34 forks source link

gattlib not working #4

Closed JorgePe closed 7 years ago

JorgePe commented 7 years ago

This works from Ubuntu 17.04 shell:

gatttool -b 00:16:53:A4:CD:7E --char-write-req --handle=0x0e --value=0c018139110a00069B9B647f03

This doesn't:

#!/usr/bin/env python3
from gattlib import GATTRequester, GATTResponse
from time import sleep

req = GATTRequester("00:16:53:A4:CD:7E",True,"hci0")
response = GATTResponse()
req.write_by_handle_async(0x0e, "\x0C\x01\x81\x39\x11\x0A\x00\x06\x9B\x9B\x64\x7F\x03", response)
while not response.received():
    sleep(0.1)
    print(response.received())
print(req.read_by_handle(0x0e))

Output:

['\x13']
['\x0c\x01\x819\x11\n\x00\x06\x9b\x9bd\x7f\x03']

Also replacing with a shorter command like changing LED color

gatttool -b 00:16:53:A4:CD:7E --char-write-req --handle=0x0e --value=080081321151000A

returns

['\x13']
['\x08\x00\x812\x11Q\x00\n']

Something is wrong after 3rd byte ?!?

JorgePe commented 7 years ago

\x81 is > 127, converting to string in python3 works different than python2 think I figured the proper way, have to try

JorgePe commented 7 years ago

Writing bytes(bytearray(b'\x08\x00\x81\x32\x11\x51\x00\x0A')) instead of str(bytearray(b'\x08\x00\x81\x32\x11\x51\x00\x0A')) works.

JorgePe commented 7 years ago

As also just b'\x08\x00\x81\x32\x11\x51\x00\x0A'