Slide 1

Slide 1 text

EVERYTHING ABOUT BLUETOOTH Johnny Sung

Slide 2

Slide 2 text

https://fb.com/j796160836 Johnny Sung Mobile devices Developer https://plus.google.com/+JohnnySung http://about.me/j796160836

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

MessageHorn https://play.google.com/store/apps/details?id=com.JohnnyWorks.messagehorn https://itunes.apple.com/tw/app/messagehorn/id994783068 iOS Server Android Client iOS Server Android Client

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

#-6&5005)➝稲

Slide 7

Slide 7 text

http://www.redicecreations.com/article.php?id=31630 ⚆私儘⚸띋涸㕜桬ㆁ䬘晋♧⚆ )BSBME#M¤UBOE(PSNTFO  罜➮涸そ㶶#M¤UBOE湬缺㽠僽չ话暆պ CM¤话UBOE暆 〢⻍姘铃涸薊铃⻋隶넓歋)BHBMMㄤ#KBSLBO涸穉ざ⛳㽠僽)BSBME#M¤UBOE涸껷㶶嫢չ)#պ涸ざ㻨 http://www.ettoday.net/dalemon/post/3250

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

2.0 2.0 + 4.0 Dual Mode 4.0 Bluetooth SMART READY Bluetooth Bluetooth SMART

Slide 10

Slide 10 text

#-&嚌䙂

Slide 11

Slide 11 text

Bluetooth low energy Protocol Stack

Slide 12

Slide 12 text

• Peripheral ヰ鼹酤縨 • Central • Broadcaster • Observer GAP Roles

Slide 13

Slide 13 text

Peripheral Central

Slide 14

Slide 14 text

Peripheral Central

Slide 15

Slide 15 text

Peripheral Central

Slide 16

Slide 16 text

GATT

Slide 17

Slide 17 text

• Service • Characteristic • Data • Descriptor GATT

Slide 18

Slide 18 text

• Heart Rate Service • Heart Rate Measurement • Data • Descriptor 00002A37-0000-1000-8000-00805F9B34FB GATT Heart Rate Monitor 0000180D-0000-1000-8000-00805F9B34FB Property: Notify

Slide 19

Slide 19 text

Property: Indicate • Health Thermometer • Temperature Measurement • Data • Descriptor GATT Health Thermometer 00001809-0000-1000-8000-00805F9B34FB 00002A1C-0000-1000-8000-00805F9B34FB

Slide 20

Slide 20 text

• Read • Write • Notify • Indicate Characteristic Properties

Slide 21

Slide 21 text

UUID 00002A37-0000-1000-8000-00805F9B34FB 0x2A37 Heart Rate Measurement

Slide 22

Slide 22 text

• an indicate operation is identical to a notify operation except that indications are acknowledged, while notifications are not. Notify vs Indicate http://mbientlab.com/blog/bluetooth-low-energy-introduction/

Slide 23

Slide 23 text

https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx? u=org.bluetooth.service.health_thermometer.xml

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Property: Indicate • Health Thermometer • Temperature Measurement • Data • Descriptor GATT Health Thermometer 00001809-0000-1000-8000-00805F9B34FB 00002A1C-0000-1000-8000-00805F9B34FB

Slide 29

Slide 29 text

"/%30*%㻜⡲

Slide 30

Slide 30 text

• Central • Android 4.3 (API Level 18) • Peripheral • Android 5.0 (API Level 21) • Specific BLE chip Requirement in Android

Slide 31

Slide 31 text

CENTRAL

Slide 32

Slide 32 text

• Discover • Connect • Explore • Interact Central֥ඹἠᾲ؍ 䵃㼦酤縨 鸮䱺 䱳程须俲穡圓 ✽⹛

Slide 33

Slide 33 text


 
 
 Bluetooth⃴ཋ ᄝ"OESPJE.BOJGFTUYNMࡆഈ

Slide 34

Slide 34 text

Bluetooth⃴ཋ ⃷ק൞ڎᆦჱ#-& getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) @Override
 public void onActivityResult(int requestCode , int resultCode, Intent data) {
 if (requestCode == REQUEST_ENABLE_BT) {
 if (resultCode == Activity.RESULT_OK) {
 // Bluetooth has turned on
 } else {
 // User did not enable Bluetooth or an error occurred
 }
 }
 } Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
 startActivityForResult(enableIntent, REQUEST_ENABLE_BT); ေ౰յῘῴ࿩

Slide 35

Slide 35 text

Discover ෆ⇨⊬ᇂ BluetoothManager manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
 BluetoothAdapter adapter = manager.getAdapter(); adapter.startLeScan(scanCallback); adapter.stopLeScan(scanCallback); ଦ֞#MVFUPPUI"EBQUFS Ῐ൓ෆ⇨ ᾵ඏෆ⇨ This method was deprecated in API level 21 API level 18

