SlideShare una empresa de Scribd logo
1 de 22
Descargar para leer sin conexión
Bluetooth LEとiBeaconを使った、
すれ違い通信	
2014.4.5
Bitz Co., Ltd. 村上幸雄
• 村上幸雄	

• @m_yukio	

• ビッツ有限会社
http://www.bitz.co.jp/
今回のサンプルコードは以下のURL.
https://github.com/murakami/workbook/tree/master/ios/Wibree
  Bluetoothは、省電力な電波を使った無線通信で、
最新の4.xでは対応機器は次の3つに分類されま
す。	
分類	
 説明	
Bluetooth Smart
4.0で追加されたBluetooth Low Energyのみ対
応。	
Bluetooth Smart Ready Bluetooth LEと従来のBluetoothの両方に対応。	
Bluetooth 従来のBluetoothのみ対応。
  iOSでBluetoothに対応する方法を整理してみます。	
Bluetoothの種類	
 説明	
従来のBLuetooth
MFi機器に対してExternal Accessory
Frameworkで通信。	
Game Kit
Bluetooth LE Core Bluetooth Framework
iOSでは、無関係の機器と自由に通信したいのならBluetooth LEという事になるか
と思います。
すれ違い通信	
識別子	
 識別子	
識別子を交換	
Bluetooth LE
Periphera
l
Advertise
Central 発見	
Service
UUID
  Peripheralが対応しているService UUIDをAdvertiseする。
  Centralは探しているService UUIDがないか調査する。
  Centralが見つけられたら、Peripheralに対して接続要求を出し、受
けいれるとデータ通信が可能になる。
  サンプルコードでは、識別子のCharacteristic UUIDを問い合わせ
て、識別子を受け取っている。
Service
すれ違い通信	
Characteristic
識別子	
CBPeripheral
CBPeripheral
CBCharacteristic
SAMPLE CODE
Central Managerの用意	
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self!
queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
Centralが使えるようになったので、Peripheralを探す	
- (void)centralManagerDidUpdateState:(CBCentralManager *)central!
{!
if (central.state != CBCentralManagerStatePoweredOn) {!
return;!
}!
[self scan];!
!
}!
!
- (void)scan!
{!
[self.centralManager scanForPeripheralsWithServices:!
@[[CBUUID UUIDWithString:WIBREE_SERVICE_UUID]]!
options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }];!
}
探すサービスUUID
Peripheralが見つかったので接続する	
- (void)centralManager:(CBCentralManager *)central!
didDiscoverPeripheral:(CBPeripheral *)peripheral!
advertisementData:(NSDictionary *)advertisementData!
RSSI:(NSNumber *)RSSI!
{!
if (self.discoveredPeripheral != peripheral) {!
self.discoveredPeripheral = peripheral;!
[self.centralManager connectPeripheral:peripheral options:nil];!
}!
}
サービスUUIDで検索	
- (void)centralManager:(CBCentralManager *)central!
didConnectPeripheral:(CBPeripheral *)peripheral!
{!
[self.centralManager stopScan];!
[self.data setLength:0];!
peripheral.delegate = self;!
[peripheral discoverServices:@[[CBUUID UUIDWithString:WIBREE_SERVICE_UUID]]];!
}!
利用するサービスUUID
キャラクタリスティックスUUIDで検索	
- (void)peripheral:(CBPeripheral *)peripheral!
didDiscoverServices:(NSError *)error!
{!
if (error) {!
[self cleanup];!
return;!
}!
for (CBService *service in peripheral.services) {!
[peripheral discoverCharacteristics:!
@[[CBUUID UUIDWithString:WIBREE_CHARACTERISTIC_UUID]]!
forService:service];!
}!
}!
!
- (void)peripheral:(CBPeripheral *)peripheral!
didDiscoverCharacteristicsForService:(CBService *)service!
error:(NSError *)error!
{!
if (error) {!
[self cleanup];!
return;!
}!
for (CBCharacteristic *characteristic in service.characteristics) {!
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:!
WIBREE_CHARACTERISTIC_UUID]]) {!
[peripheral setNotifyValue:YES forCharacteristic:characteristic];!
}!
}!
}
利用するキャラクタリスティックスUUID
見つけたキャラクタリスティックスの値の通知を設定
識別子を受け取る	
- (void)peripheral:(CBPeripheral *)peripheral!
didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic!
error:(NSError *)error!
{!
NSString *stringFromData = [[NSString alloc]!
initWithData:characteristic.value encoding:NSUTF8StringEncoding];!
if ([stringFromData isEqualToString:@EOM]) {!
NSString *uniqueIdentifier = [[NSString alloc]!
initWithData:self.data encoding:NSUTF8StringEncoding];!
dispatch_async(dispatch_get_main_queue(), ^{!
[self _notifyParserDidDiscoverUUID:uniqueIdentifier];!
});!
[peripheral setNotifyValue:NO forCharacteristic:characteristic];!
[self.centralManager cancelPeripheralConnection:peripheral];!
}!
[self.data appendData:characteristic.value];!
}
断片化された受信データを格納する	
サンプルコードで決めた終端データを受け取る
値の通知の設定の結果を受け取る	
- (void)peripheral:(CBPeripheral *)peripheral!
didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic!
error:(NSError *)error!
{!
if (![characteristic.UUID isEqual:[CBUUID!
UUIDWithString:WIBREE_CHARACTERISTIC_UUID]]) {!
return;!
}!
if (! characteristic.isNotifying) {!
[self.centralManager cancelPeripheralConnection:peripheral];!
}!
}
状態は、通知解除
Peripheral Managerの用意	
self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self!
queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];!
[self.peripheralManager startAdvertising:!
@{ CBAdvertisementDataServiceUUIDsKey :!
@[[CBUUID UUIDWithString:WIBREE_SERVICE_UUID]] }];
Peripheralが利用可能	
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral!
{!
if (peripheral.state != CBPeripheralManagerStatePoweredOn) {!
return;!
}!
self.transferCharacteristic = [[CBMutableCharacteristic alloc]!
initWithType:[CBUUID UUIDWithString:WIBREE_CHARACTERISTIC_UUID]!
properties:CBCharacteristicPropertyNotify!
value:nil!
permissions:CBAttributePermissionsReadable];!
CBMutableService *transferService = [[CBMutableService alloc]!
initWithType:[CBUUID UUIDWithString:WIBREE_SERVICE_UUID]!
primary:YES];!
transferService.characteristics = @[self.transferCharacteristic];!
[self.peripheralManager addService:transferService];!
}
見つけてもらうサービスUUID
利用可能なサービスUUIDとキャラク
タリスティックスUUID
識別子の送信	
- (void)peripheralManager:(CBPeripheralManager *)peripheral!
central:(CBCentral *)central!
didSubscribeToCharacteristic:(CBCharacteristic *)characteristic!
{!
self.dataToSend = [[Document sharedDocument].uniqueIdentifier dataUsingEncoding:NSUTF8StringEncoding];!
self.sendDataIndex = 0;!
[self sendData];!
}!
!
- (void)sendData!
{!
static BOOL sendingEOM = NO; !
if (sendingEOM) {!
BOOL didSend = [self.peripheralManager!
updateValue:[@EOM dataUsingEncoding:NSUTF8StringEncoding]!
forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil];!
if (didSend) sendingEOM = NO;!
return;!
}!
if (self.sendDataIndex = self.dataToSend.length) return;!
BOOL didSend = YES; !
while (didSend) {!
NSInteger amountToSend = self.dataToSend.length - self.sendDataIndex;!
if (amountToSend  NOTIFY_MTU) amountToSend = NOTIFY_MTU;!
NSData *chunk = [NSData dataWithBytes:self.dataToSend.bytes+self.sendDataIndex length:amountToSend];!
didSend = [self.peripheralManager updateValue:chunk!
forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil];!
if (!didSend) return;!
NSString *stringFromData = [[NSString alloc] initWithData:chunk encoding:NSUTF8StringEncoding];!
self.sendDataIndex += amountToSend;!
if (self.sendDataIndex = self.dataToSend.length) {!
sendingEOM = YES;!
BOOL eomSent = [self.peripheralManager updateValue:!
[@EOM dataUsingEncoding:NSUTF8StringEncoding]!
forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil]; !
if (eomSent) sendingEOM = NO; !
return;!
}!
}!
}!
!
- (void)peripheralManagerIsReadyToUpdateSubscribers:(CBPeripheralManager *)peripheral!
{!
[self sendData];!
}!
サンプルコードで決めた終端データを送る
  バックグラウンドで動かすには
   Info.plistのRequired background modesでApp communicates using CoreBluetoothを設定。
   Info.plistのRequired background modesでApp shares data using CoreBluetoothを設定。
  iBeaconを試してみる。
   CoreBluetoothでビーコンを実装。
   CoreLocationでビーコンを検出。
   iBeaconはアドバタイズのパケットにiBeaconの情報を付与したもの。
   ビーコンUUIDというのを定義するので、これをサンプルのサービス
