BLE Attribute requires authentication although I have paired - bluetooth-lowenergy

(Updated)
I am trying to communicate with a BLE device using command-line or program.
I have paired with this device, using bluetoothctl v5.50:
[bluetooth]# paired-devices
Device XX:XX:XX:XX:XX:XX Mydevice
But when I try to read its characteristics with gatttool, I get the answer Characteristic value/descriptor operation failed: Attribute requires authentication before read/write.
sudo gatttool -b XX:XX:XX:XX:XX:XX -I -t random --sec-level=high
[XX:XX:XX:XX:XX:XX][LE]> connect
Attempting to connect to d2:a7:4c:76:f3:e0
Connection successful
[XX:XX:XX:XX:XX:XX][LE]> char-read-hnd 0x000e
Error: Characteristic value/descriptor read failed: Attribute requires authentication before read/write
[XX:XX:XX:XX:XX:XX][LE]>
I also tried with with bleah and I get the error Error from Bluetooth stack (comerr).
With bluetoothctl, list-attributes does not return anything. And I am unable to read standard characteristic such as 00002a00-0000-1000-8000-00805f9b34fb (Device Name):
[MyDevice]# list-attributes
[MyDevice]# attribute-info 00002a00-0000-1000-8000-00805f9b34fb
Attribute 00002a00-0000-1000-8000-00805f9b34fb not available
Note that the characteristics are readable (I enumerated the device with bleah): 0x000e has READ property.
Can somebody suggest a solution to read such characteristics?

Related

GATT API bluez - MI band 2

I have been trying for a few weeks to connect to the MI Band 2 watch, and read the heart rate characteristic value, but without luck.
I am a little unsure what the procedure is, when we are talking about GATT.
For the API https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/gatt-api.txt I was thinking about using the org.bluez.GattCharacteristic1 interface to read a value out.
I can connect and pair the watch, and get all UUIDs (services, descriptors and characteristics). The heart rate measurement has the following info:
Characteristic
/org/bluez/hci0/dev_CD_1D_69_25_19_5E/service0027/char0028
00002a37-0000-1000-8000-00805f9b34fb
I have tried using the bluetoothctl program to read the value, but getting a "not permitted" feedback.
What is the procedure to read out a characteristic value, using the GATT API.
Your device is using the adopted Heart Rate profile, seeing that 0x2A37 is the adopted characteristic UUID for heart rate measurement. I would recommend that you use the BlueZ command line tools as follows:-
1. Find the handle of the heart rate characteristic using:-
gatttool -b 00:11:22:33:44:55 --characteristics
Replace 00:11:22:33:44:55 with the Bluetooth address of your device. You basically want to find the uuid that contains 2a37 and note down its corresponding 'char value handle'.
2. Find the descriptors at that handle using:-
gatttool -b 00:11:22:33:44:55 char-desc --handle=0xXX
Where XX is the char value handle that you noted down earlier. You should be able to see a couple of characteristic descriptors at that handle. Note down the char handle with uuid 2902.
3- Enable notifications by writing '0100' at that handle using:-
gatttool -b 00:11:22:33:44:55 --sec-level=high --char-write --handle=0xYYYY --value=0100
Where 0xYYYY is the handle of the CCCD descriptor that you noted in step 2. Once this happens, you should start getting indication data, which you can decipher using the temperature data structure found here.
You can find more information about using the BlueZ commands at the following links:-
How can I connect to the FitBit Zip over Bluetooth 4.0 LE on Linux with bluez?
Bluetooth Low Energy: listening for notifications/indications in linux
Using Bluetooth low energy in linux command line
I hope this helps.
Maybe you could try the shell program gatttool or use app like nRF Connect to read.

BlueZ BLE GATT write request (0x12) instead of (0x16)

I am trying to reverse engineer a BLE device for research. The BLE device does not require pairing.
One of the commands that are written that I can see in wireshark is write to a specific handle. When I try to do the same using the Gatttool write request:
sudo gatttool -i hci0 -b 54:6C:0E:21:F5:99 --char-write-req -a 0x0030
-n 110100701301000110010030721000d68c054688df413aa89fb3cfab3d6457172000053958839fa147ac53c129eafc524829bc9ed7655fe96c9f641745c4e07cf044
It uses a 0x16 prepare write request instead and there seems to be some error as well. Below is an image of both captures, the left side is the GAtttool request and the right side is the request done by the phone.
The communication to the right has earlier negotiated a larger MTU. That's why it can send the whole value in one request.

