Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bluetooth Low Energy: Read/Write to sensors attached to RedBearLab Shield

I have the RedBearLab BLE shield connected to Arduino UNO R3. I can connect to it using gatttool from a Rasp-Pi (attached CSR4.0 dongle). I have some sensors (FSR) connected to the analog pin and LED connected to digital pin in Arduino. My goal is to read/write to anything that is connected to the Arduino through BLE.

As a sample, I was looking into this link. It seems I need to know the handle of the sensor, config register # etc. to read/write.But I am not sure how to find the handle/uuid related to the sensor that is attached to the shield.

For example I see below.

[xx:xx:xx:xx:xx:xx][LE]> char-desc
handle: 0x0001, uuid: 2800
handle: 0x0002, uuid: 2803
handle: 0x0003, uuid: 2a00
handle: 0x0004, uuid: 2803
handle: 0x0005, uuid: 2a01
handle: 0x0006, uuid: 2803
handle: 0x0007, uuid: 2a04
handle: 0x0008, uuid: 2800
handle: 0x0009, uuid: 2800
handle: 0x000a, uuid: 2803
handle: 0x000b, uuid: 713d0003-503e-4c75-ba94-3148f18d941e
handle: 0x000c, uuid: 2803
handle: 0x000d, uuid: 713d0002-503e-4c75-ba94-3148f18d941e
handle: 0x000e, uuid: 2902
handle: 0x000f, uuid: 2800
handle: 0x0010, uuid: 2803
handle: 0x0011, uuid: 2a27    
Discover descriptors finished: No attribute found within the given range
[xx:xx:xx:xx:xx:xx][LE]> char-read-hnd 0x0001
Characteristic value/descriptor: 00 18
[xx:xx:xx:xx:xx:xx][LE]> char-read-hnd 0x000b
Error: Characteristic value/descriptor read failed: Attribute can't be read

How do I know which of them is the FSR I have attached to the shield?

update

I am using RedBearLab example - simplecontrol

So Arduino and iOS/Android code both are there. My goal is to understand from gatttool's perspective so I can develop something similar (of iOS/Android) in Java running at Raspberry Pi.

From the code, I can figure out which address to write. For example - to turn on the LED attached to the digital out pin, below works

char-write-cmd 0x000b 010100

Similarly, to turn on the sensor reading capability, I need to write below

char-write-cmd 0x000b A00100

I know this works. I see expected output in the Arduino serial monitor. I am pretty sure it is reading the sensor but I can't see that in the RaspPi prompt. I think I need to enable broadcast reading capability at RaspPi end.

Any suggestion?

like image 335
nad Avatar asked Jan 25 '14 01:01

nad


1 Answers

well, to beging working with BLE, you have to understand how the whole GATT stuff is working. Basically, you need to have some code on your arduino that sets up a profile in the nRF8001 component on your shield that defines "pipes" which is the link between a characteristic exposed by the radio (and seen using the gatttool) and a function from which you can read data or to which you can send data.

To modify and work on gatt profiles, and define those pipes, you need to use the nrfgo tool distributed by Nordic. It's windows only, but it works perfectly fine using wine on OSX or linux (I do it every day).

There you can load a profile and modify it or create a new one, it's up to you. I'd also advice you to look at the nordic examples in their devzone on how to setup a profile for nrf8001 + Arduino, those example are pretty clear.

Then once you've made all your characteristics, you can only read/write the characteristics you're handling. Having a characteristic available does not mean it can be read/written to, you may need to subscribe to it or it may always return an error. Remember that most of the characteristics you list are characteristics used by the gatt for having the whole gatt system work and usually is hidden by libraries abstracting the BLE stuff.

like image 76
zmo Avatar answered Oct 17 '22 23:10

zmo