GATT API bluez - MI band 2 - bluetooth-lowenergy

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.

Related

BLE: HM10 indicate no read property when characteristic has read property

I am attempting to use HM10 as central to read data from a sensor. The HM10 has been flashed with the latest firmware V710 to use the self learn functionality.
Here is the list of messages I am sending and receiving from the HM10
First I configure the HM10 as central and turn on some notifications. Then I connect to the MAC address of the sensor. I use the AT+FINDSERVICES? command to get the list of services, then find all the characteristics in the range of that uuid. The characteristics I am interested in is 0021.
But here is when the problems start. If I try to read that characteristic I get OK+DATA-ER, which the datasheet the characteristic does not have a read property. Same thing with notify.
But from the AT+CHAR command we can see handle 0021 has both read and notify. I have also tired reading from 001E handle and I get the same error. I am able to read data like the device name from another handle so I am able to get some data off the sensor.
I am wondering if the OK+DATA-ER response can mean something else? Or if the characteristic handle isn't correct somehow. If that were the case how would I find the correct handle?
I have tried connecting to the sensor on my iphone using the LightBlue app and I am able to both read and subscribe to the notification. I have also tried cloning the sensor as a virtual device on LightBlue and I am able to read and subscribe from the HM10 to the phone. So the issue seem to be between the HM10 and the sensor specifically and not with either device individually.
LightBlue UUID
LightBlue read data
I figured it out. Turned out to be a security issue. The sensor would allow connection but no data would be accessible unless the connection was encrypted.
The BLE sensor required pairing when it first connect to a phone and does not subsequently so I missed that fact when I was trying to connect to it via the HM-10.
I don't believe the HM-10 supports pairing connection. I tried setting AT+TYPE to other than 0 but it would no longer connect to the sensor. I would get OK+CO11A but it wouldn't finish connecting.
I switched to an ESP32 board and used
BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT);
This allowed me to read and subscribe to the characteristic.

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!

Sending and receiving data over Bluetooth Low Energy (BLE) using Telit BlueMod+SR