UUIDとした。
   ペリフェラルにメジャー番号とマイナー番号を与えられるので、サン
プルではこれを識別子とした。
/* CLLocationManagerを生成 */!
self.locationManager = [[CLLocationManager alloc] init];!
self.locationManager.delegate = self;!
if (! self.locationManager) {!
/* CLLocationManagerの初期化失敗 */!
self.state = kBeaconCentralStateError;!
self.error = [self _errorWithCode:kBeaconCentralResponseParserGenericError!
localizedDescription:@CLLocationManagerの初期化に失敗しました。];!
return;!
}!
!
/* ビーコン領域を生成 */!
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:BEACON_SERVICE_UUID];!
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid!
                identifier:@demo.Wibree.BeaconCentralResponseParser];!
if (! self.beaconRegion) {!
/* ビーコン領域の初期化失敗 */!
self.state = kBeaconCentralStateError;!
self.error = [self _errorWithCode:kBeaconCentralResponseParserGenericError!
localizedDescription:@ビーコン領域の初期化に失敗しました。];!
self.locationManager = nil;!
return;!
}!
!
/* ビーコン領域の出入りを監視 */!
[self.locationManager startMonitoringForRegion:self.beaconRegion];!
!
/* 距離を監視 */!
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];!
iBeaconを探す	
探すビーコンのUUID
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region!
{!
DBGMSG(@%s, __func__);!
if ([self.delegate respondsToSelector:@selector(beaconCentralResponseParser:didEnterRegion:)]) {!
[self.delegate beaconCentralResponseParser:self didEnterRegion:region];!
}!
}!
!
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region!
{!
DBGMSG(@%s, __func__);!
if ([self.delegate respondsToSelector:@selector(beaconCentralResponseParser:didExitRegion:)]) {!
[self.delegate beaconCentralResponseParser:self didExitRegion:region];!
}!
}!
!
- (void)locationManager:(CLLocationManager *)manager!
didRangeBeacons:(NSArray *)beacons!
inRegion:(CLBeaconRegion *)region!
{!
DBGMSG(@%s, __func__);!
if ([self.delegate respondsToSelector:@selector(beaconCentralResponseParser:didRangeBeacons:inRegion:)]) {!
[self.delegate beaconCentralResponseParser:self didRangeBeacons:beacons inRegion:region];!
}!
}!
!
- (void)locationManager:(CLLocationManager *)manager!
monitoringDidFailForRegion:(CLRegion *)region!
withError:(NSError *)error!
{!
DBGMSG(@%s region:%@, __func__, region);!
DBGMSG(@%s error:%@, __func__, error);!
}!
検出	
 領域に入る	
領域から外れる	
距離を監視
/* CBPeripheralManagerを生成 */!
self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self!
queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];!
if (! self.peripheralManager) {!
/* CBPeripheralManagerの初期化失敗 */!
self.state = kBeaconPeripheralStateError;!
self.error = [self _errorWithCode:kBeaconPeripheralResponseParserGenericError!
localizedDescription:@CBPeripheralManagerの初期化に失敗しました。];!
return;!
}!
!
/* ビーコン領域を生成 */!
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:BEACON_SERVICE_UUID];!
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid!
major:12345!
minor:67890!
identifier:@demo.Wibree.BeaconCentralResponseParser];!
if (! self.beaconRegion) {!
/* ビーコン領域の初期化失敗 */!
self.state = kBeaconPeripheralStateError;!
self.error = [self _errorWithCode:kBeaconPeripheralResponseParserGenericError!
localizedDescription:@ビーコン領域の初期化に失敗しました。];!
self.peripheralManager = nil;!
return;!
}!
!
/* 告知開始 */!
NSDictionary *dictionary = [self.beaconRegion peripheralDataWithMeasuredPower:nil];!
[self.peripheralManager startAdvertising:dictionary];
見つけてほしいUUIDを告知	
見つけてほしいビーコンのUUID
メジャー番号とマイナー番号
  バックグラウンドで動かすには
   Info.plistのRequired background modesでlocationを設定。
  課題など
   Bluetooth LEとiBeaconのバックグラウンド設定が衝突
し、動作しなくなる。
   iBeaconのペリフェラルはバックグラウンドでは動作しな
い。

Más contenido relacionado

La actualidad más candente

CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~ CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~ SEGADevTech
 
ソーシャルアプリにおけるRedisの活用事例とトラブル事例
ソーシャルアプリにおけるRedisの活用事例とトラブル事例ソーシャルアプリにおけるRedisの活用事例とトラブル事例
ソーシャルアプリにおけるRedisの活用事例とトラブル事例leverages_event
 
