2014-03-17 18:06:54

by Christian Bianchini

[permalink] [raw]
Subject: Re: Bluetooth low energy with gatttool and jawbone

I can try with your idea but if I continue to type commands to read
stuff, try to write, etc... the device doesn't disconnect. I guess
it's a timeout after I dont get or send any data, probably a
power-safe-mode.

i have bluez 4.101 :
ii bluez 4.101-0ubuntu8b1
amd64 Bluetooth tools and daemons


What I dont get is that I can't write any parameters:
char-write-req a 0100
[CON][DC:7A:F8:10:AF:A5][LE]> Characteristic Write Request failed:
Attribute can't be written

I am following this guide to understand how a BLE device is made and
how to access specific information:
http://joost.damad.be/2013/08/experiments-with-bluetooth-low-energy.html

What I understood is that sending 0100 ( 0x01, 0x00 ) each
"functionality" ( that are 3 of them ) should send me a notification
of its status, but I am not able to write anything :(

As soon as I can write the data, I am sure I will have solved my
problem and I can read all the sensors!

Thanks again for your help

On Mon, Mar 17, 2014 at 5:50 PM, Anderson Lizardo
<[email protected]> wrote:
> Hi Christian,
>
> On Mon, Mar 17, 2014 at 12:30 PM, Christian Bianchini
> <[email protected]> wrote:
>> Tried to connect with bluez:
>> $ sudo bluez-simple-agent hci0 DC:7A:F8:10:AF:A5
>> Creating device failed: org.bluez.Error.ConnectionAttemptFailed: Page Timeout
>
> If you are using a 4.x BlueZ, you must run "test-discovery" until the
> device appears, and then attempt the simple-agent command above. This
> will feed an internal cache that allows BlueZ to know that this
> address is from a LE device, not a BR/EDR one. Since BlueZ 5.0, this
> is not necessary anymore.
>
> If this does not work, please post the output from hcidump when you
> run the "bluez-simple-agent" command.
>
>> Stupid question, how do I read the firmware version? Sorry to ask
>> silly questions but this my first attempt to use this kind of "AT
>> commands" via GATT
>
> Given that your connection is dropping after a few seconds, it is
> difficult to run commands on the gatttool prompt before fixing this
> connection timeout issue. Try running test-discovery + simple-agent as
> described above, and then try gatttool again and see if it stays
> connected.
>
>> Here is the dump:
>> [...]
>
> Unfortunately, the log only says your device is disconnecting due to
> "Connection Timeout". Are you getting this same error every time? And
> for how long the link stays up before disconnecting? (you can pass
> "-t" to hcidump to show the timestamp so you can measure easily).
>
> This error usually means there is a poor connection between your
> machine and the device, or that the device "disappeared" (i.e. became
> out of range). Is the device fully charged?
>
> Best Regards,
> --
> Anderson Lizardo
> http://www.indt.org/?lang=en
> INdT - Manaus - Brazil



--
---------------------------
Web/Mobile Developer
Luiis Group
[email protected]


2014-03-19 17:22:09

by Anderson Lizardo

[permalink] [raw]
Subject: Re: Bluetooth low energy with gatttool and jawbone

Hi Christian,

On Wed, Mar 19, 2014 at 12:29 PM, Christian Bianchini
<[email protected]> wrote:
>> Can you try this instead:
>>
>> char-write-req 0x000c 0100
>
> OK this worked but didnt activate any input.

It might be just that the device does not have any notification to
send immediately. Also try reading the descriptor value back (using
char-read-hnd 0x000c) to make sure the correct value was written.

> I tried to get characteristics for the 1? service and I found 3 of
> them, this let me think I have 3 sensors. Can the vibrate motor be a
> sensor as well?

It's hard to guess here, as they are proprietary services (i.e. not
defined by the Bluetooth SIG and not found on
developer.bluetooth.org). Did you find any information about this
device on the internet? I.e. whether someone already reverse
engineered it, of if it is already documented somewhere. Or at least
some sample code.

> The characteristics from this range are:
>
> handle: 0x000a, char properties: 0x18, char value handle: 0x000b,
> uuid: f7c9b162-6658-4390-b53c-1de5e1453654

Note that this characteristic is also writable (the other two are only
notifiable), as shown by the "char properties" value. It could be used
to send commands to the device.

> handle: 0x000d, char properties: 0x10, char value handle: 0x000e,
> uuid: f7c9ba82-6658-4390-b53c-1de5e1453654
> handle: 0x0010, char properties: 0x10, char value handle: 0x0011,
> uuid: f7c9ba91-6658-4390-b53c-1de5e1453654

> I discovered that sending 01 to the 0x000f I get one notification
>
> char-write-req 0x000f 01
> [CON][DC:7A:F8:10:AF:A5][LE]> Characteristic value was written successfully
>
> Notification handle = 0x000e value: 20 0f 1f aa f9 84 d5 e1 78 29 23
> 2d 14 bc fb c4 ef 71

You still need to figure out what those bits mean. They are not
documented in developer.bluetooth.org.

> Probably I need to do a custom activation, because pairing the device
> with the specific app I get a vibration on the device.
>
> I might be on the right track, I would like to know if my discovery
> are right and I am not floating around.

Everything you described here makes sense. But you will need to figure
out how to use those characteristics so you can do what you want.

