更换热点链接方式
This commit is contained in:
@@ -37,9 +37,9 @@ Assign BOOL isGoChangeWiFi;//更换为设备的WiFi
|
||||
|
||||
[self.connectWiFiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.view);
|
||||
make.bottom.mas_equalTo(-kSizeFrom750(60));
|
||||
make.width.mas_equalTo(kSizeFrom750(400));
|
||||
make.height.mas_equalTo(kSizeFrom750(60));
|
||||
make.bottom.mas_equalTo(-30);
|
||||
make.width.mas_equalTo(200);
|
||||
make.height.mas_equalTo(30);
|
||||
}];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillEnterForeground:) name:Noti_WillEnterForeground object:nil];
|
||||
@@ -100,17 +100,17 @@ Assign BOOL isGoChangeWiFi;//更换为设备的WiFi
|
||||
}
|
||||
}
|
||||
-(void)checkWiFi{
|
||||
// NSDictionary *ifs = [self getSSIDInfo];
|
||||
// NSString *wifiName = [ifs objectForKey:@"SSID"];
|
||||
// if ([wifiName rangeOfString:@"ifish-"].location!=NSNotFound) {
|
||||
NSDictionary *ifs = [self getSSIDInfo];
|
||||
NSString *wifiName = [ifs objectForKey:@"SSID"];
|
||||
if ([wifiName rangeOfString:@"ifish-"].location!=NSNotFound) {
|
||||
//wifi正确,则尝试连接设备
|
||||
ConnectingAquarVC *connecting = InitObject(ConnectingAquarVC);
|
||||
connecting.wifiName = self.wifiName;
|
||||
connecting.wifiPassword = self.wifiPwd;
|
||||
[self.navigationController pushViewController:connecting animated:YES];
|
||||
// }else{
|
||||
// [self.view makeToast:@"WiFi名称不匹配,请重试"];
|
||||
// }
|
||||
}else{
|
||||
[self.view makeToast:@"WiFi名称不匹配,请重试"];
|
||||
}
|
||||
|
||||
}
|
||||
- (id)getSSIDInfo
|
||||
|
||||
@@ -14,7 +14,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
输入当前wifi密码页面
|
||||
*/
|
||||
@interface ConAquarNowWiFiPwdVC : BaseViewController
|
||||
|
||||
Copy NSString *ssid;
|
||||
Copy NSString *bssid;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -159,8 +159,8 @@ Strong UIButton *nextBtn;
|
||||
[self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.view);
|
||||
make.top.mas_equalTo(self.wifiPwdTextField.mas_bottom).offset(kSizeFrom750(100));
|
||||
make.width.mas_equalTo(kSizeFrom750(400));
|
||||
make.height.mas_equalTo(kSizeFrom750(55));
|
||||
make.width.mas_equalTo(200);
|
||||
make.height.mas_equalTo(30);
|
||||
}];
|
||||
|
||||
[self addContentLabel];;
|
||||
@@ -207,6 +207,12 @@ Strong UIButton *nextBtn;
|
||||
}
|
||||
#pragma mark --buttonClick
|
||||
-(void)nextBtnClick:(UIButton *)sender{
|
||||
BOOL isRight =[dataContorl isIncludeSpecialCharact:self.wifiPwdTextField.text];
|
||||
|
||||
if (!isRight) {
|
||||
[self.view makeToast:@"路由器密码不能包含特殊字符,只能为数字、字母或下划线"];
|
||||
return;
|
||||
}
|
||||
ConAquarChooseWiFiVC *chooseVC = InitObject(ConAquarChooseWiFiVC);
|
||||
chooseVC.wifiName = self.wifiNameTextField.text;
|
||||
chooseVC.wifiPwd = self.wifiPwdTextField.text;
|
||||
|
||||
@@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@interface ConnectingAquarVC : BaseViewController
|
||||
Copy NSString *wifiName;//设备要连接的WiFi名称
|
||||
Copy NSString *wifiPassword;//智能设备要连接的WiFi密码
|
||||
Copy NSString *ssid;
|
||||
Copy NSString *bssid;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -14,12 +14,14 @@
|
||||
#import "ESPTouchResult.h"
|
||||
#import "ESPTouchTask.h"
|
||||
#import "IfishDataUnity.h"
|
||||
#import <GWP2P/GWP2P.h>
|
||||
@interface ConnectingAquarVC ()
|
||||
//#import <GWP2P/GWP2P.h>
|
||||
@interface ConnectingAquarVC ()<IFishHotpotUDPHelperDelegate>
|
||||
Strong HKPieChartView *progressView;
|
||||
Strong UILabel *titleL;
|
||||
Strong ESPTouchTask* epTask;
|
||||
Strong NSMutableString *trackString;
|
||||
Strong MBProgressHUD *HUD;
|
||||
Strong NSTimer *timer;
|
||||
/**
|
||||
设备返回的mac地址
|
||||
*/
|
||||
@@ -48,21 +50,33 @@ Assign NSInteger retryTimes;
|
||||
make.centerX.mas_equalTo(self.view);
|
||||
make.width.mas_equalTo(kSizeFrom750(700));
|
||||
}];
|
||||
[self.progressView updatePercent:99 animation:YES];
|
||||
[self.progressView updatePercent:100 animation:YES];
|
||||
//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) {
|
||||
// //
|
||||
// NSLog(@"设备%@收到WiFi,isSupport:%d",deviceId,isSupport);
|
||||
// } deviceLinkIn:^(NSDictionary *deviceDict) {
|
||||
// //成功
|
||||
// }];
|
||||
//传入设备要连接的wifi名称和密码
|
||||
// [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)dealloc
|
||||
{
|
||||
if (!self.timer) {
|
||||
return;
|
||||
}
|
||||
[self.timer invalidate];
|
||||
self.timer = nil;
|
||||
}
|
||||
- (HKPieChartView *)progressView
|
||||
{
|
||||
if (!_progressView) {
|
||||
_progressView = [[HKPieChartView alloc]initWithFrame:RECT((screen_width - 100)/2, 120, 100, 100)];
|
||||
_progressView = [[HKPieChartView alloc]initWithFrame:RECT((screen_width - 100)/2, 100, 100, 100)];
|
||||
}
|
||||
return _progressView;
|
||||
}
|
||||
@@ -78,6 +92,172 @@ Assign NSInteger retryTimes;
|
||||
}
|
||||
return _titleL;
|
||||
}
|
||||
-(void)timerAction{
|
||||
[self.progressView updatePercent:100 animation:YES];
|
||||
}
|
||||
#pragma mark - UDP related
|
||||
|
||||
- (NSString *)currentWifiSSID {
|
||||
NSString *ssid = @"Not Found";
|
||||
CFArrayRef myArray = CNCopySupportedInterfaces();
|
||||
if (myArray != nil) {
|
||||
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
|
||||
if (myDict != nil) {
|
||||
NSDictionary *dict = (NSDictionary *)CFBridgingRelease(myDict);
|
||||
ssid = [dict valueForKey:@"SSID"];
|
||||
}
|
||||
}
|
||||
return ssid;
|
||||
}
|
||||
|
||||
- (void)sendToDeviceWithSSIDName:(NSString *)name andSSIDPWD:(NSString *)pwd {
|
||||
[IFishHotpotUDPHelper sharedInstance].delegate = self;
|
||||
[[IFishHotpotUDPHelper sharedInstance] broadCastHotspotConnectCommandWith:name pwd:pwd];
|
||||
}
|
||||
|
||||
#pragma mark - IFishHotpotUDPHelperDelegate
|
||||
|
||||
- (void)udpHelperCommandExecutedSuccess:(IFishUDPHelperBackMsgModel *)backModel {
|
||||
self.ssid = backModel.senderMacAddress;
|
||||
[self.view resignFirstResponder];
|
||||
self.HUD.labelText = @"请稍后";
|
||||
self.trackString = [NSMutableString string];
|
||||
[self appendTrakContent:@"=================收到设备答复==================="];
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"答复状态码:%@", backModel.result]];
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"答复Mac地址:%@", backModel.senderMacAddress]];
|
||||
self.macAddress = backModel.senderMacAddress;
|
||||
|
||||
[IFishHotpotUDPHelper sharedInstance].delegate = nil;
|
||||
[[IFishHotpotUDPHelper sharedInstance] broadCastRestartCommand];
|
||||
self.bindTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(startBinding) userInfo:nil repeats:YES];
|
||||
}
|
||||
|
||||
- (void)startBinding {
|
||||
BOOL networkOk = NO;
|
||||
AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
|
||||
if (status == AFNetworkReachabilityStatusReachableViaWiFi) {
|
||||
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) {
|
||||
networkOk = YES;
|
||||
}
|
||||
} else if (status == AFNetworkReachabilityStatusReachableViaWWAN) {
|
||||
networkOk = YES;
|
||||
}
|
||||
if (!networkOk) {
|
||||
return;
|
||||
}
|
||||
if (self.isBindingDevice) {
|
||||
return;
|
||||
}
|
||||
if (self.macAddress.length == 0) {
|
||||
return;
|
||||
}
|
||||
self.isBindingDevice = YES;
|
||||
if (self.bindTimer) {
|
||||
[self.bindTimer invalidate];
|
||||
self.bindTimer = nil;
|
||||
}
|
||||
self.retryTimes = 0;
|
||||
[self bindDeviceWithSsid:self.macAddress];
|
||||
}
|
||||
|
||||
- (void)udpHelperMessage:(NSString *)msg {
|
||||
self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
||||
self.HUD.mode = MBProgressHUDModeIndeterminate;
|
||||
self.HUD.labelText = msg;
|
||||
}
|
||||
|
||||
#pragma mark - bind
|
||||
-(void)bindDeviceWithSsid:(NSString*)bssid{
|
||||
NSLog(@"设备bssid_%@",bssid);
|
||||
[self appendTrakContent:@"=================进入绑定函数================="];
|
||||
NSString *userId = [dataContorl dataControlGetUserIdInfo];
|
||||
self.HUD.labelText = @"正在绑定设备";
|
||||
[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.isBindingDevice = NO;
|
||||
self.macAddress = nil;
|
||||
[self.progressView endProgressWithString:@"连接结束"];
|
||||
[self.timer invalidate];
|
||||
self.timer = 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.isBindingDevice = NO;
|
||||
self.HUD.labelText = @"请求异常";
|
||||
[self.HUD hide:YES afterDelay:2];
|
||||
[self appendTrakContent:[NSString stringWithFormat:@"绑定网络请求错误:%@", err.localizedDescription]];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (void)appendTrakContent:(NSString *)msg {
|
||||
[self.trackString appendString:msg];
|
||||
[self.trackString appendString:@"\n"];
|
||||
}
|
||||
|
||||
/*
|
||||
#pragma mark - Navigation
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ Assign BOOL isInitHostoryView;
|
||||
temp=[temp stringByReplacingOccurrencesOfString:@"°c" withString:@""];
|
||||
IfishHotBarVo*vo=self.datas[0];
|
||||
self.vo.heaterNum=[NSString stringWithFormat:@"%f",temp.floatValue];
|
||||
vo.title=[NSString stringWithFormat:@"设置温度 %.1f°c",[self.vo.heaterNum floatValue]];
|
||||
vo.subTitle=[NSString stringWithFormat:@"%.1f°c",[self.vo.heaterNum floatValue]];
|
||||
[self.mainTableView reloadData];
|
||||
[self setHeatTeapWith:temp];
|
||||
}
|
||||
@@ -367,6 +367,8 @@ Assign BOOL isInitHostoryView;
|
||||
self.historyView.datas=self.vo.phs;
|
||||
self.historyView.hidden=YES;
|
||||
}
|
||||
|
||||
|
||||
//去除鱼缸容积
|
||||
IfishHotBarVo*vo1=self.datas[4];
|
||||
if (self.vo.heater.heaterCycle.length) {
|
||||
@@ -473,9 +475,13 @@ Assign BOOL isInitHostoryView;
|
||||
self.vo.heaterNum=[NSString stringWithFormat:@"%f",num];
|
||||
|
||||
IfishHotBarVo*vo=self.datas[0];
|
||||
vo.title=[NSString stringWithFormat:@"设置温度 %.1f°c",[self.vo.heaterNum floatValue]];
|
||||
|
||||
vo.subTitle=[NSString stringWithFormat:@"%.1f°c",[self.vo.heaterNum floatValue]];
|
||||
|
||||
//设置预警温度区间
|
||||
IfishHotBarVo*vo1=self.datas[1];
|
||||
if (!IsEmptyStr(self.vo.upTeamp)) {
|
||||
vo1.subTitle = [NSString stringWithFormat:@"%.1f°c到%.1f°c",[self.vo.downTeamp floatValue],[self.vo.upTeamp floatValue]];
|
||||
}
|
||||
self.vo.wornCode=[info substringWithRange:NSMakeRange(44, 2)];
|
||||
// self.vo.wornCode=[NSString stringWithFormat:@"%llu",[dataContorl hexToTen:self.vo.wornCode]];
|
||||
|
||||
|
||||
@@ -40,10 +40,10 @@
|
||||
self.subTitleLable.text=vo.subTitle;
|
||||
self.iconImgV.image=[UIImage imageNamed:vo.iconUrl];
|
||||
self.arrowImgV.hidden=!vo.isShowArrow;
|
||||
if (vo.phv!=499) {//无水
|
||||
[self.subTitleLable setTextColor:[UIColor colorWithRed:109/255.0 green:109/255.0 blue:109/255.0 alpha:1.0]];
|
||||
if ((vo.phv!=499)&&[vo.title isEqualToString:@"水泵流量"]) {//水泵流量无水
|
||||
[self.subTitleLable setTextColor:[UIColor redColor]];
|
||||
}else{//正常
|
||||
[self.subTitleLable setTextColor:[UIColor colorWithRed:109/255.0 green:109/255.0 blue:109/255.0 alpha:1.0]];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#import "IfishUserObsever.h"
|
||||
|
||||
#import "ConnectHotpotViewController.h"
|
||||
|
||||
#import "ConAquarNowWiFiPwdVC.h"
|
||||
@interface EspTouchDelegateImpl : NSObject<ESPTouchDelegate>
|
||||
|
||||
@end
|
||||
@@ -424,7 +424,8 @@ extern BOOL isfromCameraView;
|
||||
}
|
||||
|
||||
- (IBAction)lickHereBtnClicked:(id)sender {
|
||||
ConnectHotpotViewController *vc = [[ConnectHotpotViewController alloc] init];
|
||||
// ConnectHotpotViewController *vc = [[ConnectHotpotViewController alloc] init];
|
||||
ConAquarNowWiFiPwdVC *vc = [[ConAquarNowWiFiPwdVC alloc]init];
|
||||
vc.ssid = self.ssid;
|
||||
vc.bssid = self.bssid;
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
|
||||
Reference in New Issue
Block a user