20140802 bluetooth を使って universall app で大連携
DESCRIPTION
20140802 めとべや東京#5 での発表資料TRANSCRIPT
![Page 1: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/1.jpg)
![Page 2: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/2.jpg)
仕事
個人活動
http://tanaka733.net
https://www.nuget.org/profiles/tanaka_733/
https://github.com/tanaka-takayoshi
![Page 3: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/3.jpg)
3か月に1回程度の勉強会中心のコミュニティ
めと #とは
![Page 4: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/4.jpg)
![Page 5: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/5.jpg)
iPhoneやiPadで使えるドン!可愛さと実用性を兼ね備えた『太鼓の達人』専用Bluetoothコントローラ「太鼓とバチ」12月発売
![Page 6: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/6.jpg)
なんでBluetooth?
![Page 7: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/7.jpg)
![Page 8: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/8.jpg)
マスター・スレイブ通信
リンク層プロトコル
![Page 9: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/9.jpg)
ペアリング
プロファイル
サービスディスカバリ
![Page 10: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/10.jpg)
![Page 11: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/11.jpg)
![Page 12: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/12.jpg)
BR/EDR (RFCOMM)
Bluetooth LTE (GATT)
![Page 13: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/13.jpg)
![Page 14: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/14.jpg)
詳細はブログに書いています
Texas InstrumentBluetooth Low Energy(CC2541)SensorTag
温度センサ湿度センサ圧力センサ加速度計ジャイロスコープ磁力計
![Page 15: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/15.jpg)
![Page 16: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/16.jpg)
RFCOMM Scenario: Send File as a Client(XAML)
RFCOMM Scenario: Receive File as a Server(XAML)
GATT Scenario: Retrieve Bluetooth LE Data(XAML)
GATT Scenario: Control a Bluetooth LE Thermometer Device(XAML)
Bluetooth for Windows Phone 8
【連載】Bluetooth LE (1) Bluetooth Low Energy の基礎
Bluetooth SMART デバイス(LE GATT Profile)と連携するWindows Store Appsの開発
![Page 17: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/17.jpg)
http://code.msdn.microsoft.com/windowsapps/Bluetooth-Rfcomm-Chat-afcee559/view/Discussions#content
http://code.msdn.microsoft.com/windowsapps/Bluetooth-Generic-5a99ef95/
http://blogs.msdn.com/b/flecoqui/archive/2013/12/13/windows-store-and-windows-phone-app-to-app-communication-over-bluetooth.aspx
![Page 18: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/18.jpg)
![Page 19: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/19.jpg)
http://msdn.microsoft.com/ja-jp/library/windows/apps/dn263090.aspx
![Page 20: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/20.jpg)
<Capabilities><m2:DeviceCapability Name="bluetooth.rfcomm"><m2:Device Id="any">
<m2:Function Type="serviceId:BEFB3B5F-C81D-48BB-8136-72E6BC3D0169"/></m2:Device>
</m2:DeviceCapability><m2:DeviceCapability Name="bluetooth.genericAttributeProfile"><m2:Device Id="any">
<m2:Function Type="serviceId:f000aa00-0451-4000-b000-000000000000" /><m2:Function Type="serviceId:f000aa10-0451-4000-b000-000000000000" />
</m2:Device></m2:DeviceCapability>
</Capabilities>
![Page 21: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/21.jpg)
<Capabilities><m2:DeviceCapability Name="bluetooth.rfcomm"><m2:Device Id="any">
<m2:Function Type="serviceId:BEFB3B5F-C81D-48BB-8136-72E6BC3D0169"/></m2:Device>
</m2:DeviceCapability><m2:DeviceCapability Name="bluetooth.genericAttributeProfile"><m2:Device Id="any">
<m2:Function Type="serviceId:f000aa00-0451-4000-b000-000000000000" /><m2:Function Type="serviceId:f000aa10-0451-4000-b000-000000000000" />
</m2:Device></m2:DeviceCapability>
</Capabilities>
![Page 22: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/22.jpg)
https://github.com/tanaka-takayoshi/BluetoothRfcommUniversalApp
![Page 23: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/23.jpg)
//appxmanifet で指定したServiceUUIDを使うrfcommProvider = await RfcommServiceProvider.CreateAsync(
RfcommServiceId.FromUuid(BluetoothServiceUuid));
//Socket作成して、Clientからの接続を待機socketListener = new StreamSocketListener();socketListener.ConnectionReceived += OnConnectionReceived;
await socketListener.BindServiceNameAsync(rfcommProvider.ServiceId.AsString(),SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);
//SDPに設定する部分は略//Advertising開始rfcommProvider.StartAdvertising(socketListener);
![Page 24: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/24.jpg)
//ペアリングされている端末を検出PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";var Peers = await PeerFinder.FindAllPeersAsync();//検出した端末から1台選択var device =
(await BluetoothRfcommClient.GetListPairedDevices()).First();
socket = new StreamSocket();await socket.ConnectAsync(
new HostName(device.HostName), BluetoothServiceName);
//Advertising停止PeerFinder.Stop();
![Page 25: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/25.jpg)
writer = new DataWriter(socket.OutputStream);
//送信するバイトの長さ+byte配列を書きこみwriter.WriteUInt32((uint)Command.CommandLength);writer.WriteBytes(Command.CommandBytes);await writer.StoreAsync();
![Page 26: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/26.jpg)
Bluetooth SMART デバイス(LE GATT Profile)と連携するWindows Store Appsの開発
https://github.com/tanaka-takayoshi/TISensor.Rx
![Page 27: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/27.jpg)
//SensorごとのUUIDを指定して端末を検出するvar selector = GattDeviceService.GetDeviceSelectorFromUuid(
new Guid(sensorServiceUuid));var devices = await DeviceInformation.FindAllAsync(selector);var device = devices.First();
//ID指定でサービスを作成deviceService = await GattDeviceService.FromIdAsync(deviceInfo.Id);
//センサーを有効化 (センサーによっては書きこむ値が違う)var configCharacteristic = deviceService.GetCharacteristics(
new Guid(sensorConfigUuid)).First();await configCharacteristic.WriteValueAsync(new byte[] {1}.AsBuffer());
![Page 28: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/28.jpg)
![Page 29: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/29.jpg)
![Page 30: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/30.jpg)
dataCharacteristic = deviceService.GetCharacteristics(new Guid(sensorDataUuid)).First();
await dataCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(
GattClientCharacteristicConfigurationDescriptorValue.Notify);
dataCharacteristic.ValueChanged += (sender, args) =>{
ReadRawData(args);};
![Page 31: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/31.jpg)
public IObservable<SensorRawValue> StartMonitor(){
returnObservable.FromEventPattern<
TypedEventHandler<GattCharacteristic,GattValueChangedEventArgs>,
GattValueChangedEventArgs>(h => dataCharacteristic.ValueChanged += h,h => dataCharacteristic.ValueChanged -= h)
.Select(p => ReadRawData(p.EventArgs));}
![Page 32: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/32.jpg)
using
![Page 33: 20140802 Bluetooth を使って Universall App で大連携](https://reader034.vdocuments.pub/reader034/viewer/2022050921/5560b6e1d8b42aef3b8b4a36/html5/thumbnails/33.jpg)