Slide 1

Slide 1 text

How to use Apple iBeacons with Android Krakdroid 2013 radzio +RadoslawPiekarz radzio radzio

Slide 2

Slide 2 text

Agenda  Anyone knows, anyone saw  Short history about iBeacons  iBeacons on Android – approach #1  iBeacons on Android – approach #2  Show me the code!  Problems and challenges  Summary  Q&A

Slide 3

Slide 3 text

Anyone knows, anyone saw

Slide 4

Slide 4 text

Bluetooth 4.0  Bluetooth low energy is an open standard developed by the Bluetooth SIG. It is designed to address the needs of new wireless applications, such as ultra-low power consumption, fast connection times, reliability, and security. Bluetooth low energy consumes 10 to 20 times less power than its previous version and is able to transmit data 50 times quicker than conventional Bluetooth solutions.

Slide 5

Slide 5 text

June 2013 – Apple presents iBeacons

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

What about using iBeacons with Android?

Slide 8

Slide 8 text

iBeacons on Android – approach #1

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Something is wrong…

Slide 11

Slide 11 text

iBeacons on Android – approach #2 1. How do Beacons really work? 2. How can access iBeacon’s data?

Slide 12

Slide 12 text

iBeacon – how does it work?  iBeacons are usually small devices  They are broadcasting information every 0,2 – 1s  Smartphones scan for nearby iBeacons

Slide 13

Slide 13 text

What data iBeacons send? d6 be 89 8e 40 24 05 a2 17 6e 3d 71 02 01 1a 1a ff 4c 00 02 15 e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 00 00 00 00 c5 52 ab 8d 38 a5

Slide 14

Slide 14 text

What is the iBeacon Bluetooth Profile? d6 be 89 8e Access address for advertising data (this is always the same fixed value) 40 Advertising Channel PDU Header byte 0. Contains: (type = 0) 24 Advertising Channel PDU Header byte 1. Contains: (length = total bytes of the advertising payload + 6 bytes for the BLE mac address.) 05 a2 17 6e 3d 71 Bluetooth Mac address (note this is a spoofed address) 02 01 1a 1a ff 4c 00 02 15 e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 00 00 00 00 c5 Bluetooth advertisement 52 ab 8d 38 a5 checksum

Slide 15

Slide 15 text

Extracting data from the iBeacon  02 01 1a 1a ff 4c 00 02 15 – specification part  e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 – Proximity UUID (16 bytes)  00 00 – major (2 bytes)  00 00 – minor (2 bytes)  c5 - tx power (1 byte)

Slide 16

Slide 16 text

How to calculate the distance from iBeacon?

Slide 17

Slide 17 text

How to calculate the distance from beacon #2  We have 2 types of information :  Moc z jaką nadaje beacon  Siłę sygnału, która do nas dotarła // rssi – from Android’s BLE API // txPower – read from scan data byte array – see previous slides double ratio = (rssi *1.0) / txPower; double exponentMultiplier = 1.5; double multiplier = 12.0; double distanceInMeters = Math.pow(multiplier, ratio*exponentMultiplier)/Math.pow(multiplier, exponentMultiplier); return distanceInMeters

Slide 18

Slide 18 text

Show me the code! Permissions

Slide 19

Slide 19 text

Show me the code #2 // Initializes Bluetooth adapter. final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); private void scanLeDevice(final boolean enable) { if (enable) { // Stops scanning after a pre-defined scan period. mHandler.postDelayed(new Runnable() { @Override public void run() { mScanning = false; mBluetoothAdapter.stopLeScan(mLeScanCallback); } }, SCAN_PERIOD); mScanning = true; mBluetoothAdapter.startLeScan(mLeScanCallback); } else { mScanning = false; mBluetoothAdapter.stopLeScan(mLeScanCallback); } …

Slide 20

Slide 20 text

Show me the code #3 // Device scan callback. private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) { // do something } }; Parameters device Identifies the remote device rssi The RSSI value for the remote device as reported by the Bluetooth hardware. 0 if no RSSI value is available. scanRecord The content of the advertisement record offered by the remote device.

Slide 21

Slide 21 text

What can we do with iBeacons?  Check if users has entered or left region defined by one or more iBeacons  Check how far user is from the particular iBeacon[s] Hmm… I’ll use Android background Service for searching and monitoring iBeacons!

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

What about battery life?  Unlike iOS Android does not natively support iBeacons [yet]  We need to search for them, calculate the distance, check whether the user is within a given region  What if more applications will want to work with iBeacons at the same time?  Maybe we should scan for iBeacons only when the user is in an area that is defined by the geofence?

Slide 24

Slide 24 text

What about NFC?

Slide 25

Slide 25 text

What about NFC?  Enemies or complementary technologies?  Mobile payment = NFC  Tickets, entry cards = NFC?  Indoor navigation = iBeacons  Real world context = iBeacons/ NFC

Slide 26

Slide 26 text

iBeacons – pros & cons Pros  We get access to the context of real-world  Amazing new opportunities in terms of access to needed information  They just works + easy setup Cons  No native support on Android  Possibility of battery drains  Currently small percentage of Android phones support Bluetooth LE

Slide 27

Slide 27 text

Summary  iBeacons are a promising technology, which is worth exploring  New clients  NFC complementary  We can „easily” create indoor navigation  A lot of fun!

Slide 28

Slide 28 text

Q&A  Thanks for your attention! radzio +RadoslawPiekarz radzio radzio

Slide 29

Slide 29 text

Bonus – existing iBeacons Android SDKs  https://github.com/RadiusNetworks/android-ibeacon-service It might not work with all beacons  https://github.com/Estimote/Android-SDK (preview)  https://github.com/radzio/android-ibeacons (work in progress)