换用新的SDK尝试AP配网

This commit is contained in:
wbzhan 2019-10-09 18:44:18 +08:00
parent 7157c3b0ed
commit 79fc0ce36b
2 changed files with 95 additions and 12 deletions

View File

@ -7,7 +7,6 @@
//
#import <UIKit/UIKit.h>
@interface BaseViewController : UIViewController
@property(nonatomic,strong)UIBarButtonItem*back;

View File

@ -14,7 +14,7 @@
#import "ESPTouchResult.h"
#import "ESPTouchTask.h"
#import "IfishDataUnity.h"
//#import <GWP2P/GWP2P.h>
#import <GWP2P/GWP2P.h>
@interface ConnectingAquarVC ()<IFishHotpotUDPHelperDelegate>
Strong HKPieChartView *progressView;
Strong UILabel *titleL;
@ -32,6 +32,7 @@ Copy NSString *macAddress;
Assign BOOL isBindingDevice;
Strong NSTimer *bindTimer;
Assign NSInteger retryTimes;
Copy NSString *deviceId;
@end
@implementation ConnectingAquarVC
@ -52,22 +53,105 @@ Assign NSInteger retryTimes;
}];
[self.progressView updatePercent:100 animation:YES];
[self.progressView endProgressWithString:@"设备连接中..."];
self.HUD.labelText = @"正在绑定设备";
//AP
// [[GWP2PDeviceLinker shareInstance] p2pAPLinkDeviceWithWiFiSSID:self.wifiName wifiPassword:self.wifiPassword devicePassword:@"123" deviceReceive:^(NSString *deviceId, BOOL isSupport) {
// //
// NSLog(@"设备%@收到WiFi,isSupport:%d",deviceId,isSupport);
// } deviceLinkIn:^(NSDictionary *deviceDict) {
// //
// }];
[[GWP2PDeviceLinker shareInstance] p2pAPLinkDeviceWithWiFiSSID:self.wifiName wifiPassword:self.wifiPassword devicePassword:@"123" deviceReceive:^(NSString *deviceId, BOOL isSupport) {
//wifi
NSLog(@"设备%@收到WiFi,isSupport:%d",deviceId,isSupport);
self.deviceId = deviceId;
} deviceLinkIn:^(NSDictionary *deviceDict) {
//AP//wifi
[self bindDeviceWithDeviceId:self.deviceId];
}];
//wifi
[self sendToDeviceWithSSIDName:self.wifiName andSSIDPWD:self.wifiPassword];
// Do any additional setup after loading the view.
// [self sendToDeviceWithSSIDName:self.wifiName andSSIDPWD:self.wifiPassword];
// // Do any additional setup after loading the view.
//
self.timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
-(void)bindDeviceWithDeviceId:(NSString*)deviceId{
NSLog(@"设备bssid_%@",deviceId);
[self appendTrakContent:@"=================进入绑定函数================="];
NSString *userId = [dataContorl dataControlGetUserIdInfo];
self.HUD.labelText = @"正在绑定设备";
[self appendTrakContent:[NSString stringWithFormat:@"绑定参数 userID:%@", userId]];
[self appendTrakContent:[NSString stringWithFormat:@"绑定参数 macaddress:%@", deviceId]];
[AFHttpTool bindDeviceWithUserId:userId macAddress:deviceId success:^(id response) {
[self endProgress];
self.isBindingDevice = NO;
self.macAddress = nil;
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSLog(@"data:%@",resultDic[@"data"]);
[self appendTrakContent:[NSString stringWithFormat:@"绑定请求成功。返回数据为:%@", resultDic]];
if ([resultDic[@"result"] isEqualToString:@"100"]) {
//
NSDictionary*dataDic=resultDic[@"data"];
DeviceModel*devicemodel=[[DeviceModel alloc] initWithDict:dataDic];
[self appendTrakContent:[NSString stringWithFormat:@"绑定返回状态码正确。设备信息为:%@", dataDic]];
if (!devicemodel.type){
self.HUD.labelText = @"用户绑定设备成功,但设备初次入网失败请重新登陆";
}else{
NSMutableArray * _deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
[_deviceArry insertObject:devicemodel atIndex:0];
[[DataCenter defaultDtacenter]setValue:_deviceArry forKey:@"deviceInfo"];
if ([devicemodel.type isEqual:[NSNull null]]){
//
self.HUD.labelText = @"设备不在服务器";
}else{
self.HUD.labelText = @"设备绑定成功";
[[IfishDataUnity shareDataInstance] initAppCenterVcWith:devicemodel addWithdissMisVc:nil];
//
[[IfishUserObsever sharedInstance] xinZengJingYanZhi:IFISHADDEXP_BIDDEVICE addType:IFISHADDEXPTYPE1];
}
}
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
[self appendTrakContent:@"绑定返回状态码错误。设备信息为:%@"];
self.HUD.labelText = @"绑定失败";
self.bakbutton.userInteractionEnabled=YES;
}else if ([resultDic[@"result"] isEqualToString:@"301"]){
[self appendTrakContent:@"绑定返回状态码错误。设备信息为:%@"];
self.HUD.labelText = @"请求验证失败,请重新登录";
self.bakbutton.userInteractionEnabled=YES;
}else if ([resultDic[@"result"] isEqualToString:@"302"]){
//
[self appendTrakContent:@"绑定返回状态码错误。设备信息为:%@"];
self.bakbutton.userInteractionEnabled=YES;
self.HUD.labelText = @"绑定失败";
[self.HUD hide:YES afterDelay:2];
}
} failure:^(NSError *err) {
if (self.retryTimes < 3) {
[self bindDeviceWithSsid:self.macAddress];
self.retryTimes += 1;
} else {
[self endProgress];
self.isBindingDevice = NO;
self.HUD.labelText = @"请求异常";
[self.HUD hide:YES afterDelay:2];
[self appendTrakContent:[NSString stringWithFormat:@"绑定网络请求错误:%@", err.localizedDescription]];
self.bakbutton.userInteractionEnabled=YES;
}
}];
}
- (void)dealloc
{
if (!self.timer) {
@ -182,7 +266,7 @@ Assign NSInteger retryTimes;
[self appendTrakContent:[NSString stringWithFormat:@"绑定参数 userID:%@", userId]];
[self appendTrakContent:[NSString stringWithFormat:@"绑定参数 macaddress:%@", bssid]];
[AFHttpTool bindDeviceWithUserId:userId macAddress:bssid success:^(id response) {
[self.progressView endEditing:YES];
[self endProgress];
self.isBindingDevice = NO;
self.macAddress = nil;