【DL輪読会】"A Generalist Agent"
【DL輪読会】"A Generalist Agent"【DL輪読会】"A Generalist Agent"
【DL輪読会】"A Generalist Agent"Deep Learning JP
 
明治大学 データサイエンス・AIに関するオムニバス授業 エバンジェリストというキャリア
明治大学 データサイエンス・AIに関するオムニバス授業 エバンジェリストというキャリア明治大学 データサイエンス・AIに関するオムニバス授業 エバンジェリストというキャリア
明治大学 データサイエンス・AIに関するオムニバス授業 エバンジェリストというキャリアDaiyu Hatakeyama
 
【メタサーベイ】基盤モデル / Foundation Models
【メタサーベイ】基盤モデル / Foundation Models【メタサーベイ】基盤モデル / Foundation Models
【メタサーベイ】基盤モデル / Foundation Modelscvpaper. challenge
 
Transformerを雰囲気で理解する
Transformerを雰囲気で理解するTransformerを雰囲気で理解する
Transformerを雰囲気で理解するAtsukiYamaguchi1
 
すごい constexpr たのしくレイトレ!
すごい constexpr たのしくレイトレ!すごい constexpr たのしくレイトレ!
すごい constexpr たのしくレイトレ!Genya Murakami
 
C#でもメタプログラミングがしたい!!
C#でもメタプログラミングがしたい!!C#でもメタプログラミングがしたい!!
C#でもメタプログラミングがしたい!!TATSUYA HAYAMIZU
 
画像処理ライブラリ OpenCV で 出来ること・出来ないこと
画像処理ライブラリ OpenCV で 出来ること・出来ないこと画像処理ライブラリ OpenCV で 出来ること・出来ないこと
画像処理ライブラリ OpenCV で 出来ること・出来ないことNorishige Fukushima
 
マルチコアを用いた画像処理
マルチコアを用いた画像処理マルチコアを用いた画像処理
マルチコアを用いた画像処理Norishige Fukushima
 
深層生成モデルと世界モデル(2020/11/20版)
深層生成モデルと世界モデル(2020/11/20版)深層生成モデルと世界モデル(2020/11/20版)
深層生成モデルと世界モデル(2020/11/20版)Masahiro Suzuki
 
Anomaly detection 系の論文を一言でまとめた
Anomaly detection 系の論文を一言でまとめたAnomaly detection 系の論文を一言でまとめた
Anomaly detection 系の論文を一言でまとめたぱんいち すみもと
 
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機Tetsuyuki Kobayashi
 
cvpaper.challenge 研究効率化 Tips
cvpaper.challenge 研究効率化 Tipscvpaper.challenge 研究効率化 Tips
cvpaper.challenge 研究効率化 Tipscvpaper. challenge
 
【DL輪読会】Llama 2: Open Foundation and Fine-Tuned Chat Models
【DL輪読会】Llama 2: Open Foundation and Fine-Tuned Chat Models【DL輪読会】Llama 2: Open Foundation and Fine-Tuned Chat Models
【DL輪読会】Llama 2: Open Foundation and Fine-Tuned Chat ModelsDeep Learning JP
 
Autoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォーム
Autoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォームAutoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォーム
Autoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォームTakuya Azumi
 
【DL輪読会】ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
【DL輪読会】ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation【DL輪読会】ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
【DL輪読会】ViTPose: Simple Vision Transformer Baselines for Human Pose EstimationDeep Learning JP
 
深層学習によるHuman Pose Estimationの基礎
深層学習によるHuman Pose Estimationの基礎深層学習によるHuman Pose Estimationの基礎
深層学習によるHuman Pose Estimationの基礎Takumi Ohkuma
 

La actualidad más candente (20)

CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~ CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
 
ソーシャルアプリにおけるRedisの活用事例とトラブル事例
ソーシャルアプリにおけるRedisの活用事例とトラブル事例ソーシャルアプリにおけるRedisの活用事例とトラブル事例
ソーシャルアプリにおけるRedisの活用事例とトラブル事例
 
【DL輪読会】"A Generalist Agent"
【DL輪読会】"A Generalist Agent"【DL輪読会】"A Generalist Agent"
【DL輪読会】"A Generalist Agent"
 
明治大学 データサイエンス・AIに関するオムニバス授業 エバンジェリストというキャリア
明治大学 データサイエンス・AIに関するオムニバス授業 エバンジェリストというキャリア明治大学 データサイエンス・AIに関するオムニバス授業 エバンジェリストというキャリア
明治大学 データサイエンス・AIに関するオムニバス授業 エバンジェリストというキャリア
 
【メタサーベイ】基盤モデル / Foundation Models
【メタサーベイ】基盤モデル / Foundation Models【メタサーベイ】基盤モデル / Foundation Models
【メタサーベイ】基盤モデル / Foundation Models
 
Transformerを雰囲気で理解する
Transformerを雰囲気で理解するTransformerを雰囲気で理解する
Transformerを雰囲気で理解する
 
すごい constexpr たのしくレイトレ!
すごい constexpr たのしくレイトレ!すごい constexpr たのしくレイトレ!
すごい constexpr たのしくレイトレ!
 
C#でもメタプログラミングがしたい!!
C#でもメタプログラミングがしたい!!C#でもメタプログラミングがしたい!!
C#でもメタプログラミングがしたい!!
 
画像処理ライブラリ OpenCV で 出来ること・出来ないこと
画像処理ライブラリ OpenCV で 出来ること・出来ないこと画像処理ライブラリ OpenCV で 出来ること・出来ないこと
画像処理ライブラリ OpenCV で 出来ること・出来ないこと
 
マルチコアを用いた画像処理
マルチコアを用いた画像処理マルチコアを用いた画像処理
マルチコアを用いた画像処理
 
深層生成モデルと世界モデル(2020/11/20版)
深層生成モデルと世界モデル(2020/11/20版)深層生成モデルと世界モデル(2020/11/20版)
深層生成モデルと世界モデル(2020/11/20版)
 
Anomaly detection 系の論文を一言でまとめた
Anomaly detection 系の論文を一言でまとめたAnomaly detection 系の論文を一言でまとめた
Anomaly detection 系の論文を一言でまとめた
 
RvizPlugin作成入門
RvizPlugin作成入門RvizPlugin作成入門
RvizPlugin作成入門
 
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
 
cvpaper.challenge 研究効率化 Tips
cvpaper.challenge 研究効率化 Tipscvpaper.challenge 研究効率化 Tips
cvpaper.challenge 研究効率化 Tips
 
【DL輪読会】Llama 2: Open Foundation and Fine-Tuned Chat Models
【DL輪読会】Llama 2: Open Foundation and Fine-Tuned Chat Models【DL輪読会】Llama 2: Open Foundation and Fine-Tuned Chat Models
【DL輪読会】Llama 2: Open Foundation and Fine-Tuned Chat Models
 
Autoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォーム
Autoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォームAutoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォーム
Autoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォーム
 
