Successfully reported this slideshow.
Your SlideShare is downloading. ×

Core Bluetooth on iOS

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 43 Ad

More Related Content

Similar to Core Bluetooth on iOS (20)

Advertisement

Recently uploaded (20)

Core Bluetooth on iOS

  1. 1. 現實⽣生活中的經驗使⽤用 BLE David Chu Monday, November 18, 13
  2. 2. core bluetooth timeLINE WWDC 2013 Monday, November 18, 13 開始 讀書 睡好 現在
  3. 3. core bluetooth timeLINE WWDC 2013 Monday, November 18, 13 開始 讀書 睡好 現在
  4. 4. BT4.0 Not Backwards Compatible 1.0 Monday, November 18, 13 2.0 3.0 4.0
  5. 5. Streaming @ Max 30 mA Classic Packets @ Max 15 mA 4.0 Monday, November 18, 13
  6. 6. Hardware Monday, November 18, 13
  7. 7. BLE Specs Range Data 1 Mbps Power 1 year Proximity Monday, November 18, 13 50 m RSSI
  8. 8. Power 1 year? Monday, November 18, 13
  9. 9. Monday, November 18, 13
  10. 10. Monday, November 18, 13
  11. 11. CR2032 225 mAh Data Transaction Time 3s Max Antenna Power 15 mA 225 mAh / 15mA = 15 hours 15 hours = 54,000,000 ms 54M ms / 3 ms = 18M transactions 1 transaction every second = ~7 months Monday, November 18, 13
  12. 12. Data 1 Mbps? Monday, November 18, 13
  13. 13. Bluetooth HW Bluetooth SW 270 kbps Streaming Music 120 - 320 kps Real Life Monday, November 18, 13 1 Mbps Streaming Video 720x486 Max 56 kbps ?
  14. 14. Monday, November 18, 13
  15. 15. Monday, November 18, 13
  16. 16. Range 50 m? Monday, November 18, 13
  17. 17. Monday, November 18, 13
  18. 18. Monday, November 18, 13
  19. 19. Monday, November 18, 13
  20. 20. Actual Range Bluetooth Spec Range 50 m Our Tested Range 30 m Monday, November 18, 13
  21. 21. Still Need Testing Monday, November 18, 13
  22. 22. Proximity RSSI Accuracy? Monday, November 18, 13
  23. 23. Standing Still Monday, November 18, 13
  24. 24. Software Monday, November 18, 13
  25. 25. Core Bluetooth App States and Multitasking State Preservation and Restoration Monday, November 18, 13
  26. 26. iOS as bluetooth-central • Scan • Connect • Read • Write • Subscribe Monday, November 18, 13
  27. 27. Monday, November 18, 13
  28. 28. Monday, November 18, 13
  29. 29. Monday, November 18, 13
  30. 30. Monday, November 18, 13
  31. 31. [centralManager scanForPeripheralsWithServices:serviceUUIDs options:options]; Core Bluetooth peripheral Bluetooth Device Address 00:22:D0:00:AC:92 BDA NSUUID Your App (NSUUID *) peripheral.identifier = 68753A44-4D6F-1226-9C60-0050E4C00067 // CBCentralManagerDelegate - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI { // peripheral.services is empty until you call [peripheral discoverServices:]; NSArray *serviceUUIDs = [advertismentData objectForKey: CBAdvertisementDataServiceUUIDsKey]; } Monday, November 18, 13
  32. 32. (NSDictionary *)advertisementData CBAdvertisementDataLocalNameKey Name of Device CBAdvertisementDataManufacturerDataKey ID for Manufacturer CBAdvertisementDataServiceDataKey Dictionary with serviceUUIDs and data CBAdvertisementDataServiceUUIDsKey Array of serviceUUIDs CBAdvertisementDataTxPowerLevelKey Power Level of Transmission (optional) CBAdvertisementDataIsConnectable If Device data is connectable Monday, November 18, 13
  33. 33. [centralManager connectPeripheral:peripheral options:options]; iOS Keychain peripheral Bluetooth Device Address 00:22:D0:00:AC:92 BDA NSUUID Your App Monday, November 18, 13 (NSUUID *) peripheral.identifier = 68753A44-4D6F-1226-9C60-0050E4C00067
  34. 34. // Check Peripherals That Your App Has Connected To Before - (NSArray *)retrievePeripheralsWithIdentifiers:(NSArray *)identifiers // Check Peripherals Already Connected To iPhone // Peripherals may be connected to other apps, but not yours - (NSArray *)retrieveConnectedPeripheralsWithServices:(NSArray *)serviceUUIDs // Scan For New Peripherals - (void)scanForPeripheralsWithServices:(NSArray *)serviceUUIDs options:(NSDictionary *)options // Callback in CBCentralManagerDelegate - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI -connectPeripheral:options: Monday, November 18, 13
  35. 35. CBCentralManager Scan for all peripherals Foreground Can have multiple peripheral discoveries Scan frequency normal CBPeripheralManager Service UUIDs are advertised Device Name advertised Advertising frequency highest Can only scan for service UUID Monday, November 18, 13 Peripheral discovered only once Device Name is hidden Scan frequency 55x less Background ServiceUUIDs are hidden Advertising frequency decreased
  36. 36. Reconnecting Peripheral Foreground Active - Visible Background Active - Not Visible Suspended Inactive - In Memory Terminated Not in Memory Monday, November 18, 13 // CBCentralMangerDelegateProtocol - centralManager:central didDisconnectPeripheral:peripheral error:error { if (error) { // User did not cancel connection. Reconnect. // Connection Requests DO NOT TIME OUT [central connectPeripheral:peripheral options:nil]; } } // CBCentralMangerDelegateProtocol - centralManager:central didConnectPeripheral:peripheral { // App will be brought back to background state } State Preservation and Restore
  37. 37. Scanning For Peripherals Foreground Active - Visible Background Active - Not Visible Suspended Inactive - In Memory Terminated Not in Memory Monday, November 18, 13 // CBCentralMangerDelegateProtocol - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData: (NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI { // Device can connect to BLE Peripheral and run task // In Background, you have 10s to complete task. // Background scanning also runs 55X slower or more. } Scanning is not possible iOS cannot guarantee that you will not be suspended or that you will be brought back to background once suspended.
  38. 38. Your App Monday, November 18, 13 If the user removes your app in the multi-tasking window, then all your background operations stop.
  39. 39. Resources Monday, November 18, 13
  40. 40. LightBlue Monday, November 18, 13
  41. 41. https://github.com/ddaddy/BackgroundKill Monday, November 18, 13
  42. 42. https://lists.apple.com/mailman/listinfo/bluetooth-dev Monday, November 18, 13
  43. 43. Monday, November 18, 13

×