Skip to content

Arduino library for BLE

Guan Yang edited this page Jun 24, 2014 · 5 revisions

This is a draft API for an Arduino library for BLE. Current targets are:

  • nRF8001 with nRFgo Studio and services.h
  • nRF8001 configured directly from Arduino

Classes

BLEPeripheral

nRF8001:

nRF8001 nrf(4, 10, 3, setup_msgs, pipe_data);
BLEPeripheral peripheral(nrf);

BLECharacteristic

To make it easier for users, we will specify a data type. It is also possible to set up a characteristic as an array of values of the same type. For more complicated data structures, users should either manipulate a array of bytes (or uint8_ts) or use a struct.

BLECharacteristic<uint8_t> example1(peripheral);
BLECharacteristic<uint8_t, 10> example2(peripheral);
BLECharacteristic<int16_t> example3(peripheral);

example1.write(12);
example1.read();
example3.write(-42);

uint8_t data[10];
example2.read(data);

For nRF8001, we need to specify the pipes that belong to each characteristic. For example, one characteristic might have pin 2 and another might have pins 2 and 3. How should we do this?

Implementation specific considerations

nRF8001 with nRFgo Studio/services.h

We need to be passed the setup and pipe type data structures from services.h.

services.h can tell us the number of pipes (NUMBER_OF_PIPES) and the type of each pipe (SERVICES_PIPE_TYPE_MAPPING_CONTENT). This means that if we are given the SERVICES_PIPE_TYPE_MAPPING_CONTENT data structure, the user only needs to tell us which pipes belong to each services. This could be done with something like:

BLECharacteristic characteristic(peripheral);
characteristic.addPipe(2);
characteristic.addPipe(3);

This tells the library that pipes 2 and 3 belong to this characteristic, and the library can figure out what they do. Except at this stage BLECharacteristic doesn’t know that it’s an nRF8001. We might need something like this:

nRF8001 nrf(...);
BLEPeripheral peripheral(nrf);
BLECharacteristic characteristic(peripheral);
nrf.addPipe(characteristic, 2);
nrf.addPipe(characteristic, 3);