Slide 36

Slide 36 text

Discover ෆ⇨⊬ᇂ BluetoothAdapter.LeScanCallback scanCallback =
 new BluetoothAdapter.LeScanCallback() {
 @Override
 public void onLeScan(final BluetoothDevice device , final int rssi , byte[] scanRecord) {
 addDevice(device, rssi);
 // Add device to list
 }
 }; ෆ⇨֥$BMMCBDL This method was deprecated in API level 21 API level 18

Slide 37

Slide 37 text

scanner.stopScan(scanCallback); scanner.startScan(filters, settings, scanCallback); Ῐ൓ෆ⇨ ᾵ඏෆ⇨ Discover ෆ⇨⊬ᇂ ڿႨ#MVFUPPUI-F4DBOOFS API level 21 BluetoothManager manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
 BluetoothAdapter adapter = manager.getAdapter(); BluetoothLeScanner scanner = adapter.getBluetoothLeScanner(); // Setting ScanFilter and ScanSettings

Slide 38

Slide 38 text

Discover ෆ⇨⊬ᇂ ArrayList filters = new ArrayList<>();
 ScanFilter.Builder fb = new ScanFilter.Builder();
 fb.setServiceUuid(new ParcelUuid(UUID.fromString("...")));
 filters.add(fb.build()); 
 ScanSettings.Builder sb = new ScanSettings.Builder();
 ScanSettings settings = sb.build(); ෆ⇨⇢⇊ API level 21

Slide 39

Slide 39 text

Discover ෆ⇨⊬ᇂ ෆ⇨⇢⇊ • ScanFilter • ServiceUuid • ServiceData • DeviceAddress • DeviceName • ManufacturerData API level 21

Slide 40

Slide 40 text

Discover ෆ⇨⊬ᇂ ෆ⇨⇢⇊ • ScanSettings • CallbackType (All matches / First match / Match lost) • MatchMode • NumOfMatches • ScanMode (Low latency / Balanced / Low power) API level 21

Slide 41

Slide 41 text

ScanCallback scanCallback = new ScanCallback() {
 @Override
 public void onScanResult(int callbackType , ScanResult result) {
 if (callbackType == ScanSettings.CALLBACK_TYPE_ALL_MATCHES) {
 // Add device to list
 }
 }
 
 @Override
 public void onScanFailed(int errorCode) {
 Log.e("Scan Failed", "Error Code: " + errorCode);
 } @Override
 public void onBatchScanResults(List results) { }
 }; Discover ෆ⇨⊬ᇂ ෆ⇨$BMMCBDL API level 21

Slide 42

Slide 42 text

Discover ෆ⇨⊬ᇂ ਙԛෆ⇨֥֞⊬ᇂ

Slide 43

Slide 43 text

Connect ’ࢤ⊬ᇂ ’ࢤ⊬ᇂ String deviceAddress = "0A:0B:0C:0D:0F:10";
 BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address); BluetoothGatt mBluetoothGatt = device.connectGatt(this, false, mGattCallback); API level 18

Slide 44

Slide 44 text