Data-Centric AIの紹介
Data-Centric AIの紹介Data-Centric AIの紹介
Data-Centric AIの紹介
 
【DL輪読会】ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
【DL輪読会】ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation【DL輪読会】ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
【DL輪読会】ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
 
深層学習によるHuman Pose Estimationの基礎
深層学習によるHuman Pose Estimationの基礎深層学習によるHuman Pose Estimationの基礎
深層学習によるHuman Pose Estimationの基礎
 

Destacado

iPhoneのBluetoothについての知見まとめ
iPhoneのBluetoothについての知見まとめiPhoneのBluetoothについての知見まとめ
iPhoneのBluetoothについての知見まとめShuichi Tsutsumi
 
Bluetooth LE +スマートフォン勉強会@関西(2013年11月2日)
Bluetooth LE +スマートフォン勉強会@関西(2013年11月2日)Bluetooth LE +スマートフォン勉強会@関西(2013年11月2日)
Bluetooth LE +スマートフォン勉強会@関西(2013年11月2日)akihiro uehara
 
iOS7アプリ同士の近距離通信どれがいい?
iOS7アプリ同士の近距離通信どれがいい?iOS7アプリ同士の近距離通信どれがいい?
iOS7アプリ同士の近距離通信どれがいい?Norihiro Arita
 
Bluetooth LEとiBeaconを使った、すれ違い通信
Bluetooth LEとiBeaconを使った、すれ違い通信Bluetooth LEとiBeaconを使った、すれ違い通信
Bluetooth LEとiBeaconを使った、すれ違い通信幸雄 村上
 
iOSアプリ開発者のための Bluetooth Low Energy体験講座
iOSアプリ開発者のための Bluetooth Low Energy体験講座iOSアプリ開発者のための Bluetooth Low Energy体験講座
iOSアプリ開発者のための Bluetooth Low Energy体験講座akihiro uehara
 
Bluetooth Low Energy入門講座 -part2
Bluetooth Low Energy入門講座 -part2Bluetooth Low Energy入門講座 -part2
Bluetooth Low Energy入門講座 -part2edy555
 
Bluetoothl-Low-Energy入門講座-part1
Bluetoothl-Low-Energy入門講座-part1Bluetoothl-Low-Energy入門講座-part1
Bluetoothl-Low-Energy入門講座-part1edy555
 
Bluetoothでつなごう!
Bluetoothでつなごう!Bluetoothでつなごう!
Bluetoothでつなごう!Shin Ise
 
ツイッター災害情報収集・共有 (ITx災害 勉強会 平成27年2月25日)
ツイッター災害情報収集・共有 (ITx災害 勉強会 平成27年2月25日)ツイッター災害情報収集・共有 (ITx災害 勉強会 平成27年2月25日)
ツイッター災害情報収集・共有 (ITx災害 勉強会 平成27年2月25日)Shigeru INANO
 
Angular js はまりどころ
Angular js はまりどころAngular js はまりどころ
Angular js はまりどころAyumi Goto
 
Moverio BT-200 チュートリアル
Moverio BT-200 チュートリアルMoverio BT-200 チュートリアル
Moverio BT-200 チュートリアルKazuhiro Sasao
 
iPhone でバックグラウンド位置情報アプリケーションを作ってみた。
iPhone でバックグラウンド位置情報アプリケーションを作ってみた。iPhone でバックグラウンド位置情報アプリケーションを作ってみた。
iPhone でバックグラウンド位置情報アプリケーションを作ってみた。Hal Seki
 
AVSpeechSynthesizerとロケール
AVSpeechSynthesizerとロケールAVSpeechSynthesizerとロケール
AVSpeechSynthesizerとロケールtoyship
 
Downalodable Storyboard
Downalodable StoryboardDownalodable Storyboard
Downalodable StoryboardYuta Tokoro
 
最新AndroidとIoTプラットフォームの今 (WJ2016)
最新AndroidとIoTプラットフォームの今 (WJ2016)最新AndroidとIoTプラットフォームの今 (WJ2016)
最新AndroidとIoTプラットフォームの今 (WJ2016)嶋 是一 (Yoshikazu SHIMA)
 
第25回プロコン一関大会課題部門-富山(射水)-「DTN通信を用いた災害時の 安否及び避難所情報収集システム」
第25回プロコン一関大会課題部門-富山(射水)-「DTN通信を用いた災害時の安否及び避難所情報収集システム」第25回プロコン一関大会課題部門-富山(射水)-「DTN通信を用いた災害時の安否及び避難所情報収集システム」
第25回プロコン一関大会課題部門-富山(射水)-「DTN通信を用いた災害時の 安否及び避難所情報収集システム」Hokuto Tateyama
 
もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境
もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境
もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境Masashi Shinbara
 

Destacado (20)

iPhoneのBluetoothについての知見まとめ
iPhoneのBluetoothについての知見まとめiPhoneのBluetoothについての知見まとめ
iPhoneのBluetoothについての知見まとめ
 
Bluetooth LE +スマートフォン勉強会@関西(2013年11月2日)
Bluetooth LE +スマートフォン勉強会@関西(2013年11月2日)Bluetooth LE +スマートフォン勉強会@関西(2013年11月2日)
Bluetooth LE +スマートフォン勉強会@関西(2013年11月2日)
 
iOS7アプリ同士の近距離通信どれがいい?
iOS7アプリ同士の近距離通信どれがいい?iOS7アプリ同士の近距離通信どれがいい?
iOS7アプリ同士の近距離通信どれがいい?
 
Bluetooth LEとiBeaconを使った、すれ違い通信
Bluetooth LEとiBeaconを使った、すれ違い通信Bluetooth LEとiBeaconを使った、すれ違い通信
Bluetooth LEとiBeaconを使った、すれ違い通信
 
iOSアプリ開発者のための Bluetooth Low Energy体験講座
iOSアプリ開発者のための Bluetooth Low Energy体験講座iOSアプリ開発者のための Bluetooth Low Energy体験講座
iOSアプリ開発者のための Bluetooth Low Energy体験講座
 
Bluetooth Low Energy入門講座 -part2
Bluetooth Low Energy入門講座 -part2Bluetooth Low Energy入門講座 -part2
Bluetooth Low Energy入門講座 -part2
 
Bluetoothl-Low-Energy入門講座-part1
Bluetoothl-Low-Energy入門講座-part1Bluetoothl-Low-Energy入門講座-part1
Bluetoothl-Low-Energy入門講座-part1
 
Bluetoothでつなごう!
Bluetoothでつなごう!Bluetoothでつなごう!
Bluetoothでつなごう!
 
ツイッター災害情報収集・共有 (ITx災害 勉強会 平成27年2月25日)
ツイッター災害情報収集・共有 (ITx災害 勉強会 平成27年2月25日)ツイッター災害情報収集・共有 (ITx災害 勉強会 平成27年2月25日)
ツイッター災害情報収集・共有 (ITx災害 勉強会 平成27年2月25日)
 
