BLE gatttool reading serial data from bluno?

908 Views Asked by At

I am trying to send data over BLE from Bluno to a Raspberry Pi (Raspian), bluez 5.50.

Whilst the connection seems to be fine. I am struck in a point where am unable to retrieve serial data from notification handle.

Below is what I tried.

pi@raspberrypi:~ $ sudo gatttool -b <BLE-MAC-ADDRESS> -I
<BLE-MAC-ADDRESS>[LE]> connect
Attempting to connect to <BLE-MAC-ADDRESS>
Connection successful
[<BLE-MAC-ADDRESS>][LE]>
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
[<BLE-MAC-ADDRESS>][LE]>char-read-hnd 0x0025
handle : 0x0025 value : 01
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
[<BLE-MAC-ADDRESS>][LE]>

So the problem here is , Notification handle listener 'listens' to the serial data and returns the value( 2 -> Hex:32) every 1 second from Bluno (as programmed in Adurinosketch).

But when I try to retrieve this value through the command char-read (tried both by handle & uuid) it always returns 01 ?!!!

Ultimately I want to retrieve this value in my Python code (am using Pexpect for this)

Any help / directions appreciated.

1

There are 1 best solutions below

0
On

Ok , Here is what I ended up doing in my Python code to retrieve the value

`

child = pexpect.spawn("sudo gatttool -b <BLUNO-MAC-ADDR> -I")
# Connect to the device.
print("Connecting to Bluno...")
child.sendline("connect")
child.expect("Connection successful", timeout=5)
print(" Connected!")

while True: 
    child.expect("Notification handle = 0x0025 value: ", timeout=10)
    child.expect("\r\n", timeout=10)
    resp = child.before
    print(process_my_data(bytearray.fromhex(resp.decode("utf-8")).decode()))

`