private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
 @Override
 public void onConnectionStateChange(BluetoothGatt gatt , int status, int newState) {
 switch (newState) {
 case BluetoothProfile.STATE_CONNECTED: // do discoverServices
 break;
 case BluetoothProfile.STATE_DISCONNECTED:
 break;
 
 case BluetoothProfile.STATE_CONNECTING:
 case BluetoothProfile.STATE_DISCONNECTING:
 break;
 }
 }
 
 // More ...
 }; Connect ’ࢤ⊬ᇂ (BUU$BMMCBDL API level 18

Slide 45

Slide 45 text

Explore ฐ෬⊷ਘ᾵ἧ ෆ⇨4FSWJDFT API level 18 mBluetoothGatt.discoverServices(); private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
 // ... Continued 
 @Override
 public void onServicesDiscovered(BluetoothGatt gatt , int status) {
 if (status == BluetoothGatt.GATT_SUCCESS) {
 // Do Something
 }
 } // More ...
 }; (BUU$BMMCBDL ⇟

Slide 46

Slide 46 text

Explore ฐ෬⊷ਘ᾵ἧ ౼֤4FSWJDFT API level 18 BluetoothGattService gattService = mBluetoothGatt.getService(UUID.fromString("..."));
 BluetoothGattCharacteristic characteristic = gattService.getCharacteristic(UUID.fromString("..."));
 ౼֤$IBSBDUFSJTUJD

Slide 47

Slide 47 text

Explore ฐ෬᾵ἧ ਙԛ෮Ⴕ֥4FSWJDFT

Slide 48

Slide 48 text

Explore ฐ෬᾵ἧ ਙԛ෮Ⴕ֥$IBSBDUFSJTUJDT

Slide 49

Slide 49 text

Interact ޺ọ ồ౼$IBSBDUFSJTUJD֥ᆴ API level 18 byte[] bytes = characteristic.getValue(); private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { // ... Continued
 @Override
 public void onCharacteristicRead(BluetoothGatt gatt,
 BluetoothGattCharacteristic characteristic, int status) {
 if (status == BluetoothGatt.GATT_SUCCESS) {
 // Do Something
 }
 } // More ...
 }; (BUU$BMMCBDL ⇟

Slide 50

Slide 50 text

Interact ޺ọ ồ౼$IBSBDUFSJTUJD֥ᆴ API level 18 byte[] bytes = characteristic.getValue(); float floatValue = characteristic.getFloatValue( BluetoothGattCharacteristic.FORMAT_FLOAT, 0); 
 int intValue = characteristic.getIntValue( BluetoothGattCharacteristic.FORMAT_SINT8, 0); 
 int uintValue = characteristic.getIntValue( BluetoothGattCharacteristic.FORMAT_UINT8, 0); 
 String stringValue = characteristic.getStringValue(0); ὕॖၛ≾∄ồ౼ mBluetoothGatt.setCharacteristicNotification(characteristic, true);
 UUID CCCD = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
 BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CCCD);
 descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
 mBluetoothGatt.writeDescriptor(descriptor);

Slide 51

Slide 51 text

Interact ޺ọ 䩏⤳$IBSBDUFSJTUJD֥/PUGJDBUJPO۷ྍ API level 18 mBluetoothGatt.setCharacteristicNotification(characteristic, true);
 UUID CCCD = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
 BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CCCD);
 descriptor.setValue( BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
 mBluetoothGatt.writeDescriptor(descriptor); private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { // ... Continued
 @Override
 public void onCharacteristicChanged(BluetoothGatt gatt,
 BluetoothGattCharacteristic characteristic) {
 // Do Something
 }
 }; (BUU$BMMCBDL ⇟

Slide 52

Slide 52 text

Interact ޺ọ թ౼$IBSBDUFSJTUJDT

Slide 53

Slide 53 text

Samples https://github.com/j796160836/nRFSample_uCXpresso-Android nRFSample-Android https://github.com/j796160836/nRFSample_uCXpresso-iOS nRFSample-iOS https://github.com/googlesamples/android-BluetoothLeGatt android-BluetoothLeGatt

Slide 54

Slide 54 text

Develop tools https://play.google.com/store/apps/details?id=no.nordicsemi.android.nrftoolbox nRF Toolbox https://itunes.apple.com/tw/app/id557428110 LightBlue Explorer (iOS) https://itunes.apple.com/us/app/id820906058 nRF Toolbox (iOS) https://play.google.com/store/apps/details?id=com.kyriakosalexandrou.bluetoothsupportcheck BLE Central,Peripheral Check https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner BLE Scanner: Read,Write,Notify Andorid

Slide 55

Slide 55 text

Develop tools https://itunes.apple.com/tw/app/id557428110 LightBlue Explorer https://itunes.apple.com/us/app/id820906058 nRF Toolbox iOS https://itunes.apple.com/tw/app/lightblue/id639944780?mt=12 Mac LightBlue

Slide 56

Slide 56 text

MessageHorn

Slide 57

Slide 57 text

MessageHorn for iOS https://itunes.apple.com/tw/app/messagehorn/id994783068

Slide 58

Slide 58 text

MessageHorn for Android Wear When messaging Connected to device Device selection Main https://play.google.com/store/apps/details?id=com.JohnnyWorks.messagehorn

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

MessageHorn https://play.google.com/store/apps/details?id=com.JohnnyWorks.messagehorn https://itunes.apple.com/tw/app/messagehorn/id994783068 iOS Server Android Client iOS Server Android Client

Slide 61

Slide 61 text

AndroidWear⛳〳⟃䖎惐

Slide 62

Slide 62 text

Q&A

Slide 63

Slide 63 text

• https://developer.bluetooth.org/gatt/services/Pages/ ServicesHome.aspx • https://www.safaribooksonline.com/library/view/getting-started- with/9781491900550/ch04.html • http://gogoprivateryan.blogspot.tw/2014/09/cc2540-bluetooth-low- energy-3.html • http://www.redicecreations.com/article.php?id=31630 • http://mbientlab.com/blog/bluetooth-low-energy-introduction/ References

Slide 64

Slide 64 text

https://www.facebook.com/groups/353660298163446/ 穿戴式裝置開發者社群 歡迎您的加⼊入