HomeHubWifiPasswdInputViewController.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // HomeHubWifiPasswdInputViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 5. 11..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "HomeHubWifiPasswdInputViewController.h"
  9. #import "HomeHubConnectWifiViewController.h"
  10. @interface HomeHubWifiPasswdInputViewController () {
  11. BLEServiceHandler *bleService;
  12. BOOL updateSSID;
  13. BOOL updateBSSID;
  14. BOOL updateIPSet;
  15. BOOL updateIPAddr;
  16. }
  17. @end
  18. @implementation HomeHubWifiPasswdInputViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self initUI];
  22. [self prepareViewDidLoad];
  23. }
  24. - (void)initUI {
  25. _lblSSID.text = [NSString stringWithFormat:@"SSID : %@", _selectedWLanModel.ssid];
  26. }
  27. - (void)prepareViewDidLoad {
  28. //ble
  29. bleService = [BLEServiceHandler sharedManager];
  30. bleService.delegate = self;
  31. updateSSID = updateBSSID = updateIPSet = updateIPAddr = NO;
  32. }
  33. - (void)didReceiveMemoryWarning {
  34. [super didReceiveMemoryWarning];
  35. }
  36. #pragma mark - User Event
  37. - (IBAction)btnAgainTouched:(id)sender {
  38. BOOL find = NO;
  39. for (UIViewController *vc in self.navigationController.viewControllers) {
  40. if ([vc isKindOfClass:HomeHubConnectWifiViewController.class]) {
  41. find = YES;
  42. [self.navigationController popToViewController:vc animated:YES];
  43. }
  44. }
  45. if (!find) {
  46. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubConnectWifiViewController" storyboardName:@"HomeHub"];
  47. [self.navigationController pushViewController:vc animated:YES];
  48. }
  49. }
  50. - (IBAction)btnConnectTouched:(id)sender {
  51. NSString *pass = _txtInputPasswd.text.trim;
  52. if (pass.length == 0) {
  53. return;
  54. }
  55. [bleService setWiFiPwd:pass];
  56. [bleService enableDHCP];
  57. [bleService readAndNotifyCharacteristicUUID:kBLEChrStDHCPArg isNotify:NO];
  58. updateSSID = updateBSSID = updateIPSet = updateIPAddr = NO;
  59. }
  60. - (IBAction)btnCancelTouched:(id)sender {
  61. [self.navigationController popToRootViewControllerAnimated:YES];
  62. }
  63. #pragma mark - ble delegate
  64. //enableDHCP
  65. - (void)BLEWiFiDHCPUpdate:(id)data {
  66. [bleService applyWiFiSettingInfo];
  67. [bleService readAndNotifyCharacteristicUUID:kBLEChrRdConInfo isNotify:YES];
  68. }
  69. //kBLEChrRdConInfo
  70. - (void)BLEWiFiConnectionUpdate:(CBCharacteristic *)info {
  71. NSLog(@"Connection Update!");
  72. NSString *value = [bleService hexStringValue:info] ;
  73. NSLog(@"value : %@", value) ;
  74. NSLog(@"value : %@", [value substringFromIndex:value.length-1]) ;
  75. if (value.length > 0 &&
  76. EQUALS([value substringFromIndex:value.length-1], @"1")) {
  77. [bleService readConnectionWiFiInfo];
  78. }
  79. }
  80. //readConnectionWiFiInfo
  81. - (void)BLEWiFiConnectionInfoUpdateWithKey:(NSString *)kBLEChr
  82. result:(NSString *)result {
  83. NSLog(@"Connection Info Update!") ;
  84. if (EQUALS(kBLEChr, kBLEChrRdSSID)) {
  85. updateSSID = YES;
  86. }
  87. else if(EQUALS(kBLEChr, kBLEChrRdBSSID)) {
  88. updateBSSID = YES;
  89. }
  90. else if(EQUALS(kBLEChr, kBLEChrRnIpSet)) {
  91. updateIPSet = YES;
  92. }
  93. else if(EQUALS(kBLEChr, kBLEChrRnIpAddr)) {
  94. updateIPAddr = YES;
  95. }
  96. // 연결 확인 완료
  97. if (updateSSID && updateBSSID && updateIPSet && updateIPAddr) {
  98. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubUpdateCompleteViewController" storyboardName:@"HomeHub"];
  99. [self.navigationController pushViewController:vc animated:YES];
  100. }
  101. }
  102. @end