Go Down

Topic: Object Transfer method (Read 1 time) previous topic - next topic

evanhjalmar

Feb 03, 2016, 01:46 am Last Edit: Feb 07, 2016, 05:44 pm by evanhjalmar
Trying to understand how to use each of the services defined here: https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx

I noticed that all the bluetooth heart rate demos are including the service & a characteristic but the naming conventions seem very different from the methods defined on Bluetooth.org :
Code: [Select]


BLEService heartRateService("180D"); // BLE Heart Rate Service

BLECharacteristic heartRateChar




Can anyone provide an example on how to define these services?

drmpf

Here is a definition of Nordic's UART service

// ====  create Nordic UART service =========
BLEService               uartService          = BLEService("6E400001B5A3F393E0A9E50E24DCCA9E");
// create characteristic
BLECharacteristic    txCharacteristic = BLECharacteristic("6E400003B5A3F393E0A9E50E24DCCA9E", BLENotify , 20); // == RX on central (android app)
BLECharacteristic    rxCharacteristic = BLECharacteristic("6E400002B5A3F393E0A9E50E24DCCA9E", BLEWriteWithoutResponse, 20);  // == TX on central (android app)
 
void blePeripheralConnectHandler(BLECentral& central) {
  // central connected event handler
  parser.connect();
}

void blePeripheralDisconnectHandler(BLECentral& central) {
  // central disconnected event handler
  parser.closeConnection();
}

void rxCharacteristicWritten(BLECentral& central, BLECharacteristic& characteristic)  {
  int len = characteristic.valueLength();
  const unsigned char *data = characteristic.value();
  parserCmd = parser.parse((const byte*)data, len);
}

I am putting the finishing touches on a code generator Android app (pfodDesigner) that will generate custom menus for Arduino101 and other BLE cards and connect with pfodApp to display those menus and allow the user to operate buttons, sliders, sub-menus and log and plot data

see www.pfod.com.au for the current, non-BLE app and designer

drmpf

You also need in the setup() {

 // set advertised local name and service UUID
 blePeripheral.setLocalName("101 BLE");
 blePeripheral.setAdvertisedServiceUuid(uartService.uuid());

 // add service and characteristic
 blePeripheral.addAttribute(uartService);
 blePeripheral.addAttribute(rxCharacteristic);
 blePeripheral.addAttribute(txCharacteristic);

 // assign event handlers for connected, disconnected to peripheral
 blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
 blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);

 // assign event handlers for characteristic
 rxCharacteristic.setEventHandler(BLEWritten, rxCharacteristicWritten);

 // begin initialization
 blePeripheral.begin();

}

Goood

Hi !

How to use txCharacteristic in this case ?

Go Up