Stefano Zanetti § DevCamp
iBeacons
the new low-powered way of location awareness
DevCamp
Stefano Zanetti
 Apple iOS Developer
Superpartes Innovation Campus & H-Farm	

!
 Co-founder di
# Pragma Mark ― w...
DevCamp
What is a Beacon?
A Bluetooth LE radio, some minor electronic
components and a button cell.
That’s all!
DevCamp
estimote.com radiusnetworks.com kontakt.io
DevCamp
How Beacons could change the world:
1. Your home will automatically react to you.
2. Your phone will give you a to...
DevCamp
Bluetooth LE
DevCamp
a lot of versions…
• first stable version 1.2 (2003)	

• 2.0 + EDR (2004)	

• 2.1 + EDR (2007)	

• 3.0 + HS (2009)	...
DevCamp
ISM 2.4GHz
This is in the globally unlicensed (but not
unregulated) Industrial, Scientific and Medical
(ISM) 2.4 GH...
DevCamp
Mbit/s
0
7,5
15
22,5
30
version
v1.2 v2.o+EDR v3.0+HS v4.0 v4 LE
0,3Mbit/s
24Mbit/s24Mbit/s
3Mbit/s1Mbit/s
Speed
DevCamp
Other differences
classic bluetooth bluetooth low energy
latency 100ms 6ms
total time to
send data
100ms 3ms
peak ...
DevCamp
Single and Double mode
Classic and low energy BT are not
compatible with each other
Single-mode
devices
Classic OR...
DevCamp
Connectionless
Devices do not need to maintain a connection
for useful information to be exchanged quickly
between...
DevCamp
Stateless
Any client can send any request at any time
and the server will respond to the same
request in exactly t...
DevCamp
Packet structure
DevCamp
Advertising packet
• Preamble - 1 Byte - fixed 8bit to synchronize bit timing and set
radio’s automatic gain contro...
DevCamp
iBeacon
DevCamp
iBeacon is a new technology that
extends Location Services in iOS
iBeacons provide a way to create and
monitor bea...
DevCamp
example of iBeacon PDU
9F436059ADC00201061AFF4C000215B9407F30F5F8466EAFF925556B57FE6D010000FFB6
9F436059ADC0: Beac...
DevCamp
iOS Frameworks
iBeacon
Core
Bluetooth
Core
Location
DevCamp
iOS Classes
CLBeacon
CLLocationManager
CLLocationManagerDelegate
CBPeripheralManager
CBPeripheral
CBCentralManager...
DevCamp
CLBeacon
Identifying the Beacon


    proximityUUID  property


    major  property


    minor  property
