22// Bluetooth.m
33// BluetoothController
44//
5- // Created by Matthieu Cherubini on 20/11/2015.
6- // Copyright © 2015 Beach Creative. All rights reserved.
5+ // Created by mchrbn on 20/11/2015.
76//
87
98#import " Bluetooth.h"
109
1110@implementation Bluetooth
1211@synthesize cbcManager;
1312
13+ // Might have to change these values
1414#define ARDUINO_SHIELD_NAME @" ZBModlue"
1515#define SHIELD_RW_CHARACTERISTIC @" FFC1"
1616
17-
17+ // Init the Bluetooth Service
1818-(void ) start {
1919 cbcManager = [[CBCentralManager alloc ] initWithDelegate: self queue: nil ];
2020}
2121
22+ // Call this method to send values over BLE
2223-(void ) sendValues : (NSString *)value {
2324 [self .peripheral writeValue: [value dataUsingEncoding: NSUTF8StringEncoding] forCharacteristic: self .characteristic type: CBCharacteristicWriteWithResponse];
2425 NSLog (@" Sent data %@ to %@ " , value, self.characteristic .UUID );
2526}
2627
27- // Delegate showing discovered peripherals
28+ // Step #1 : Delegate showing discovered peripherals
2829- (void )centralManager : (CBCentralManager *)central didDiscoverPeripheral : (CBPeripheral *)peripheral advertisementData : (NSDictionary *)advertisementData RSSI : (NSNumber *)RSSI {
2930 NSLog (@" %@ " ,peripheral.name );
3031 // Connect the central manager to the peripheral (Arduino Shield)
@@ -38,7 +39,7 @@ - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeri
3839}
3940
4041
41- // Delegate when a central manager successfully connected to a peripheral
42+ // Step #2 : Delegate when a central manager successfully connected to a peripheral
4243- (void )centralManager : (CBCentralManager *)central didConnectPeripheral : (CBPeripheral *)peripheral {
4344 NSString *log = [NSString stringWithFormat: @" Connecting to %@ " , peripheral.name];
4445 NSLog (@" %@ " ,log);
@@ -49,13 +50,15 @@ - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPerip
4950}
5051
5152
53+ // Step #3 : Delegate when a central manager start to look for services on a connected peripheral
5254- (void )peripheral : (CBPeripheral *)peripheral didDiscoverServices : (NSError *)error {
5355 for (CBService *service in peripheral.services ) {
5456 NSLog (@" Discovered service: %@ " , service.UUID );
5557 [peripheral discoverCharacteristics: nil forService: service];
5658 }}
5759
58-
60+ // Step #4 : Delegate when a central manager start to look for characteristic on a service
61+ // In the case of the ZBModule BLE Shield, the characteristic where values have to be sent is called FFC1
5962- (void )peripheral : (CBPeripheral *)peripheral didDiscoverCharacteristicsForService : (CBService *)service error : (NSError *)error {
6063 for (CBCharacteristic *characteristic in service.characteristics ) {
6164 if ([characteristic.UUID.UUIDString isEqualToString: SHIELD_RW_CHARACTERISTIC]){
0 commit comments