bluetoothbluetooth-lowenergyhci

Send data using over bluetooth using different protocols


I have an app that communicates with a bluetooth device, and I'm trying to replace that app with some code.

I tried using C# InTheHand nuget, Microsoft's Bluetooth LE Explorer, python's sockets and others to send data and see what happens.

But there's something I still don't understand - in each way using different libraries I saw in wireshark a different protocol: ATT, RFCOMM, L2CAP...

When I sniffed my bluetooth traffic from my phone using the app mentioned before, I saw mostly HCI_CMD protocol traffic.

How can I choose the protocol I want to send? Is there a simple package for that? something to read?

Do I need to build the packet myself? including headers and such?

Thank you!

Update: Using Microsoft's Bluetooth LE Explorer I was able to send a packet that lit up my lamp, starting with 02010e10000c00040012(data)
Using bleak I was able to send a packet starting with 02010e10000c00040052(data)
the difference makes the lamp not ligh up and I'm not sure if I can change it via bleak as it's not part of the data I send


Solution

  • I think what you are showing is that bleak does a write without response while MS BLE Explorer does a write_with_response.

    Looking at the Bleak documentation for write_gatt_char that seems to be consistent as response is False by default

    write_gatt_char Parameters:

    • char_specifier (BleakGATTCharacteristic, int, str or UUID). The characteristic to write to, specified by either integer handle, UUID or directly by the BleakGATTCharacteristic object representing it.

    • data (bytes or bytearray) – The data to send.

    • response (bool) – If write-with-response operation should be done. Defaults to False.

    I would expect the following to have the desired effect:

    await   client.write_gatt_char(LIGHT_CHARACTERISTIC, b"\x55\xaa\x03\x08\x02\xff\x00\xff\xf5", True)