単車の手帳
単車の手帳単車の手帳
単車の手帳
 
Angular js はまりどころ
Angular js はまりどころAngular js はまりどころ
Angular js はまりどころ
 
Moverio BT-200 チュートリアル
Moverio BT-200 チュートリアルMoverio BT-200 チュートリアル
Moverio BT-200 チュートリアル
 
iPhone でバックグラウンド位置情報アプリケーションを作ってみた。
iPhone でバックグラウンド位置情報アプリケーションを作ってみた。iPhone でバックグラウンド位置情報アプリケーションを作ってみた。
iPhone でバックグラウンド位置情報アプリケーションを作ってみた。
 
AVSpeechSynthesizerとロケール
AVSpeechSynthesizerとロケールAVSpeechSynthesizerとロケール
AVSpeechSynthesizerとロケール
 
Downalodable Storyboard
Downalodable StoryboardDownalodable Storyboard
Downalodable Storyboard
 
最新AndroidとIoTプラットフォームの今 (WJ2016)
最新AndroidとIoTプラットフォームの今 (WJ2016)最新AndroidとIoTプラットフォームの今 (WJ2016)
最新AndroidとIoTプラットフォームの今 (WJ2016)
 
Xcode5でのデバッグ / CI | iOS 7エンジニア勉強会
Xcode5でのデバッグ / CI | iOS 7エンジニア勉強会Xcode5でのデバッグ / CI | iOS 7エンジニア勉強会
Xcode5でのデバッグ / CI | iOS 7エンジニア勉強会
 
RDF Semantic Graph「RDF 超入門」
RDF Semantic Graph「RDF 超入門」RDF Semantic Graph「RDF 超入門」
RDF Semantic Graph「RDF 超入門」
 
第25回プロコン一関大会課題部門-富山(射水)-「DTN通信を用いた災害時の 安否及び避難所情報収集システム」
第25回プロコン一関大会課題部門-富山(射水)-「DTN通信を用いた災害時の安否及び避難所情報収集システム」第25回プロコン一関大会課題部門-富山(射水)-「DTN通信を用いた災害時の安否及び避難所情報収集システム」
第25回プロコン一関大会課題部門-富山(射水)-「DTN通信を用いた災害時の 安否及び避難所情報収集システム」
 
もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境
もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境
もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境
 

Similar a Bluetooth LEとiBeaconを使った、すれ違い通信

インフラ管理者に送る あらためての IoT Edge / IoT Hub
インフラ管理者に送る あらためての IoT Edge / IoT Hubインフラ管理者に送る あらためての IoT Edge / IoT Hub
インフラ管理者に送る あらためての IoT Edge / IoT HubMasahiko Ebisuda
 
「 Azure 」にデータを溜めて活用する のご紹介 - 「はじめてのNode-RED ver.1.3.0対応版」書籍出版記念イベント LT
「 Azure 」にデータを溜めて活用する のご紹介 - 「はじめてのNode-RED ver.1.3.0対応版」書籍出版記念イベント LT「 Azure 」にデータを溜めて活用する のご紹介 - 「はじめてのNode-RED ver.1.3.0対応版」書籍出版記念イベント LT
「 Azure 」にデータを溜めて活用する のご紹介 - 「はじめてのNode-RED ver.1.3.0対応版」書籍出版記念イベント LTKazumi IWANAGA
 
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.1
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.1IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.1
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.1Seeed K.K.
 
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.0(旧)
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.0(旧)IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.0(旧)
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.0(旧)Seeed K.K.
 
プロペラブForth発表osc愛媛
プロペラブForth発表osc愛媛プロペラブForth発表osc愛媛
プロペラブForth発表osc愛媛titoi2
 
Bluetooth connecting iot bluetooth
Bluetooth connecting iot bluetoothBluetooth connecting iot bluetooth
Bluetooth connecting iot bluetoothDaisuke Nagata
 
Mono is Dead
Mono is DeadMono is Dead
Mono is Deadmelpon
 
LEGO MINDSTORMS EV3 API
LEGO MINDSTORMS EV3 APILEGO MINDSTORMS EV3 API
LEGO MINDSTORMS EV3 APIAkira Hatsune
 
ひげボタンをAzure IoT Centralにつないでみる
ひげボタンをAzure IoT CentralにつないでみるひげボタンをAzure IoT Centralにつないでみる
ひげボタンをAzure IoT CentralにつないでみるKen'ichirou Kimura
 
mbed祭り2016@秋の虎ノ門(AzureIoTSuiteの検証)
mbed祭り2016@秋の虎ノ門(AzureIoTSuiteの検証)mbed祭り2016@秋の虎ノ門(AzureIoTSuiteの検証)
mbed祭り2016@秋の虎ノ門(AzureIoTSuiteの検証)Takehiko Tomiyama
 
I2CでRaspberry Piから 複数の周辺機器を制御する
I2CでRaspberry Piから複数の周辺機器を制御するI2CでRaspberry Piから複数の周辺機器を制御する
I2CでRaspberry Piから 複数の周辺機器を制御するHirokazu Nishio
 
hubotで快適BOT生活
hubotで快適BOT生活 hubotで快適BOT生活
hubotで快適BOT生活 Kazufumi Otani
 
BOSHでお手軽CFデプロイon AWS
BOSHでお手軽CFデプロイon AWSBOSHでお手軽CFデプロイon AWS
BOSHでお手軽CFデプロイon AWSi_yudai
 
【de:code 2020】 Azure Bot Services を使って Teams bot を開発する
【de:code 2020】 Azure Bot Services を使って Teams bot を開発する【de:code 2020】 Azure Bot Services を使って Teams bot を開発する
【de:code 2020】 Azure Bot Services を使って Teams bot を開発する日本マイクロソフト株式会社
 

Similar a Bluetooth LEとiBeaconを使った、すれ違い通信 (14)

インフラ管理者に送る あらためての IoT Edge / IoT Hub
インフラ管理者に送る あらためての IoT Edge / IoT Hubインフラ管理者に送る あらためての IoT Edge / IoT Hub
インフラ管理者に送る あらためての IoT Edge / IoT Hub
 
「 Azure 」にデータを溜めて活用する のご紹介 - 「はじめてのNode-RED ver.1.3.0対応版」書籍出版記念イベント LT
「 Azure 」にデータを溜めて活用する のご紹介 - 「はじめてのNode-RED ver.1.3.0対応版」書籍出版記念イベント LT「 Azure 」にデータを溜めて活用する のご紹介 - 「はじめてのNode-RED ver.1.3.0対応版」書籍出版記念イベント LT
「 Azure 」にデータを溜めて活用する のご紹介 - 「はじめてのNode-RED ver.1.3.0対応版」書籍出版記念イベント LT
 
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.1
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.1IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.1
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.1
 
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.0(旧)
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.0(旧)IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.0(旧)
IoT Kit ハンズオントレーニング ~ Seeed Wio LTE + SORACOM Beam ~ V4.0(旧)
 
