// // HomeHubWifiPasswdInputViewController.m // OneCable // // Created by nComz on 2017. 5. 11.. // Copyright © 2017년 ntels. All rights reserved. // #import "HomeHubWifiPasswdInputViewController.h" #import "HomeHubConnectWifiViewController.h" @interface HomeHubWifiPasswdInputViewController () { BLEServiceHandler *bleService; BOOL updateSSID; BOOL updateBSSID; BOOL updateIPSet; BOOL updateIPAddr; } @end @implementation HomeHubWifiPasswdInputViewController - (void)viewDidLoad { [super viewDidLoad]; [self initUI]; [self prepareViewDidLoad]; } - (void)initUI { _lblSSID.text = [NSString stringWithFormat:@"SSID : %@", _selectedWLanModel.ssid]; } - (void)prepareViewDidLoad { //ble bleService = [BLEServiceHandler sharedManager]; bleService.delegate = self; updateSSID = updateBSSID = updateIPSet = updateIPAddr = NO; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - User Event - (IBAction)btnAgainTouched:(id)sender { BOOL find = NO; for (UIViewController *vc in self.navigationController.viewControllers) { if ([vc isKindOfClass:HomeHubConnectWifiViewController.class]) { find = YES; [self.navigationController popToViewController:vc animated:YES]; } } if (!find) { UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubConnectWifiViewController" storyboardName:@"HomeHub"]; [self.navigationController pushViewController:vc animated:YES]; } } - (IBAction)btnConnectTouched:(id)sender { NSString *pass = _txtInputPasswd.text.trim; if (pass.length == 0) { return; } [bleService setWiFiPwd:pass]; [bleService enableDHCP]; [bleService readAndNotifyCharacteristicUUID:kBLEChrStDHCPArg isNotify:NO]; updateSSID = updateBSSID = updateIPSet = updateIPAddr = NO; } - (IBAction)btnCancelTouched:(id)sender { [self.navigationController popToRootViewControllerAnimated:YES]; } #pragma mark - ble delegate //enableDHCP - (void)BLEWiFiDHCPUpdate:(id)data { [bleService applyWiFiSettingInfo]; [bleService readAndNotifyCharacteristicUUID:kBLEChrRdConInfo isNotify:YES]; } //kBLEChrRdConInfo - (void)BLEWiFiConnectionUpdate:(CBCharacteristic *)info { NSLog(@"Connection Update!"); NSString *value = [bleService hexStringValue:info] ; NSLog(@"value : %@", value) ; NSLog(@"value : %@", [value substringFromIndex:value.length-1]) ; if (value.length > 0 && EQUALS([value substringFromIndex:value.length-1], @"1")) { [bleService readConnectionWiFiInfo]; } } //readConnectionWiFiInfo - (void)BLEWiFiConnectionInfoUpdateWithKey:(NSString *)kBLEChr result:(NSString *)result { NSLog(@"Connection Info Update!") ; if (EQUALS(kBLEChr, kBLEChrRdSSID)) { updateSSID = YES; } else if(EQUALS(kBLEChr, kBLEChrRdBSSID)) { updateBSSID = YES; } else if(EQUALS(kBLEChr, kBLEChrRnIpSet)) { updateIPSet = YES; } else if(EQUALS(kBLEChr, kBLEChrRnIpAddr)) { updateIPAddr = YES; } // 연결 확인 완료 if (updateSSID && updateBSSID && updateIPSet && updateIPAddr) { UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubUpdateCompleteViewController" storyboardName:@"HomeHub"]; [self.navigationController pushViewController:vc animated:YES]; } } @end