>> PS: When replying to e-mails on the mailing list, be sure to not
>> top-post (i.e. write your reply before the original message) and
>> remember to trim the original message to only show the relevant part
>> of the original message (like I did above), otherwise it is difficult
>> to follow discussion.
>>
>> Best Regards,
>
> thanks for the advice, I am not really expert on this maillist system :(

No problem, it is just that your e-mails are more likely to be ignored
by others if they get long due to top-posting and not trimming the
original message.

Best Regards,
--
Anderson Lizardo
http://www.indt.org/?lang=en
INdT - Manaus - Brazil

2014-03-19 16:29:33

by Christian Bianchini

[permalink] [raw]
Subject: Re: Bluetooth low energy with gatttool and jawbone

> This error actually means "Write not permitted". One first error is
> that you are trying to write to the characteristic declaration
> attribute, which is always read-only. To enable notification, you
> should write to the Client Characteristic Configuration (CCC)
> descriptor, which for the first characteristic is probably 0x000c (you
> can confirm by running "char-desc 0x000c 0x000c", if it appears one
> attribute with UUID 0x2902, it is a CCC).
>
> Can you try this instead:
>
> char-write-req 0x000c 0100

OK this worked but didnt activate any input.

>
> By the way, I strongly suggest you read a bit more on GATT (there are
> some good resources on bluetooth.org), so you understand better what
> are notifications, descriptors, characteristics, services etc.

I read a lot about it. I understood that I have 2 services:

1) Jawbone service where I should be able to read and active sensors
2) Default service where I can read Firmware, model, etc...

I was able to read everything about the 2? service, and I am happy with that.
I tried to get characteristics for the 1? service and I found 3 of
them, this let me think I have 3 sensors. Can the vibrate motor be a
sensor as well?

Doing char-desc of each of three ranges, I couldn't find something
helpful, only UUID with 0x2803 and 0x2800
I read about these two UUIDs are for the whole system to help the
discovery of Characteristics or Descriptions, what I need is to
discover on with 0x2902 (CCC) , am I right?

Let do a summary, maybe you just give me some input:

**First service ( Jawbone ) :
attr handle: 0x0009, end grp handle: 0x0012 uuid:
f7c9ba7e-6658-4390-b53c-1de5e1453654
Range: 0x0009 - 0x0012

The characteristics from this range are:

handle: 0x000a, char properties: 0x18, char value handle: 0x000b,
uuid: f7c9b162-6658-4390-b53c-1de5e1453654
handle: 0x000d, char properties: 0x10, char value handle: 0x000e,
uuid: f7c9ba82-6658-4390-b53c-1de5e1453654
handle: 0x0010, char properties: 0x10, char value handle: 0x0011,
uuid: f7c9ba91-6658-4390-b53c-1de5e1453654

So what I discovered from your last email is that my CCC are:

0x000c , 0x000f , 0x0012

also doing the char-desc I can see that the uuid is 0x2902

I discovered that sending 01 to the 0x000f I get one notification

char-write-req 0x000f 01
[CON][DC:7A:F8:10:AF:A5][LE]> Characteristic value was written successfully

Notification handle = 0x000e value: 20 0f 1f aa f9 84 d5 e1 78 29 23
2d 14 bc fb c4 ef 71

Probably I need to do a custom activation, because pairing the device
with the specific app I get a vibration on the device.

I might be on the right track, I would like to know if my discovery
are right and I am not floating around.


> PS: When replying to e-mails on the mailing list, be sure to not
> top-post (i.e. write your reply before the original message) and
> remember to trim the original message to only show the relevant part
> of the original message (like I did above), otherwise it is difficult
> to follow discussion.
>
> Best Regards,

thanks for the advice, I am not really expert on this maillist system :(

2014-03-17 19:13:10

by Anderson Lizardo

[permalink] [raw]
Subject: Re: Bluetooth low energy with gatttool and jawbone

Hi Christian,

On Mon, Mar 17, 2014 at 2:06 PM, Christian Bianchini
<[email protected]> wrote:
> I can try with your idea but if I continue to type commands to read
> stuff, try to write, etc... the device doesn't disconnect. I guess
> it's a timeout after I dont get or send any data, probably a
> power-safe-mode.
>
> i have bluez 4.101 :
> ii bluez 4.101-0ubuntu8b1
> amd64 Bluetooth tools and daemons
>
>
> What I dont get is that I can't write any parameters:
> char-write-req a 0100
> [CON][DC:7A:F8:10:AF:A5][LE]> Characteristic Write Request failed:
> Attribute can't be written

This error actually means "Write not permitted". One first error is
that you are trying to write to the characteristic declaration
attribute, which is always read-only. To enable notification, you
should write to the Client Characteristic Configuration (CCC)
descriptor, which for the first characteristic is probably 0x000c (you
can confirm by running "char-desc 0x000c 0x000c", if it appears one
attribute with UUID 0x2902, it is a CCC).

Can you try this instead:

char-write-req 0x000c 0100

By the way, I strongly suggest you read a bit more on GATT (there are
some good resources on bluetooth.org), so you understand better what
are notifications, descriptors, characteristics, services etc.

PS: When replying to e-mails on the mailing list, be sure to not
top-post (i.e. write your reply before the original message) and
remember to trim the original message to only show the relevant part
of the original message (like I did above), otherwise it is difficult
to follow discussion.

Best Regards,
--
Anderson Lizardo
http://www.indt.org/?lang=en
INdT - Manaus - Brazil