プロペラブForth発表osc愛媛
プロペラブForth発表osc愛媛プロペラブForth発表osc愛媛
プロペラブForth発表osc愛媛
 
Bluetooth connecting iot bluetooth
Bluetooth connecting iot bluetoothBluetooth connecting iot bluetooth
Bluetooth connecting iot bluetooth
 
Mono is Dead
Mono is DeadMono is Dead
Mono is Dead
 
LEGO MINDSTORMS EV3 API
LEGO MINDSTORMS EV3 APILEGO MINDSTORMS EV3 API
LEGO MINDSTORMS EV3 API
 
ひげボタンをAzure IoT Centralにつないでみる
ひげボタンをAzure IoT CentralにつないでみるひげボタンをAzure IoT Centralにつないでみる
ひげボタンをAzure IoT Centralにつないでみる
 
mbed祭り2016@秋の虎ノ門(AzureIoTSuiteの検証)
mbed祭り2016@秋の虎ノ門(AzureIoTSuiteの検証)mbed祭り2016@秋の虎ノ門(AzureIoTSuiteの検証)
mbed祭り2016@秋の虎ノ門(AzureIoTSuiteの検証)
 
I2CでRaspberry Piから 複数の周辺機器を制御する
I2CでRaspberry Piから複数の周辺機器を制御するI2CでRaspberry Piから複数の周辺機器を制御する
I2CでRaspberry Piから 複数の周辺機器を制御する
 
hubotで快適BOT生活
hubotで快適BOT生活 hubotで快適BOT生活
hubotで快適BOT生活
 
BOSHでお手軽CFデプロイon AWS
BOSHでお手軽CFデプロイon AWSBOSHでお手軽CFデプロイon AWS
BOSHでお手軽CFデプロイon AWS
 
【de:code 2020】 Azure Bot Services を使って Teams bot を開発する
【de:code 2020】 Azure Bot Services を使って Teams bot を開発する【de:code 2020】 Azure Bot Services を使って Teams bot を開発する
【de:code 2020】 Azure Bot Services を使って Teams bot を開発する
 

Más de 幸雄 村上

アプリケーション識別子.pdf
アプリケーション識別子.pdfアプリケーション識別子.pdf
アプリケーション識別子.pdf幸雄 村上
 
圧縮ネイティブ・ライブラリについて.pdf
圧縮ネイティブ・ライブラリについて.pdf圧縮ネイティブ・ライブラリについて.pdf
圧縮ネイティブ・ライブラリについて.pdf幸雄 村上
 
分散環境におけるジャストインタイム設定の試み
分散環境におけるジャストインタイム設定の試み分散環境におけるジャストインタイム設定の試み
分散環境におけるジャストインタイム設定の試み幸雄 村上
 
SwiftのOptionalを理解する
SwiftのOptionalを理解するSwiftのOptionalを理解する
SwiftのOptionalを理解する幸雄 村上
 
え!それって参照渡し?
え!それって参照渡し?え!それって参照渡し?
え!それって参照渡し?幸雄 村上
 
プライバシーとセキュリティ(リモート通知のデバイストークンの扱いなど)
プライバシーとセキュリティ(リモート通知のデバイストークンの扱いなど)プライバシーとセキュリティ(リモート通知のデバイストークンの扱いなど)
プライバシーとセキュリティ(リモート通知のデバイストークンの扱いなど)幸雄 村上
 
AppleScriptとは何ぞや
AppleScriptとは何ぞやAppleScriptとは何ぞや
AppleScriptとは何ぞや幸雄 村上
 
Web API 通信の符号化について
Web API 通信の符号化についてWeb API 通信の符号化について
Web API 通信の符号化について幸雄 村上
 
Master-Detail App を実装する
Master-Detail App を実装するMaster-Detail App を実装する
Master-Detail App を実装する幸雄 村上
 
SwiftのOptionalを理解する
SwiftのOptionalを理解するSwiftのOptionalを理解する
SwiftのOptionalを理解する幸雄 村上
 
Getting a packet trace
Getting a packet traceGetting a packet trace
Getting a packet trace幸雄 村上
 
The Bash in Tokyo : AppKitとUIKit
The Bash in Tokyo : AppKitとUIKitThe Bash in Tokyo : AppKitとUIKit
The Bash in Tokyo : AppKitとUIKit幸雄 村上
 
Swiftでブロックチェーンを実装する
Swiftでブロックチェーンを実装するSwiftでブロックチェーンを実装する
Swiftでブロックチェーンを実装する幸雄 村上
 
ゲームの企画書づくりに挑戦
ゲームの企画書づくりに挑戦ゲームの企画書づくりに挑戦
ゲームの企画書づくりに挑戦幸雄 村上
 
IBM Watson Services for Core ML
IBM Watson Services for Core MLIBM Watson Services for Core ML
IBM Watson Services for Core ML幸雄 村上
 
独自Documentクラス
独自Documentクラス独自Documentクラス
独自Documentクラス幸雄 村上
 
独自Documentクラス
独自Documentクラス独自Documentクラス
独自Documentクラス幸雄 村上
 

Más de 幸雄 村上 (20)

アプリケーション識別子.pdf
アプリケーション識別子.pdfアプリケーション識別子.pdf
アプリケーション識別子.pdf
 
圧縮ネイティブ・ライブラリについて.pdf
圧縮ネイティブ・ライブラリについて.pdf圧縮ネイティブ・ライブラリについて.pdf
圧縮ネイティブ・ライブラリについて.pdf
 
分散環境におけるジャストインタイム設定の試み
分散環境におけるジャストインタイム設定の試み分散環境におけるジャストインタイム設定の試み
分散環境におけるジャストインタイム設定の試み
 
SwiftのOptionalを理解する
SwiftのOptionalを理解するSwiftのOptionalを理解する
SwiftのOptionalを理解する
 
え!それって参照渡し?
え!それって参照渡し?え!それって参照渡し?
え!それって参照渡し?
 
プライバシーとセキュリティ(リモート通知のデバイストークンの扱いなど)
プライバシーとセキュリティ(リモート通知のデバイストークンの扱いなど)プライバシーとセキュリティ(リモート通知のデバイストークンの扱いなど)
プライバシーとセキュリティ(リモート通知のデバイストークンの扱いなど)
 
AppleScriptなど
AppleScriptなどAppleScriptなど
AppleScriptなど
 
MojaveのDark Mode
MojaveのDark ModeMojaveのDark Mode
MojaveのDark Mode
 
AppleScriptとは何ぞや
AppleScriptとは何ぞやAppleScriptとは何ぞや
AppleScriptとは何ぞや
 
