1

I am working on a Bluetooth Low Energy (BLE) project which needs iPhone to act as a peripheral device. I am using BLEManager to deal with CoreBluetooth related jobs, which includes good implementations for both Central and Peripheral mode.

Question:

I don't have any idea about design patterns and best practices of a peripheral's architecture. There is no pattern for the definition of Services and Characteristics. It seems I can choose one of the following patterns:

  • define multiple services, with one read/write/notify characteristic
  • define one service, with some read/write/notify characteristics
  • define one service, one characteristic for read/write/notify, and extract commands from the characteristic updated value

Which one shall I choose?

Implementation

Here are some parts of my peripheral implementation using BLEManager:

let peripheralServiceUUID = CBUUID(string: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
let nameCharacteristicUUID = CBUUID(string: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")

var CharactersticArray = [MyCharacterstic]()

characteristic.uuid = nameCharacteristicUUID
characteristic.value = nil
characteristic.permission = [.writeable, .readEncryptionRequired]
characteristic.property = [.write, .read, .notify]
CharactersticArray.append(characteristic)

Peripheral.instance().service_UUID = peripheralServiceUUID
Peripheral.instance().service_characteristics = CharactersticArray
Peripheral.instance().localName = "iPhone"
Peripheral.instance().startAdvertising()
Hassan Shahbazi
  • 1,543
  • 9
  • 26
  • Your Question section does not include any question. If you want to know the best design, number two seems good. – Emil Mar 03 '18 at 16:42
  • @Emil I just edited the question section. I couldn't find any appropriate documentation about this pattern, could it decrease connection performance? – Hassan Shahbazi Mar 04 '18 at 05:48

0 Answers0