GATT Profileに登場するオブジェクト

ツイート このエントリーをはてなブックマークに追加
1つ上へ / ブログトップへ

まず、BLEのProfileの1つであるGATT Profile(Generic Attribute Profile)に登場するオブジェクトについて説明します。

Service

文字通りサービスです。例えば温度計サービスや体重計サービスなどが考えられます。ServiceにはUUIDが付いています。

CoreBluetoothでは、次のようにしてServiceオブジェクトを生成します。

NSString* const MY_UUID = @"7B5FC8F1-66E3-442F-A4EE-BA18D0DE01D8";

// Create UUID
CBUUID *uuid = [CBUUID UUIDWithString:MY_UUID];

// Create Service
CBMutableService *service = [[CBMutableService alloc] initWithType:uuid primary:YES];

Characteristic

実際にデータを提供する人です。Serviceの子供になり、こいつもやはりUUIDで識別されます。例えば温度計サービスの場合、Characteristicとして

  • 実際に温度データを提供するCharacteristic
  • デバイスのバッテリー残量を提供するCharacteristic

のようなものが考えられます。

CoreBluetoothでは、次のようにしてCharacteristicオブジェクトを生成し、Serviceに紐付けます。

NSString* const MY_UUID = @"AB0B5B1C-14B2-4D5B-8AB3-80558B6B2243";

// Create UUID
CBUUID *uuid = [CBUUID UUIDWithString:MY_UUID];

// create characteristic
CBMutableCharacteristic *myCharacteristic =
[[CBMutableCharacteristic alloc] initWithType:uuid
                                   properties:CBCharacteristicPropertyRead
                                        value:nil
                                  permissions:CBAttributePermissionsReadable];

// set characteristics
service.characteristics = @[myCharacteristic];
1つ上へ / ブログトップへ