Web API 通信の符号化について
Web API 通信の符号化についてWeb API 通信の符号化について
Web API 通信の符号化について
 
Master-Detail App を実装する
Master-Detail App を実装するMaster-Detail App を実装する
Master-Detail App を実装する
 
SwiftのOptionalを理解する
SwiftのOptionalを理解するSwiftのOptionalを理解する
SwiftのOptionalを理解する
 
Getting a packet trace
Getting a packet traceGetting a packet trace
Getting a packet trace
 
The Bash in Tokyo : AppKitとUIKit
The Bash in Tokyo : AppKitとUIKitThe Bash in Tokyo : AppKitとUIKit
The Bash in Tokyo : AppKitとUIKit
 
RUDP
RUDPRUDP
RUDP
 
Swiftでブロックチェーンを実装する
Swiftでブロックチェーンを実装するSwiftでブロックチェーンを実装する
Swiftでブロックチェーンを実装する
 
ゲームの企画書づくりに挑戦
ゲームの企画書づくりに挑戦ゲームの企画書づくりに挑戦
ゲームの企画書づくりに挑戦
 
IBM Watson Services for Core ML
IBM Watson Services for Core MLIBM Watson Services for Core ML
IBM Watson Services for Core ML
 
独自Documentクラス
独自Documentクラス独自Documentクラス
独自Documentクラス
 
独自Documentクラス
独自Documentクラス独自Documentクラス
独自Documentクラス
 

