ibeacons e le novità di ble [mokapp 2013]

46

Upload: francesco-novelli

Post on 28-Jan-2015

107 views

Category:

Technology


2 download

DESCRIPTION

iBeacons e le novità di BLE

TRANSCRIPT

Page 1: iBeacons e le novità di BLE [Mokapp 2013]
Page 2: iBeacons e le novità di BLE [Mokapp 2013]

@if9 - [email protected] - runcode.it

iBeacons e le novità di BLE

Francesco Novelli

Page 3: iBeacons e le novità di BLE [Mokapp 2013]

Francesco Novelli chi?

❖ Freelance! !

❖ iOS Developer!

❖ Web (Back-end) Developer!

❖ Windows 8 Developer!

Page 4: iBeacons e le novità di BLE [Mokapp 2013]

Chi??

fag.it

Page 5: iBeacons e le novità di BLE [Mokapp 2013]

Di cosa parliamo?

❖ iOS 7!!

❖ Bluetooth 4.0!

❖ iBeacons!

❖ Raspberry PI

Page 6: iBeacons e le novità di BLE [Mokapp 2013]
Page 7: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons

Page 8: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons e le novità di BLE

Bluetooth 4.0

• Cos’è?!• Il solito bluetooth? NO!• Chi lo usa?!• Come lo uso nella mia app?

Page 9: iBeacons e le novità di BLE [Mokapp 2013]

Bluetooth 4.0: cos’è?

❖ BLE: Blueooth Low Energy!

❖ Standard dal 2010!

❖ Chip diverso dal 3.0-!

❖ Dual Chip Device

Page 10: iBeacons e le novità di BLE [Mokapp 2013]

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

Page 11: iBeacons e le novità di BLE [Mokapp 2013]

Bluetooth 4.0: Le novità

❖ Range: 50m vs 100m!

❖ Throughput: 0.27 Mbit/s vs 2.1 Mbit/s!

❖ Latency: 6ms vs 100ms

Page 12: iBeacons e le novità di BLE [Mokapp 2013]

Bluetooth 4.0: Le novità

❖ Niente auricolari Bluetooth 4.0!

❖ Niente scambio foto à la Symbian!

❖ Niente cuffie BLE!

❖ quindi? che ci faccio?

Page 13: iBeacons e le novità di BLE [Mokapp 2013]

Bluetooth 4.0: Chi lo usa?❖ Orologi!

❖ Sport e fitness devices!

❖ Healtcare devices!

❖ Security devices!

❖ Proxymity!

❖ Automation!

❖ …

Page 14: iBeacons e le novità di BLE [Mokapp 2013]

Bluetooth 4.0: Profili disponibili

❖ GATT Profiles:!

❖ http://is.gd/blegatt!

❖ Rivolto a developer!

❖ Rivolto a hardware makers

Page 15: iBeacons e le novità di BLE [Mokapp 2013]

Bluetooth 4.0 in iOS

❖ CoreBluetooth.framework!

❖ Disponibile su iOS e Mac OS!

❖ CBPeripheral (ogni BLE device)!

❖ CBCentralManager (iOS BLE)

Page 16: iBeacons e le novità di BLE [Mokapp 2013]

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

Page 17: iBeacons e le novità di BLE [Mokapp 2013]

Bluetooth 4.0 in iOS: DiscoveringmyCentralManager =! [[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);!!}

Page 18: iBeacons e le novità di BLE [Mokapp 2013]

Bluetooth 4.0 in iOS: Connecting[myCentralManager connectPeripheral:peripheral options:nil];

- (void)centralManager:(CBCentralManager *)central! didConnectPeripheral:(CBPeripheral *)peripheral {! ! NSLog(@"Peripheral connected");! ...

peripheral.delegate = self;!

Page 19: iBeacons e le novità di BLE [Mokapp 2013]

Bluetooth 4.0 in iOS: Services- (void)peripheral:(CBPeripheral *)peripheral!didDiscoverServices:(NSError *)error {! ! for (CBService *service in peripheral.services) {! NSLog(@"Discovered service %@", service);! ...! }! ...

Page 20: iBeacons e le novità di BLE [Mokapp 2013]

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);! ...! }! ...!

