浏览代码

06.13 ble connection notify

eunmi.kim 8 年之前
父节点
当前提交
6ce63f9689

+ 2 - 2
OneCable/Classes/Handler/BLEServiceHandler.h

@@ -75,8 +75,8 @@ static NSString *kBLEChrRnIpAddr = @"WF_IP_ADDR_CHR_UUID";
 
 //WiFi Setting관련 메뉴
 
--(void)readCharacteristicUUID:(NSString *)uuid;
-
+-(void)readAndNotifyCharacteristicUUID:(NSString *)uuid
+                              isNotify:(BOOL)isNotify;
 // WiFi Ap 스캔
 -(void)scanWiFiList;
 // WiFi 스캔결과 조회

+ 13 - 6
OneCable/Classes/Handler/BLEServiceHandler.m

@@ -213,7 +213,7 @@
     
     if ([str isDigit]) {
         int dataToWrite = [str intValue];
-        data = [NSData dataWithBytes:&dataToWrite length:sizeof(dataToWrite)];
+        data = [NSData dataWithBytes:&dataToWrite length:1];
     } else {
         data = [str dataUsingEncoding:NSASCIIStringEncoding];
     }
@@ -262,7 +262,8 @@
     [self sendData:[self getChrInfo:kBLEChrStSSIDArg] str:ssid];
 }
 
--(void)readCharacteristicUUID:(NSString *)uuid
+-(void)readAndNotifyCharacteristicUUID:(NSString *)uuid
+                              isNotify:(BOOL)isNotify
 {
     
     for (CBService *service in _conDevice.peripheralRef.services) {
@@ -271,11 +272,17 @@
             
             if ([characteristic.UUID.UUIDString isEquestToIgnoreCase:[self getGatewayDicUUIDForKey:uuid]]) {
                 
-                [_conDevice.peripheralRef readValueForCharacteristic:characteristic];
+                if (isNotify) {
+                    
+                    [_conDevice.peripheralRef setNotifyValue:YES forCharacteristic:characteristic];
+                }
+                else {
+                    [_conDevice.peripheralRef readValueForCharacteristic:characteristic];
+                }
+                
                 break;
             }
         }
-        
     }
 }
 
@@ -504,7 +511,7 @@
 
 - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
     
-    NSLog(@"Incoming: [%@] %@", [self getChrName:characteristic],[self asciiStringValue:characteristic]);
+    NSLog(@"Incoming: [%@] %@ %@", [self getChrName:characteristic],[self asciiStringValue:characteristic], [self hexStringValue:characteristic]);
     
     if ([[self getStrUUID:characteristic] isEquestToIgnoreCase:
          [self getServiceUUID:kBLEChrRdConInfo]]) {
@@ -524,7 +531,7 @@
     //dhcp 읽음
     else if ([[self getStrUUID:characteristic] isEquestToIgnoreCase:
               [self getServiceUUID:kBLEChrStDHCPArg]]) {
-        
+
         if( _delegate && [_delegate respondsToSelector:@selector(BLEWiFiDHCPRead:)] ) {
             [_delegate BLEWiFiDHCPRead:nil];
         }

+ 7 - 2
OneCable/Classes/ViewControllers/HomeHubScreens/HomeHubWifiPasswdInputViewController.m

@@ -68,7 +68,7 @@
     
     [bleService setWiFiPwd:pass];
     [bleService enableDHCP];
-    [bleService readCharacteristicUUID:kBLEChrStDHCPArg];
+    [bleService readAndNotifyCharacteristicUUID:kBLEChrStDHCPArg isNotify:NO];
 }
 
 - (IBAction)btnCancelTouched:(id)sender {
@@ -78,6 +78,11 @@
 
 
 #pragma mark - ble delegate
-
+- (void)BLEWiFiDHCPRead:(id)data {
+    
+    NSLog(@"BLEWiFiDHCPRead") ;
+    [bleService applyWiFiSettingInfo];
+    [bleService readAndNotifyCharacteristicUUID:kBLEChrRdConInfo isNotify:YES];
+}
 
 @end

+ 2 - 1
OneCable/Classes/ViewControllers/HomeHubScreens/HomeHubWifiSearchSuccessViewController.m

@@ -120,7 +120,8 @@
     if (selectedWLanModel != nil) {
         
         [bleService setWiFiSSID:selectedWLanModel.ssid];
-        [bleService readCharacteristicUUID:kBLEChrStSSIDArg];
+        [bleService readAndNotifyCharacteristicUUID:kBLEChrStSSIDArg
+         isNotify:NO];
     }
 }