!
Determ...
DevCamp
CLBeaconRegion
Initializing the Beacon Region
!! – initWithProximityUUID:identifier:
!! – initWithProximityUUID:ma...
DevCamp
Code
DevCamp
iDevice as an iBeacon
self.manager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
!
NSUUID *uuid...
DevCamp
Monitoring & Ranging
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@“666972D4-9BE7-4E7D-
A1D4-973E1285BE19"];
...
DevCamp
- (void)locationManager:(CLLocationManager *)manager didDetermineState:
(CLRegionState)state forRegion:(CLRegion *...
DevCamp
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray
*)beacons inRegion:(CLBeaconRegion *...
DevCamp
Background mode
DevCamp
Background region monitoring
If a region boundary is crossed while an app isn’t running, that app
is relaunched in...
DevCamp
but…
Region monitoring in background takes very long time to notify the
region change (up to 15min).
there is a li...
DevCamp
Limitations
1. Signal interference
2. Very small data packets
3. Easy to sniff advertising packets
4. Easy to clon...
DevCamp
Internet & Books
http://developer.radiusnetworks.com
http://estimote.com
https://www.bluetooth.org/en-us/specificat...
DevCamp
Link
!
facebook.com/pragmamark	

facebook.com/groups/pragmamark	



@pragmamarkorg	

!
!
http://pragmamark.org
DevCamp
NSLog(@”Thank you!”);
stefano.zanetti@pragmamark.org
Upcoming SlideShare
Loading in …5
×

iBeacons - the new low-powered way of location awareness

1,653 views
1,275 views

Published on

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,653
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
42
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

iBeacons - the new low-powered way of location awareness

  1. 1. Stefano Zanetti § DevCamp iBeacons the new low-powered way of location awareness
  2. 2. DevCamp Stefano Zanetti  Apple iOS Developer Superpartes Innovation Campus & H-Farm !  Co-founder di # Pragma Mark ― www.pragmamark.org !  [tt] @stezanna
 [in] Stefano Zanetti
 [fb] stefano.znt 
 [email] stefano.zanetti@pragmamark.org
  3. 3. DevCamp What is a Beacon? A Bluetooth LE radio, some minor electronic components and a button cell. That’s all!
  4. 4. DevCamp estimote.com radiusnetworks.com kontakt.io
  5. 5. DevCamp How Beacons could change the world: 1. Your home will automatically react to you. 2. Your phone will give you a tour of museums. 3. Tickets that automatically load as you enter sporting events. 4. …
  6. 6. DevCamp Bluetooth LE
  7. 7. DevCamp a lot of versions… • first stable version 1.2 (2003) • 2.0 + EDR (2004) • 2.1 + EDR (2007) • 3.0 + HS (2009) • 4.0 & 4.0 LE (2010)
  8. 8. DevCamp ISM 2.4GHz This is in the globally unlicensed (but not unregulated) Industrial, Scientific and Medical (ISM) 2.4 GHz short-range radio frequency band 2400–2483.5 MHz
  9. 9. DevCamp Mbit/s 0 7,5 15 22,5 30 version v1.2 v2.o+EDR v3.0+HS v4.0 v4 LE 0,3Mbit/s 24Mbit/s24Mbit/s 3Mbit/s1Mbit/s Speed
  10. 10. DevCamp Other differences classic bluetooth bluetooth low energy latency 100ms 6ms total time to send data 100ms 3ms peak current consumption <30mA <15mA active slaves! 7 implementation dependent profile standard BT profile like SPP, DUN, PAN GATT: Generic Attribute profile paring YES NO
  11. 11. DevCamp Single and Double mode Classic and low energy BT are not compatible with each other Single-mode devices Classic OR low energy radio Double-mode devices Classic AND low energy radio
  12. 12. DevCamp Connectionless Devices do not need to maintain a connection for useful information to be exchanged quickly between them The connectionless model solves these problems by not defining the state of a connection, but the state of the device
  13. 13. DevCamp Stateless Any client can send any request at any time and the server will respond to the same request in exactly the same way, regardless of which client made the request.
  14. 14. DevCamp Packet structure
  15. 15. DevCamp Advertising packet • Preamble - 1 Byte - fixed 8bit to synchronize bit timing and set radio’s automatic gain control. 101010101 or 010101010 • Access Address - 4 Bytes - 32 fixed and random bit. 0x8E89BED6 (that in binary is 01101011011111011001000101110001.The preamble would be 01010101) • Header - 1 Byte - to describe the contents of packet • Length - 1 Byte - to describe the payload length • CRC - 3 Bytes: checksum calculated over PDU • PDU (Protocol Data Unit) - 37 Bytes
  16. 16. DevCamp iBeacon
  17. 17. DevCamp iBeacon is a new technology that extends Location Services in iOS iBeacons provide a way to create and monitor beacons that advertise certain identifying information using Bluetooth low energy wireless technology (ref. iOS 7: Understanding Location Services - Apple)
  18. 18. DevCamp example of iBeacon PDU 9F436059ADC00201061AFF4C000215B9407F30F5F8466EAFF925556B57FE6D010000FFB6 9F436059ADC0: Beacon’s Bluetooth MAC address 02: Length of the next field 01: Flags field identifier 06: Flags (LE General Discoverable Mode) 1A: Length of the next field FF: Manufacturer Specific Data field identifier 4C00: Apple’s ID 0215: Two fixed bytes B9407F30F5F8466EAFF925556B57FE6D: Proximity UUID 0100: Major 00FF: Minor B6: Measured power
  19. 19. DevCamp iOS Frameworks iBeacon Core Bluetooth Core Location
  20. 20. DevCamp iOS Classes CLBeacon CLLocationManager CLLocationManagerDelegate CBPeripheralManager CBPeripheral CBCentralManager CLBeaconRegion
  21. 21. DevCamp CLBeacon Identifying the Beacon    proximityUUID  property    major  property    minor  property ! Determining the Beacon Distance    proximity  property    accuracy  property    rssi  property
  22. 22. DevCamp CLBeaconRegion Initializing the Beacon Region !! – initWithProximityUUID:identifier: !! – initWithProximityUUID:major:identifier: !! – initWithProximityUUID:major:minor:identifier: Accessing the Beacon Attributes    proximityUUID  property    major  property    minor  property Delivering Beacon Notifications    notifyEntryStateOnDisplay  property Getting Beacon Advertisement Data !! – peripheralDataWithMeasuredPower:
  23. 23. DevCamp Code
  24. 24. DevCamp iDevice as an iBeacon self.manager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil]; ! NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@“666972D4-9BE7-4E7D- A1D4-973E1285BE19"]; ! CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:1234 minor:12 identifier:@“My region”]; ! [self.manager startAdvertising:[region peripheralDataWithMeasuredPower:nil]]; ! [self.manager stopAdvertising];
  25. 25. DevCamp Monitoring & Ranging NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@“666972D4-9BE7-4E7D- A1D4-973E1285BE19"]; ! CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@“My region”]; ! self.manager = [[CLLocationManager alloc] init]; self.manager.delegate = self; [self.manager startMonitoringForRegion:region]; [self.manager requestStateForRegion:region];
  26. 26. DevCamp - (void)locationManager:(CLLocationManager *)manager didDetermineState: (CLRegionState)state forRegion:(CLRegion *)region { if (state == CLRegionStateInside) { NSLog(@“INSIDE REGION"); [manager startRangingBeaconsInRegion:(CLBeaconRegion *)region]; } } ! - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { NSLog(@“ENTER REGION"); [manager startRangingBeaconsInRegion:(CLBeaconRegion *)region]; } ! - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { NSLog(@“EXIT REGION"); [manager stopRangingBeaconsInRegion:(CLBeaconRegion *)region]; }
  27. 27. DevCamp - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region { for (CLBeacon *beacon in beacons) { NSLog(@"%@ %@ %@ %zd %f", beacon.major, beacon.minor, @[@"Unknown", @"Immediate", @"Near", @"Far"][beacon.proximity], beacon.rssi, beacon.accuracy); } }
  28. 28. DevCamp Background mode
  29. 29. DevCamp Background region monitoring If a region boundary is crossed while an app isn’t running, that app is relaunched into the background to handle the event. In iOS, regions associated with your app are tracked at all times, including when the app isn’t running. Similarly, if the app is suspended when the event occurs, it’s woken up and given a short amount of time (around 10 seconds) to handle the event. When necessary, an app can request more background execution time using the beginBackgroundTaskWithExpirationHandler: method of the UIApplication class.
  30. 30. DevCamp but… Region monitoring in background takes very long time to notify the region change (up to 15min). there is a little trick: Set the notifyEntryStateOnDisplay toYES the location manager sends beacon notifications when the user turns on the display and the device is already inside the region.These notifications are sent even if your app is not running.
  31. 31. DevCamp Limitations 1. Signal interference 2. Very small data packets 3. Easy to sniff advertising packets 4. Easy to clone a beacon
  32. 32. DevCamp Internet & Books http://developer.radiusnetworks.com http://estimote.com https://www.bluetooth.org/en-us/specification/adopted-specifications “Bluetooth Low Energy:The Developer's Handbook” (Heydon, Robin)
  33. 33. DevCamp Link ! facebook.com/pragmamark facebook.com/groups/pragmamark 
 @pragmamarkorg ! ! http://pragmamark.org
  34. 34. DevCamp NSLog(@”Thank you!”); stefano.zanetti@pragmamark.org

×