Page 21: iBeacons e le novità di BLE [Mokapp 2013]

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];

Page 22: iBeacons e le novità di BLE [Mokapp 2013]

Demo

bpm

cardioble

Page 23: iBeacons e le novità di BLE [Mokapp 2013]

Demo

bpm

Page 24: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons e le novità di BLE

iBeacons

• Cos’è?!• Come funziona?!• Come si costruisce?!• Quanto costa?!• Come lo uso nella mia app?

Page 25: iBeacons e le novità di BLE [Mokapp 2013]

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.

Page 26: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons: trasmette..?

❖ 3 info: UUDID, major, minor!

❖ SEMPRE!

❖ a qualsiasi BLE device attivo!

❖ nothing else matter

Page 27: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons IDs

❖ UUDID: E2C56DB5-DFFB-48D2-B060-D0F5A71096E0!

❖ Major: int!

❖ Minor: int!

❖ Major e Minor ID qualunque, ID generici

Page 28: iBeacons e le novità di BLE [Mokapp 2013]

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.

Page 29: iBeacons e le novità di BLE [Mokapp 2013]

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.

Page 30: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons: come funziona?

❖ iOS device!

❖ MiniPC con Bluetooth 4.0!

❖ Standalone device!

❖ Estimone, etc..

Page 31: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons: iOS Beacon AdvProgetto 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];

Page 32: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons: Quanto costa?

low-cost transmitters

Nome Costo Tempi Affdabilità

Estimote 99$ x 3 (33$ each) Late December *****

BLE Mini 30£ each Weeks ****

Alibaba seller 10$-20$ Days/Week ***

Page 33: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons: come lo uso?

❖Monitoring!❖Notify

Page 34: iBeacons e le novità di BLE [Mokapp 2013]

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); !}

Page 35: iBeacons e le novità di BLE [Mokapp 2013]

Demo

bpm

Page 36: iBeacons e le novità di BLE [Mokapp 2013]

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"];

Page 37: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons: Notify

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;

CLBeacon *beacon = (CLBeacon *)region;PS:

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region;

typedef NS_ENUM(NSInteger, CLRegionState) { CLRegionStateUnknown, CLRegionStateInside, CLRegionStateOutside } NS_ENUM_AVAILABLE_IOS(7_0);

Page 38: iBeacons e le novità di BLE [Mokapp 2013]

Demo

bpm

Page 39: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons on Raspberry PI

❖ Compra un Raspberry PI. ORA!!

❖ Compra un adattatore BLE. 10€ on Amazon!

❖ Collegali ed esegui i comandi delle prossime slide..

Page 40: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons on Raspberry PIapt-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

Page 41: iBeacons e le novità di BLE [Mokapp 2013]

iBeacons on Raspberry PIgit clone https://github.com/carsonmcdonald/bluez-ibeacon.git!cd bluez-ibeacon/bluez-beacon/!make

./ibeacon 200 e2c56db5dffb48d2b060d0f5a71096e0 1 1 -59

Page 42: iBeacons e le novità di BLE [Mokapp 2013]

Demo

bpm

Page 43: iBeacons e le novità di BLE [Mokapp 2013]

Di cosa abbiamo parlato?

❖ Bluetooth 4.0 cos’è, come funziona, come si implementa!

❖ iBeaconscos’è, come funzionano, come si implementa!

❖ Raspberry PIcome diventa un iBeacon

Page 44: iBeacons e le novità di BLE [Mokapp 2013]

Thanks

bpm

Page 45: iBeacons e le novità di BLE [Mokapp 2013]

@if9 - [email protected] - runcode.it

iBeacons e le novità di BLE

Francesco Novelli

Page 46: iBeacons e le novità di BLE [Mokapp 2013]