iBeacons e le novità di BLE [Mokapp 2013]

1,157 views
1,003 views

Published on

iBeacons e le novità di BLE

Published in: Technology, News & Politics

iBeacons e le novità di BLE [Mokapp 2013]

  1. 1. @if9 - francesco.nove@gmail.com - runcode.it iBeacons e le novità di BLE Francesco Novelli

  2. 2. Francesco Novelli chi? ❖ Freelance! ! ❖ iOS Developer! ❖ Web (Back-end) Developer! ❖ Windows 8 Developer!
  3. 3. Chi?? fag.it
  4. 4. Di cosa parliamo? ❖ iOS 7!! ❖ Bluetooth 4.0! ❖ iBeacons! ❖ Raspberry PI
  5. 5. iBeacons
  6. 6. iBeacons e le novità di BLE Bluetooth 4.0 • • • • Cos’è?! Il solito bluetooth? NO! Chi lo usa?! Come lo uso nella mia app?
  7. 7. Bluetooth 4.0: cos’è? ❖ BLE: Blueooth Low Energy! ❖ Standard dal 2010! ❖ Chip diverso dal 3.0-! ❖ Dual Chip Device
  8. 8. Bluetooth 4.0: Le novità ❖ Completamente differente!! ❖ Niente abbinamenti, PIN etc.! ❖ Advertising continuo! ❖ ❖ Low Power! 
 0.01-0.5 (BLE) vs 1 (classic)! Peak di <15 mA vs <30mA di classic
  9. 9. Bluetooth 4.0: Le novità ❖ Range: 50m vs 100m! ❖ Throughput: 0.27 Mbit/s vs 2.1 Mbit/s! ❖ Latency: 6ms vs 100ms
  10. 10. Bluetooth 4.0: Le novità ❖ Niente auricolari Bluetooth 4.0! ❖ Niente scambio foto à la Symbian! ❖ Niente cuffie BLE! ❖ quindi? che ci faccio?
  11. 11. Bluetooth 4.0: Chi lo usa? ❖ Orologi! ❖ Sport e fitness devices! ❖ Healtcare devices! ❖ Security devices! ❖ Proxymity! ❖ Automation! ❖ …
  12. 12. Bluetooth 4.0: Profili disponibili ❖ GATT Profiles:! ❖ http://is.gd/blegatt! ❖ Rivolto a developer! ❖ Rivolto a hardware makers
  13. 13. Bluetooth 4.0 in iOS ❖ CoreBluetooth.framework! ❖ Disponibile su iOS e Mac OS! ❖ CBPeripheral (ogni BLE device)! ❖ CBCentralManager (iOS BLE)
  14. 14. Bluetooth 4.0 in iOS ❖ init CBCentralManage! ❖ ricercare e connettersi con i BLE device che trasmettono! ❖ esplorare le info del device BLE (CBPeripheral)! ❖ Ricevere e inviare richieste con data! ❖ Registrare notifiche per cambio valori
  15. 15. Bluetooth 4.0 in iOS: Discovering myCentralManager =! [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil]; [myCentralManager scanForPeripheralsWithServices:nil options:nil]; - (void)centralManager:(CBCentralManager *)central! didDiscoverPeripheral:(CBPeripheral *)peripheral! advertisementData:(NSDictionary *)advertisementData! RSSI:(NSNumber *)RSSI {! ! NSLog(@"Discovered %@", peripheral.name);! ! }
  16. 16. Bluetooth 4.0 in iOS: Connecting [myCentralManager connectPeripheral:peripheral options:nil]; - (void)centralManager:(CBCentralManager *)central! didConnectPeripheral:(CBPeripheral *)peripheral {! ! NSLog(@"Peripheral connected");! ... peripheral.delegate = self;!
  17. 17. Bluetooth 4.0 in iOS: Services - (void)peripheral:(CBPeripheral *)peripheral! didDiscoverServices:(NSError *)error {! ! for (CBService *service in peripheral.services) {! NSLog(@"Discovered service %@", service);! ...! }! ...
  18. 18. Bluetooth 4.0 in iOS: Services NSLog(@"Discovering characteristics for service %@", interestingService);! [peripheral discoverCharacteristics:nil forService:interestingService]; - (void)peripheral:(CBPeripheral *)peripheral! didDiscoverCharacteristicsForService:(CBService *)service! error:(NSError *)error {! ! for (CBCharacteristic *characteristic in service.characteristics) {! NSLog(@"Discovered characteristic %@", characteristic);! ...! }! ...!
  19. 19. Bluetooth 4.0 in iOS: Read NSLog(@"Reading value for characteristic %@", interestingCharacteristic);! [peripheral readValueForCharacteristic:interestingCharacteristic]; - (void)peripheral:(CBPeripheral *)peripheral! didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic! error:(NSError *)error {! ! NSData *data = characteristic.value;! // parse the data as needed! ... [peripheral setNotifyValue:YES forCharacteristic:interestingCharacteristic];
  20. 20. bpm Demo cardioble
  21. 21. bpm Demo
  22. 22. iBeacons e le novità di BLE iBeacons • • • • • Cos’è?! Come funziona?! Come si costruisce?! Quanto costa?! Come lo uso nella mia app?
  23. 23. iBeacons iBeacon, a new class of low-powered, low-cost transmitters that can notify nearby iOS 7 devices of their presence, provides apps a whole new level of location awareness, such as trail markers in a park, exhibits in a museum, or product displays in stores.
  24. 24. iBeacons: trasmette..? ❖ 3 info: UUDID, major, minor! ❖ SEMPRE! ❖ a qualsiasi BLE device attivo! ❖ nothing else matter
  25. 25. iBeacons IDs ❖ UUDID: E2C56DB5-DFFB-48D2-B060-D0F5A71096E0! ❖ Major: int! ❖ Minor: int! ❖ Major e Minor ID qualunque, ID generici
  26. 26. iBeacons IDs ❖ UUDID: E2C56DB5-DFFB-48D2-B060-D0F5A71096E0
 McDonald! ❖ Major: int 17
 Grosseto! ❖ Minor: int 9
 Cassa 9! ❖ quindi…! ❖ sei nel McDonald di Grosseto alla Cassa 9.
 propongo pagamento tramite app per il conto della Cassa 9.
  27. 27. iBeacons IDs ❖ UUDID: E2C56DB5-DFFB-48D2-B060-D0F5A71096E0
 Museo Uffizi! ❖ Major: int 2
 Piano 2! ❖ Minor: int 13
 Quadro 13! ❖ quindi…! ❖ sei nel Museo al secondo piano davanti al quadro 13.
 propongo audio guida per quel quadro.
  28. 28. iBeacons: come funziona? ❖ iOS device! ❖ MiniPC con Bluetooth 4.0! ❖ Standalone device! ❖ Estimone, etc..

  29. 29. iBeacons: iOS Beacon Adv Progetto AirLocate! CoreBluetooth.framework _peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; NSDictionary *peripheralData = nil; if(_uuid && _major && _minor) { CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:_uuid major:[_major shortValue] minor:[_minor shortValue] identifier:@"com.apple.AirLocate"]; peripheralData = [region peripheralDataWithMeasuredPower:_power]; } [_peripheralManager startAdvertising:peripheralData];
  30. 30. iBeacons: Quanto costa? low-cost transmitters Nome Estimote Costo Tempi 99$ x 3 (33$ each) Late December Affdabilità ***** BLE Mini 30£ each Weeks **** Alibaba seller 10$-20$ Days/Week ***
  31. 31. iBeacons: come lo uso? ❖ Monitoring! ❖ Notify
  32. 32. iBeacons: Monitoring _locationManager = [[CLLocationManager alloc] init]; _locationManager.delegate = self; CLBeaconRegion *region = nil; _uuid = [[NSUUID alloc] initWithUUIDString:@“E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"]; region = [[CLBeaconRegion alloc] initWithProximityUUID:_uuid identifier:@"com.apple.AirLocate"]; [_locationManager startRangingBeaconsInRegion:region]; ! ! - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region { ! ! NSLog(@"Major: %@, Minor: %@, Acc: %.2fm %li", beacon.major, beacon.minor, beacon.accuracy, beacon.proximity); ! }
  33. 33. bpm Demo
  34. 34. iBeacons: Notify _locationManager = [[CLLocationManager alloc] init]; _locationManager.delegate = self; CLBeaconRegion *region = nil; _uuid = [[NSUUID alloc] initWithUUIDString:@“E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"]; region = [[CLBeaconRegion alloc] initWithProximityUUID:_uuid identifier:@"com.apple.AirLocate"]; region.notifyOnEntry = YES; region.notifyOnExit = YES; region.notifyEntryStateOnDisplay = YES; [_locationManager startMonitoringForRegion:region]; NSNumber *major = @2; NSNumber *minor = @2; region = [[CLBeaconRegion alloc] initWithProximityUUID:_uuid major:[major shortValue] minor:[minor shortValue] identifier:@"com.apple.AirLocate"];
  35. 35. iBeacons: Notify - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region; - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region; typedef NS_ENUM(NSInteger, CLRegionState) { - (void)locationManager:(CLLocationManager *)manager CLRegionStateUnknown, CLRegionStateInside, didDetermineState:(CLRegionState)state CLRegionStateOutside forRegion:(CLRegion *)region; } NS_ENUM_AVAILABLE_IOS(7_0); PS: CLBeacon *beacon = (CLBeacon *)region;
  36. 36. bpm Demo
  37. 37. iBeacons on Raspberry PI ❖ Compra un Raspberry PI. ORA!! ❖ Compra un adattatore BLE. 10€ on Amazon! ❖ Collegali ed esegui i comandi delle prossime slide..
  38. 38. iBeacons on Raspberry PI apt-get update! apt-get install libglib2.0-dev libdbus-1-dev libudev-dev libical-dev libreadline6-dev! wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.9.tar.xz! tar xvJf bluez-5.9.tar.xz! cd bluez-5.9! ./configure --disable-systemd --enable-library! make! make install hciconfig hciconfig hci0 up! hciconfig
  39. 39. iBeacons on Raspberry PI git clone https://github.com/carsonmcdonald/bluez-ibeacon.git! cd bluez-ibeacon/bluez-beacon/! make ./ibeacon 200 e2c56db5dffb48d2b060d0f5a71096e0 1 1 -59
  40. 40. bpm Demo
  41. 41. Di cosa abbiamo parlato? ❖ Bluetooth 4.0
 cos’è, come funziona, come si implementa! ❖ iBeacons
 cos’è, come funzionano, come si implementa! ❖ Raspberry PI
 come diventa un iBeacon
  42. 42. bpm Thanks
  43. 43. @if9 - francesco.nove@gmail.com - runcode.it iBeacons e le novità di BLE Francesco Novelli


×