mjg59 / python-tikteck

Python module for controlling Tikteck Bluetooth LED bulbs
MIT License
26 stars 7 forks source link

Porting to GO. #2

Closed roylee17 closed 6 years ago

roylee17 commented 8 years ago

Hi,

I've been working on a BLE library in GO language, and is trying to port the python-tikteck to it. Wrote up equivelent / similar code, but haven't got it work yet. Also having problem to get the BluetoothSocket.py work, otherwise, it'd be helpful to debug by comparision the hcidump or in program logs.

Traceback (most recent call last):
  File "./bb.py", line 10, in <module>
    bulb.connect()
  File "/mnt/roylee17/git_repo/python-tikteck/tikteck/__init__.py", line 104, in connect
    self.sock.connect_l2(0, dest, cid=4, addr_type=BDAddr.TYPE_LE_PUBLIC)
  File "/mnt/roylee17/git_repo/python-tikteck/tikteck/BluetoothSocket.py", line 101, in connect_l2
    self._connect(sa_str)
  File "/mnt/roylee17/git_repo/python-tikteck/tikteck/BluetoothSocket.py", line 96, in _connect
    raise IOError(get_errno(), os.strerror(get_errno()))
IOError: [Errno 111] Connection refused

I'm wondering if you'd take a look and see if any obvious point missing?

https://github.com/currantlabs/ble/tree/master/examples/devices/tikteck

2016/07/18 15:30:57 found pair char 000102030405060708090A0B0C0D1914, h: 0x1A, vh: 0x1B
2016/07/18 15:30:57 pairing req: E0 D0 84 06 56 85 14 8B A7 3E 29 01 A2 8E 84 97
2016/07/18 15:30:57 pairing pkt: 0C 00 01 02 03 04 05 06 07 E0 D0 84 06 56 85 14 8B
2016/07/18 15:30:57 pairing rsp: 0D E0 C7 A4 8C C1 6A D3 00 44 AE 2A 30 F7 65 A8 95
2016/07/18 15:30:57 sk: B7 C3 0D 25 BC 6C 8D 4A 17 2E D5 85 EC DC 1D BB
2016/07/18 15:30:57 packet: [ DC 07 00 00 00 FF FF C1 69 69 FF 00 00 80 00 00 00 00 00 00 ]
2016/07/18 15:30:57 enc_packet: [ DC 07 00 EB A3 F9 1B BB 50 D6 D9 20 5C 4C 6E 27 CA DE 94 A1 ]
2016/07/18 15:30:57 found command char 000102030405060708090A0B0C0D1912, h: 0x14, vh: 0x15

Write request to pair char

< ACL data: handle 64 flags 0x00 dlen 24
    ATT: Write req (0x12)
      handle 0x001b value  0x0c 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0xe0 0xd0 0x84 0x06 0x56 0x85 0x14 0x8b
> ACL data: handle 64 flags 0x02 dlen 5
    ATT: Write resp (0x13)
< ACL data: handle 64 flags 0x00 dlen 7

Read response from pair char

    ATT: Read req (0x0a)
      handle 0x001b
> HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 2
> ACL data: handle 64 flags 0x02 dlen 22
    ATT: Read resp (0x0b)
      0000: 0d e0 c7 a4 8c c1 6a d3  00 44 ae 2a 30 f7 65 a8  ......j..D.*0.e.
      0010: 95                                                .

Write to command char

< ACL data: handle 64 flags 0x00 dlen 27
    ATT: Write req (0x12)
      handle 0x0015 value  0xdc 0x07 0x00 0xeb 0xa3 0xf9 0x1b 0xbb 0x50 0xd6 0xd9 0x20 0x5c 0x4c 0x6e 0x27 0xca 0xde 0x94 0xa1
> ACL data: handle 64 flags 0x02 dlen 5
    ATT: Write resp (0x13)
< HCI Command: Disconnect (0x01|0x0006) plen 3
    handle 64 reason 0x13
    Reason: Remote User Terminated Connection
> HCI Event: Command Status (0x0f) plen 4
    Disconnect (0x01|0x0006) status 0x00 ncmd 1
evanpurkhiser commented 8 years ago

I'm actually also working on porting this library over to golang, but it looks like you're a little farther along than me. I'm planning to do some more work on this tonight and will post up any findings I have here as well :-)

evanpurkhiser commented 8 years ago

Here's some of the work I've done: https://github.com/EvanPurkhiser/go-tikteck

roylee17 commented 8 years ago

Up to the point, the byte sequences seem to be the same. Guess I missed something in the command encryption, or else. I'll try your implementation when you got the command part, and hook up the ble part.

evanpurkhiser commented 8 years ago

I'm glad you opened this issue, as I did not know about the ble library :-) I was going to attempt to use paypal/gatt (which you also seem to be a large contributor of!), but was having some difficulty understanding it.

I gave your example code a try to see if I might be able to debug it, but it seems to hang at discovering the device

2016/07/19 11:33:24 dev: hci0 up
2016/07/19 11:33:24 dev: hci0 reset
2016/07/19 11:33:24 dev: hci0 down
2016/07/19 11:33:24 dev: hci0 opened

I'll be out of town for the next week, so probably won't have any updates on this just yet.

roylee17 commented 8 years ago

By example and "discovering", I guess you're trying examples/explorer? If that's the case, you can use parameter -name or -addr to specify which device to explorer. You can try examples/scanner to find out their name and address.

Issues and PR are welcome.

evanpurkhiser commented 8 years ago

Sorry to say I'll be abandoning this. I've bought some Philips Hue bulbs which are much better supported.

ghost commented 6 years ago

hi.. its a little late :p but you have continued this project? tks