Bluetooth LEとiBeaconを使った、すれ違い通信

  • 3.   Bluetoothは、省電力な電波を使った無線通信で、 最新の4.xでは対応機器は次の3つに分類されま す。 分類 説明 Bluetooth Smart 4.0で追加されたBluetooth Low Energyのみ対 応。 Bluetooth Smart Ready Bluetooth LEと従来のBluetoothの両方に対応。 Bluetooth 従来のBluetoothのみ対応。
  • 4.   iOSでBluetoothに対応する方法を整理してみます。 Bluetoothの種類 説明 従来のBLuetooth MFi機器に対してExternal Accessory Frameworkで通信。 Game Kit Bluetooth LE Core Bluetooth Framework iOSでは、無関係の機器と自由に通信したいのならBluetooth LEという事になるか と思います。
  • 6. Periphera l Advertise Central 発見 Service UUID   Peripheralが対応しているService UUIDをAdvertiseする。   Centralは探しているService UUIDがないか調査する。   Centralが見つけられたら、Peripheralに対して接続要求を出し、受 けいれるとデータ通信が可能になる。   サンプルコードでは、識別子のCharacteristic UUIDを問い合わせ て、識別子を受け取っている。
  • 9. Central Managerの用意 self.centralManager = [[CBCentralManager alloc] initWithDelegate:self! queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; Centralが使えるようになったので、Peripheralを探す - (void)centralManagerDidUpdateState:(CBCentralManager *)central! {! if (central.state != CBCentralManagerStatePoweredOn) {! return;! }! [self scan];! ! }! ! - (void)scan! {! [self.centralManager scanForPeripheralsWithServices:! @[[CBUUID UUIDWithString:WIBREE_SERVICE_UUID]]! options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }];! } 探すサービスUUID
  • 10. Peripheralが見つかったので接続する - (void)centralManager:(CBCentralManager *)central! didDiscoverPeripheral:(CBPeripheral *)peripheral! advertisementData:(NSDictionary *)advertisementData! RSSI:(NSNumber *)RSSI! {! if (self.discoveredPeripheral != peripheral) {! self.discoveredPeripheral = peripheral;! [self.centralManager connectPeripheral:peripheral options:nil];! }! } サービスUUIDで検索 - (void)centralManager:(CBCentralManager *)central! didConnectPeripheral:(CBPeripheral *)peripheral! {! [self.centralManager stopScan];! [self.data setLength:0];! peripheral.delegate = self;! [peripheral discoverServices:@[[CBUUID UUIDWithString:WIBREE_SERVICE_UUID]]];! }! 利用するサービスUUID
  • 11. キャラクタリスティックスUUIDで検索 - (void)peripheral:(CBPeripheral *)peripheral! didDiscoverServices:(NSError *)error! {! if (error) {! [self cleanup];! return;! }! for (CBService *service in peripheral.services) {! [peripheral discoverCharacteristics:! @[[CBUUID UUIDWithString:WIBREE_CHARACTERISTIC_UUID]]! forService:service];! }! }! ! - (void)peripheral:(CBPeripheral *)peripheral! didDiscoverCharacteristicsForService:(CBService *)service! error:(NSError *)error! {! if (error) {! [self cleanup];! return;! }! for (CBCharacteristic *characteristic in service.characteristics) {! if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:! WIBREE_CHARACTERISTIC_UUID]]) {! [peripheral setNotifyValue:YES forCharacteristic:characteristic];! }! }! } 利用するキャラクタリスティックスUUID 見つけたキャラクタリスティックスの値の通知を設定
  • 12. 識別子を受け取る - (void)peripheral:(CBPeripheral *)peripheral! didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic! error:(NSError *)error! {! NSString *stringFromData = [[NSString alloc]! initWithData:characteristic.value encoding:NSUTF8StringEncoding];! if ([stringFromData isEqualToString:@EOM]) {! NSString *uniqueIdentifier = [[NSString alloc]! initWithData:self.data encoding:NSUTF8StringEncoding];! dispatch_async(dispatch_get_main_queue(), ^{! [self _notifyParserDidDiscoverUUID:uniqueIdentifier];! });! [peripheral setNotifyValue:NO forCharacteristic:characteristic];! [self.centralManager cancelPeripheralConnection:peripheral];! }! [self.data appendData:characteristic.value];! } 断片化された受信データを格納する サンプルコードで決めた終端データを受け取る
  • 13. 値の通知の設定の結果を受け取る - (void)peripheral:(CBPeripheral *)peripheral! didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic! error:(NSError *)error! {! if (![characteristic.UUID isEqual:[CBUUID! UUIDWithString:WIBREE_CHARACTERISTIC_UUID]]) {! return;! }! if (! characteristic.isNotifying) {! [self.centralManager cancelPeripheralConnection:peripheral];! }! } 状態は、通知解除
  • 14. Peripheral Managerの用意 self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self! queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];! [self.peripheralManager startAdvertising:! @{ CBAdvertisementDataServiceUUIDsKey :! @[[CBUUID UUIDWithString:WIBREE_SERVICE_UUID]] }]; Peripheralが利用可能 - (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral! {! if (peripheral.state != CBPeripheralManagerStatePoweredOn) {! return;! }! self.transferCharacteristic = [[CBMutableCharacteristic alloc]! initWithType:[CBUUID UUIDWithString:WIBREE_CHARACTERISTIC_UUID]! properties:CBCharacteristicPropertyNotify! value:nil! permissions:CBAttributePermissionsReadable];! CBMutableService *transferService = [[CBMutableService alloc]! initWithType:[CBUUID UUIDWithString:WIBREE_SERVICE_UUID]! primary:YES];! transferService.characteristics = @[self.transferCharacteristic];! [self.peripheralManager addService:transferService];! } 見つけてもらうサービスUUID 利用可能なサービスUUIDとキャラク タリスティックスUUID
  • 15. 識別子の送信 - (void)peripheralManager:(CBPeripheralManager *)peripheral! central:(CBCentral *)central! didSubscribeToCharacteristic:(CBCharacteristic *)characteristic! {! self.dataToSend = [[Document sharedDocument].uniqueIdentifier dataUsingEncoding:NSUTF8StringEncoding];! self.sendDataIndex = 0;! [self sendData];! }! ! - (void)sendData! {! static BOOL sendingEOM = NO; ! if (sendingEOM) {! BOOL didSend = [self.peripheralManager! updateValue:[@EOM dataUsingEncoding:NSUTF8StringEncoding]! forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil];! if (didSend) sendingEOM = NO;! return;! }! if (self.sendDataIndex = self.dataToSend.length) return;! BOOL didSend = YES; ! while (didSend) {! NSInteger amountToSend = self.dataToSend.length - self.sendDataIndex;! if (amountToSend NOTIFY_MTU) amountToSend = NOTIFY_MTU;! NSData *chunk = [NSData dataWithBytes:self.dataToSend.bytes+self.sendDataIndex length:amountToSend];! didSend = [self.peripheralManager updateValue:chunk! forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil];! if (!didSend) return;! NSString *stringFromData = [[NSString alloc] initWithData:chunk encoding:NSUTF8StringEncoding];! self.sendDataIndex += amountToSend;! if (self.sendDataIndex = self.dataToSend.length) {! sendingEOM = YES;! BOOL eomSent = [self.peripheralManager updateValue:! [@EOM dataUsingEncoding:NSUTF8StringEncoding]! forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil]; ! if (eomSent) sendingEOM = NO; ! return;! }! }! }! ! - (void)peripheralManagerIsReadyToUpdateSubscribers:(CBPeripheralManager *)peripheral! {! [self sendData];! }! サンプルコードで決めた終端データを送る
  • 16.   バックグラウンドで動かすには   Info.plistのRequired background modesでApp communicates using CoreBluetoothを設定。   Info.plistのRequired background modesでApp shares data using CoreBluetoothを設定。
  • 17.   iBeaconを試してみる。   CoreBluetoothでビーコンを実装。   CoreLocationでビーコンを検出。   iBeaconはアドバタイズのパケットにiBeaconの情報を付与したもの。   ビーコンUUIDというのを定義するので、これをサンプルのサービス UUIDとした。   ペリフェラルにメジャー番号とマイナー番号を与えられるので、サン プルではこれを識別子とした。
  • 18. /* CLLocationManagerを生成 */! self.locationManager = [[CLLocationManager alloc] init];! self.locationManager.delegate = self;! if (! self.locationManager) {! /* CLLocationManagerの初期化失敗 */! self.state = kBeaconCentralStateError;! self.error = [self _errorWithCode:kBeaconCentralResponseParserGenericError! localizedDescription:@CLLocationManagerの初期化に失敗しました。];! return;! }! ! /* ビーコン領域を生成 */! NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:BEACON_SERVICE_UUID];! self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid!                 identifier:@demo.Wibree.BeaconCentralResponseParser];! if (! self.beaconRegion) {! /* ビーコン領域の初期化失敗 */! self.state = kBeaconCentralStateError;! self.error = [self _errorWithCode:kBeaconCentralResponseParserGenericError! localizedDescription:@ビーコン領域の初期化に失敗しました。];! self.locationManager = nil;! return;! }! ! /* ビーコン領域の出入りを監視 */! [self.locationManager startMonitoringForRegion:self.beaconRegion];! ! /* 距離を監視 */! [self.locationManager startRangingBeaconsInRegion:self.beaconRegion];! iBeaconを探す 探すビーコンのUUID
  • 19. - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region! {! DBGMSG(@%s, __func__);! if ([self.delegate respondsToSelector:@selector(beaconCentralResponseParser:didEnterRegion:)]) {! [self.delegate beaconCentralResponseParser:self didEnterRegion:region];! }! }! ! - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region! {! DBGMSG(@%s, __func__);! if ([self.delegate respondsToSelector:@selector(beaconCentralResponseParser:didExitRegion:)]) {! [self.delegate beaconCentralResponseParser:self didExitRegion:region];! }! }! ! - (void)locationManager:(CLLocationManager *)manager! didRangeBeacons:(NSArray *)beacons! inRegion:(CLBeaconRegion *)region! {! DBGMSG(@%s, __func__);! if ([self.delegate respondsToSelector:@selector(beaconCentralResponseParser:didRangeBeacons:inRegion:)]) {! [self.delegate beaconCentralResponseParser:self didRangeBeacons:beacons inRegion:region];! }! }! ! - (void)locationManager:(CLLocationManager *)manager! monitoringDidFailForRegion:(CLRegion *)region! withError:(NSError *)error! {! DBGMSG(@%s region:%@, __func__, region);! DBGMSG(@%s error:%@, __func__, error);! }! 検出 領域に入る 領域から外れる 距離を監視
  • 20. /* CBPeripheralManagerを生成 */! self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self! queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];! if (! self.peripheralManager) {! /* CBPeripheralManagerの初期化失敗 */! self.state = kBeaconPeripheralStateError;! self.error = [self _errorWithCode:kBeaconPeripheralResponseParserGenericError! localizedDescription:@CBPeripheralManagerの初期化に失敗しました。];! return;! }! ! /* ビーコン領域を生成 */! NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:BEACON_SERVICE_UUID];! self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid! major:12345! minor:67890! identifier:@demo.Wibree.BeaconCentralResponseParser];! if (! self.beaconRegion) {! /* ビーコン領域の初期化失敗 */! self.state = kBeaconPeripheralStateError;! self.error = [self _errorWithCode:kBeaconPeripheralResponseParserGenericError! localizedDescription:@ビーコン領域の初期化に失敗しました。];! self.peripheralManager = nil;! return;! }! ! /* 告知開始 */! NSDictionary *dictionary = [self.beaconRegion peripheralDataWithMeasuredPower:nil];! [self.peripheralManager startAdvertising:dictionary]; 見つけてほしいUUIDを告知 見つけてほしいビーコンのUUID メジャー番号とマイナー番号
  • 21.   バックグラウンドで動かすには   Info.plistのRequired background modesでlocationを設定。
  • 22.   課題など   Bluetooth LEとiBeaconのバックグラウンド設定が衝突 し、動作しなくなる。   iBeaconのペリフェラルはバックグラウンドでは動作しな い。