Get BLE data notifications in ubuntu

I defined custom service (NRF51822,S110) to send sensor data. In that I enabled notifications for new data. I can able to receive data, if I enabled notification in NRFconnect app in Android and windows. But I am not able to enable notification in ubuntu 16.04 . I am using bluez gatttool. To get notification I send this command "char-write-req 0x000e 0100" from command line. Please Help me to fix this issue.
In order to receive notifications from a gatt server, you need to write to the CCCD (0x2902) descriptor and use the --listen option. Assuming that the handle of the descriptor is 0x000e, the command you need is as follows:-
gatttool -b 00:11:22:33:44:55 --char-write-req --handle=0x000e --value=0100 --listen
Please see the answers below:-
Bluetooth Low Energy: listening for notifications/indications in linux
Reading Thermometer Data with Bluez Bluetooth Low Energy
I hope this helps.
Sorry. handle 0x000f is correct. But I written as 0x000e. Now issue solved. Thank you.

Raspberryy pi 3 BLE Devices

I am new to android.I have Raspberry pi 3 device.I can connect mobile device to Raspberry pi 3 over classic Bluetooth.now i am confused about Raspberry how to connect mobile device to Raspberry over bluetooth low energy.we can connect BLE device to android device and get Characteristics and can write Characteristics.now i want to do same thing in Raspberry pi 3 like (heart rate monitor,MI band 2)
Do it using a program
You can do it programmatically using DBus Calls. DBus is an interprocess Communication method used in linux. You can use DBus bindings for different languages such as python or C to make the DBus calls and do the operations.
A few links to help you get started :
DBus tutorial - https://dbus.freedesktop.org/doc/dbus-tutorial.html
BLE DBus API - https://elinux.org/images/3/32/Doing_Bluetooth_Low_Energy_on_Linux.pdf
Using Gatttool from terminal
Gatttool is a terminal tool just like hcitool. You can use the following commands to get the thing working:
hcitool lescan Gives you the list of nearby Low Energy Devices
gatttool -b mac_adress_of_le_device -I gives you an interactive session with the mentioned LE device
From the interactive session give connect to connect to the device
primary to get the primary services.
From this result, you can use the handle values to get the list of characteristics of a specific service. characteristics handle
To get the value of a characteristic use char-read-hnd handle
To get the characteristic descriptor, use char-desc handle
to write to a characteristic char-write-req handle value
Hope This helps!

How Can IBM Bluemix Node-RED Iotout node be set up correctly to send command to Device (Arduino)?

I have an Arduino Uno that is successfully registered as a device with IBM IoTF. It can send information to the Bluemix Node-RED app without any issues now.
Now, I would like the Node-RED app to send commands to the device (the Arduino Uno). The Arduino is subscribed to the MQTT without any error. But, it is not receiving any commands from the Node-RED. I followed the directions at the link below to create another flow in Node-RED to show when a command is published and the commands are being shown, so they seem to be going to the MQTT broker. But, the device (Arduino) is not receiving them.
How can I figure out how to get this working?
Node-RED, IOT Foundation Out Node Not Sending Commands
I have the IBM IoT Out Node parameters set as follows:
Authentication: Bluemix Service
Output type: Device command
Device type: Arduino-tempsensor (this is the same string I used for the device type (name) when I registered it in IoTF)
Device ID: I put the MAC address here, should it be more
Command Type: status (I used the word "status" here. Does capitalization matter? Where should I get this value from? I used "status" because it is in the topic: "iot-2/cmd/status/fmt/json" is that correct?)
Format: json (does capitalization matter here?)
data: {"d":{"myName":"Arduino Uno", "temperature":989}} (I used this because it's JSON and I wanted to just see anything at the device)
Name: IBM IoT App Out
I typed up this whole question and then it occurred to me that the test flow to look for the published command should have all of the parameters set to exactly the same as the output. When I tried that, I was not getting the command message coming back. Then, I realized that my mac address (device ID) was capitalized in one place, but not the other. The MAC address (Device ID) I used to register the device was all in caps, so I make the Iot-out node for the command so that it was all capitalized and made the Iot-in node to test for the message so that it was all capitalized. Now it works! Then, I looked back at the device (which was printing to the serial monitor so I could see what was happening) and I am now seeing the messages! So, make sure your parameters follow the same capitaliztion!

Resources