修改设备绑定过程

This commit is contained in:
xuemh 2018-08-08 21:12:29 +08:00
parent f8009af9c0
commit 0a2f673918
2 changed files with 13 additions and 101 deletions

View File

@ -134,8 +134,9 @@
#pragma mark - IFishHotpotUDPHelperDelegate
- (void)udpHelperCommandExecutedSuccess:(IFishUDPHelperBackMsgModel *)backModel {
self.ssid = backModel.senderMacAddress;
[self.view makeToast:[NSString stringWithFormat:@"连接设置成功,mac 地址:%@",backModel.senderMacAddress]];
[self tapConfirmForResults];
[self bindDeviceWithSsid:backModel.senderMacAddress];
}
- (void)udpHelperMessage:(NSString *)msg {
@ -143,104 +144,6 @@
}
#pragma mark - bind
- (void) tapConfirmForResults{
NSLog(@"ViewController do confirm action...");
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSLog(@"ViewController do the execute work...");
// execute the task
NSArray *esptouchResultArray = [self executeForResults];
// show the result to the user in UI Main Thread
dispatch_async(dispatch_get_main_queue(), ^{
// [self._spinner stopAnimating];
// [self enableConfirmBtn];
ESPTouchResult *firstResult = [esptouchResultArray objectAtIndex:0];
// check whether the task is cancelled and no results received
if (!firstResult.isCancelled)
{
NSMutableString *mutableStr = [[NSMutableString alloc]init];
NSUInteger count = 0;
// max results to be displayed, if it is more than maxDisplayCount,
// just show the count of redundant ones
const int maxDisplayCount = 5;
if ([firstResult isSuc])
{
NSString * _deviceBssid=firstResult.bssid;
NSArray*arry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
DeviceModel*model=[[DeviceModel alloc]init];
if (arry.count<5) {
NSMutableArray*macdressArr=[[NSMutableArray alloc]init];
for (model in arry) {
[macdressArr addObject:model.macAddress];
}
BOOL exst=[macdressArr containsObject:_deviceBssid];
if (exst) {
self.bakbutton.userInteractionEnabled=YES;
//[self.navigationController popViewControllerAnimated:YES];
[self.view makeToast:@"该设备已存在"];
}else{
[self bindDeviceWithSsid:_deviceBssid];
}
}else{
[self.view makeToast:@"您的设备数量已超过限制"];
}
for (int i = 0; i < [esptouchResultArray count]; ++i)
{
ESPTouchResult *resultInArray = [esptouchResultArray objectAtIndex:i];
[mutableStr appendString:[resultInArray description]];
[mutableStr appendString:@"\n"];
count++;
if (count >= maxDisplayCount)
{
break;
}
}
if (count < [esptouchResultArray count])
{
[mutableStr appendString:[NSString stringWithFormat:@"\nthere's %lu more result(s) without showing\n",(unsigned long)([esptouchResultArray count] - count)]];
}
}
else
{
self.bakbutton.userInteractionEnabled=YES;
[self.view makeToast:@"未获取到设备mac"];
}
}
});
});
}
- (NSArray *) executeForResults
{
NSString *apSsid = self.ssid;
NSString *apPwd = self.pwdTf.text;
NSString *apBssid = self.bssid;
BOOL isSsidHidden = YES;
int taskCount=1;
self.epTask =
[[ESPTouchTask alloc]initWithApSsid:apSsid andApBssid:apBssid andApPwd:apPwd andIsSsidHiden:isSsidHidden];
NSArray * esptouchResults = [self.epTask executeForResults:taskCount];
NSLog(@"ViewController executeForResult() result is: %@",esptouchResults);
return esptouchResults;
}
-(void)bindDeviceWithSsid:(NSString*)bssid{
NSLog(@"设备bssid_%@",bssid);
NSString *userId = [dataContorl dataControlGetUserIdInfo];
@ -292,7 +195,6 @@
//
self.bakbutton.userInteractionEnabled=YES;
[self.view makeToast:@"绑定失败"];
}

View File

@ -13,13 +13,16 @@
#import "ResetDeviceModel.h"
#import "RestartDeviceModel.h"
#define K_ReSendTimeInterval 5
#define K_ReSendTimeInterval 3
@interface IFishHotpotUDPHelper ()
{
NSString * _ssidName;
NSString *_pwd;
}
@property (nonatomic, assign) BOOL backMessageReceived;
@end
@ -40,11 +43,13 @@
_ssidName = ssidName;
_pwd = pwd;
[self postmsg:@"命令已发出"];
self.backMessageReceived = NO;
self.loopTimer = [NSTimer scheduledTimerWithTimeInterval:K_ReSendTimeInterval target:self selector:@selector(sendConnectHotspotSoketdata) userInfo:nil repeats:YES];
}
- (void)broadCastRestCommand {
[self postmsg:@"命令已发出"];
self.backMessageReceived = NO;
self.loopTimer = [NSTimer scheduledTimerWithTimeInterval:K_ReSendTimeInterval target:self selector:@selector(sendRestSocketData) userInfo:nil repeats:YES];
}
@ -75,6 +80,7 @@
- (void)broadCastRestartCommand {
[self postmsg:@"命令已发出"];
self.backMessageReceived = NO;
self.loopTimer = [NSTimer scheduledTimerWithTimeInterval:K_ReSendTimeInterval target:self selector:@selector(sendRestartSocketData) userInfo:nil repeats:YES];
}
@ -134,6 +140,10 @@
-(BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port
{
if (self.backMessageReceived) {
return YES;
}
self.backMessageReceived = YES;
NSString* result = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
IFishUDPHelperBackMsgModel *model = [[IFishUDPHelperBackMsgModel alloc] initWithData:data];
if ([model.result isEqualToString:@"01"]) {