Connect to BLE device with gatttool in non-interactive mode

498 Views Asked by At

I'm trying to read data from my weight scale Bluetooth Low Energy device. After the measurement, the scale advertise new data via bluetooth for about a minute. I can read it using gatttool like that:

gatttool -b MAC_ADDRESS -I
connect

The -I option runs the gatttool in interactive mode. Then, after successfull connection I got data like this:

Indication   handle = 0x0012 value: 02 9c 0e e4 07 08 1c 0b 02 0f 
Indication   handle = 0x0012 value: 02 68 0b e4 07 08 1c 0c 03 06 
Indication   handle = 0x0012 value: 02 18 47 e4 07 08 1f 07 11 3a

I can read the value from this fine but I need to do this in gatttool non-interactive mode, so I can read the output of that in my Qt app with QProcess class. gatttool -h doesn't say much about how to just connect with the device. There is no command like: gatttool -b MAC_ADDRESS connect. There are commands to read or write but I don't need this. I just want to connect and wait for the upcoming data from the device. Can anyone tell me how to connect in non-interactive mode using gatttool?

Thanks.

1

There are 1 best solutions below

1
ukBaz On

gatttool is one of the eight tools that have been deprecated by the BlueZ project.

Wouldn't you be better off handling the BLE notification directly in Qt?

e.g: https://doc.qt.io/archives/qt-5.7/qtbluetooth-heartlistener-example.html