We are looking at using the Telit BlueMod+SR chip in a hardware idea we are working on. Towards that I've been trying to build a Bluetooth Low Energy (BLE) server simulation using the Telit BlueEva+SR evaluation board driven over USB by a Python script.
The two relevant manuals appear to be:
BlueMod+SR AT Command Reference
Terminal I/O Profile Client Implementation Guide (though I'm implementing the server)
(N.B. these are available here but are behind a register/login.)
I'm stuck on something basic: how to send or receive data. I understand that this is done by setting the value of a Generic Attribute Profile (GATT) service's characteristic. The BlueMod+SR already has the GATT service characteristics that I need (a UART data TX characteristic and a UART data RX characteristic) on its Terminal I/O Service. The UUID's of the characteristics I need are given in the Terminal I/O Profile Client Implementation Guide but I cannot see how to read from nor write to them. The AT Command Reference has a section on GATT Server commands but the only one listed, +LEATTRIB, is for defining the attributes for a service (and the ones I need are already defined).
What are the commands I need to read and write the values for the characteristics UART Data TX, UART Data RX, UART Credits TX, and UART Credits RX?
It turns out that I did not need to use the credit mechanism, that's handled for me. So to write to the TX characteristic I can either connect to BLE and just write the data, or use the multiplexing and write the data to channel 0x01 (Terminal I/O). Reading the RX characteristic si similarly just reading the serial connection.

Can I read iBeacon data using Arduino?

I am using an HM-10 module and Arduino UNO.
My requirement is to read data from ibeacons near me using Arduino. Is it possible? I have not been able to find any articles on this. All articles talk about connecting your android phone with arduino. Any idea?
Yes, it is possible. I'm using an HM-10 as an iBeacon detector (linksprite.com BLE 4.0 shield), and it is successfully detecting a RadBeacon running in iBeacon mode. Firmware on my HM-10 is version 540.
Before it would detect the RadBeacon, I had to send the HM-10 the following commands:
AT+ROLE1
AT+IMME1
AT+RESET
Then I used the AT-DISI? command, and the serial monitor is showing the broadcast received from the RadBeacon (and one other beacon) as follows (for example):
OK+DISISOK+DISC:4C000215:2G234454CF6D5A0FADF2F4911BA9FFA7:00000001AC:0CF3EE041CCE:-052OK+DISC:00000000:00000000000000000000000000000000:0000000000:B9782E08068C:-071OK+DISCE
In this example, the HM-10 is detecting my RadBeacon which has UUID of 2G234454...with signal strength of -052. It is also detecting another BLE beacon (my AppleTV downstairs) with UUID of B9782E08068C with signal strength of -071.
I'm definitely not very knowledgable about any of this stuff, but it seems to be working for me so far. Next challenge for me will be to figure out how to parse the text data being received. I'm mostly interested in the distance/signal strength data in order to trigger an action when the RadBeacon gets very close to the HM-10.
[Full disclosure: I jumbled some of the UUID numbers above since I'm not sure if any of this information is private or hackable or whatever]
[By the way, the nRF8001 BLE Shield will not do this since it only runs in peripheral mode.]
Yes, you can get the Min and Max number of the nearby iBeacons.
You need to Attach hm-10 to Arduino Uno.
Try using this Library : https://github.com/dinosd/BLE_PROXIMITY
You can configure suitable AT commands if you want to configure it. But it should work with default settings as well.
Use SoftwareSerial to access HM-10.
In firmware version V539 of the HM-10, it adds an AT command to list nearby iBeacons. The command is AT+DISI?. You would simply need to set up the Arduion to send that command over a serial port and parse the data it returns.

HM10 ble change characteristic value AT command Arduino

Can anyone help me with the AT command to write characteristic value, Or how to send data from arduino to another ble device using Hm10 module.
The HM10 after sending the AT+START, does advertise packets, and can detect the service and characteristic, But the characteristic value is the default 0x00, How can I change that?
Have checked the data sheet multiple times but can not find an AT command that is capable of doing the same.
UPDATE: Similar problem with setting the HM10 in Central Mode:
Central Mode Setup!
1) AT+ROLE1 - Set up to Central Mode
2) AT+IMME1 - Start from RESET
3) AT+SHOW1 - Show discovered devices
4) AT+DISC? - Discover Devices
Get Device MAC ID,
5) AT+CON[MAC ID]
RESULT: Always gives OK+CONNA and after 10seconds OK+CONNF
I am confused, Use of "AT+START" before "AT+DISC?" causes AT+START to not work and viceversa.
Using AT+START results into a loop of OK+CONN followed by OK+LOST continuously and no more AT commands are accepted. I believe it does result in a
Can you advice on the right order?
Using LightBlue iOS app as the peripheral. How am I to select a service and subscribe to a characteristic to receive data from the application?
Thank You.
There is no AT command to set a characteristic value.
The HM10 is a serial-port emulation device - whatever serial data you send to the HM10 module (aside from the AT commands) is made available on it's BLE characteristic. Unfortunately the data sheet doesn't document the service and characteristics, but this code suggests that the serial RX/TX characteristic is 0000ffe1-0000-1000-8000-00805f9b34fb
So, data written to the serial port should appear as the value of that characteristic. Data written to that characteristic should be delivered out of the TX serial port pin on the HM10 module.
This thread is a bit dated. But the HM-1X firmware now supports changing the characteristics of a module.
"AT+CHAR?" Will get the current characteristic setting for RX/TX
"AT+CHAR0xFFFF" will set the TX/RX characteristics to 0xFFFF
Send: AT+CHAR0xAAA0
Recv: OK+Set:0xAAA0
These features were added v518.
If you need to update your firmware,
Link to Huamao's download site.
I don't have enough reputation to comment on Ladvien's answer, but...
Just a word of warning regarding updating the firmware with a new version from Huamao's download site. http://www.jnhuamao.cn/download_rom_en.asp?id=83
In my experience there were issues with V539, which prevented the firmware operating as an iBeacon - and there may be other problems.
I was fortunately enough to find someone emailed me a copy of the V538 firmware and was able to downgrade again.
Huamao doesn't have old versions of the firmware available for download and AFIK there is no way to backup your current firmware version.
But it was possible to downgrade from V539 back to V538 if you have the bin file for V538 etc. i.e At least up as far as V539 the firmware does allow downgrades and was not checking version numbers to only allow upgrades.
No need to use any AT-commands to send data as it works like transparent serial. Currently it works good to upload sketches from iOS devices to Arduino. Check out http://www.apploader.info

Resources