更换热点链接方式

This commit is contained in:
wbzhan 2019-09-30 13:30:50 +08:00
parent 41e5233e1f
commit bfdf208899
10 changed files with 259 additions and 62 deletions

View File

@ -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

View File

@ -14,7 +14,8 @@ NS_ASSUME_NONNULL_BEGIN
wifi密码页面
*/
@interface ConAquarNowWiFiPwdVC : BaseViewController
Copy NSString *ssid;
Copy NSString *bssid;
@end
NS_ASSUME_NONNULL_END

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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]];

View File

@ -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]];
}
}

View File

@ -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];

View File

@ -11,5 +11,5 @@
@interface HKPieChartView : UIView
@property (nonatomic, assign) BOOL inCounting;
- (void)updatePercent:(CGFloat)percent animation:(BOOL)animationed;
- (void)endProgressWithString:(NSString *)text;
@end

View File

@ -7,8 +7,8 @@
//
#import "HKPieChartView.h"
#define cycle_blue RGB(174, 191, 228)
#define cycle_green RGB(66, 116, 130)
#define Cycle_DarkBlue RGB(0, 150, 200)
#define Cycle_LightBlue RGB(160, 200, 255)
@interface HKPieChartView()<CAAnimationDelegate>
@property (nonatomic, strong) CAShapeLayer *trackLayer;
@ -48,10 +48,9 @@
}
- (void)updateUI {
// self.trackColor = RGB(240, 244, 251);
self.trackColor = [UIColor clearColor];
self.progressColor = cycle_green;
self.animationDuration = 100;
self.progressColor = Cycle_DarkBlue;
self.animationDuration = 1;
self.pathWidth = self.frame.size.width - kSizeFrom750(8);
[self shadowImageView];
@ -59,7 +58,9 @@
[self gradientLayer];
[self loadGesture];
}
- (void)endProgressWithString:(NSString *)text{
self.progressLabel.text = text;
}
- (void)dealloc {
[self invalidateTimer];
}
@ -117,12 +118,11 @@
CABasicAnimation *animation= [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.fromValue = @(0.0);
animation.toValue = @(self.percent / 100.);
animation.toValue = @(self.percent / 100.f);
animation.duration = self.animationDuration * self.percent / 100;
animation.removedOnCompletion = YES;
animation.delegate = self;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
self.progressLayer.strokeEnd = self.percent / 100;
[self.progressLayer addAnimation:animation forKey:@"strokeEndAnimation"];
}
@ -131,20 +131,20 @@
#pragma mark - CAAnimationDelegate
- (void)animationDidStart:(CAAnimation *)anim {
self.timer = [NSTimer timerWithTimeInterval:1/60 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
self.progressLabel.text = @"设备连接中...";
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
if (flag) {
[self invalidateTimer];
if (self.inCounting&&self.percent==0) {
self.progressLabel.text = @"未开始";
}else
{
self.progressLabel.text = [NSString stringWithFormat:@"%.0f%%", self.percent];
}
}
// if (flag) {
// [self invalidateTimer];
// if (self.inCounting&&self.percent==0) {
// self.progressLabel.text = @"未开始";
// }else
// {
// self.progressLabel.text = [NSString stringWithFormat:@"%.0f%%", self.percent];
// }
// }
}
- (void)timerAction {
@ -157,7 +157,11 @@
self.progressLabel.text = @"未开始";
}else
{
self.progressLabel.text = [NSString stringWithFormat:@"%0.f%%",floorf(progress * 100)];
NSLog(@"%.2f",progress);
self.progressLabel.text = [NSString stringWithFormat:@"%.0f%%",floorf(progress * 100)];
if (progress>0.5) {
[self updatePercent:100 animation:NO];
}
}
}
@ -189,12 +193,11 @@
CGFloat radius = (self.frame.size.width- kSizeFrom750(8)*2)/2;
CGFloat startA = -M_PI_2; //
CGFloat endA =-M_PI_2+ M_PI * 2; //
//线10
CAShapeLayer * _backLayer = [CAShapeLayer layer];//track shape layer
_backLayer.frame = self.bounds;
_backLayer.fillColor = [[UIColor clearColor] CGColor]; //
_backLayer.strokeColor = [cycle_blue CGColor]; //path,-
_backLayer.strokeColor = [Cycle_LightBlue CGColor]; //path,-
_backLayer.opacity = 1; //
_backLayer.lineCap = kCALineCapRound;//线
_backLayer.lineWidth = kSizeFrom750(8);//线
@ -220,12 +223,10 @@
if (!_gradientLayer) {
_gradientLayer = [CAGradientLayer layer];
_gradientLayer.frame = self.bounds;
_gradientLayer.borderColor = cycle_green.CGColor;
// _gradientLayer.colors = @[(id)[UIColor cyanColor].CGColor,
// (id)[UIColor colorWithRed:0.000 green:0.502 blue:1.000 alpha:1.000].CGColor];
// _gradientLayer.colors = @[(id)HEXCOLOR(@"#4294f8").CGColor,(id)HEXCOLOR(@"#3b82f6").CGColor];
// [_gradientLayer setStartPoint:CGPointMake(0.5, 1.0)];
// [_gradientLayer setEndPoint:CGPointMake(0.5, 0.0)];
// _gradientLayer.colors = @[(id)Cycle_DarkBlue.CGColor,(id)HEXCOLOR(@"#3b82f6").CGColor];
_gradientLayer.colors = @[(id)Cycle_DarkBlue.CGColor,(id)Cycle_DarkBlue.CGColor];
[_gradientLayer setStartPoint:CGPointMake(0.5, 1.0)];
[_gradientLayer setEndPoint:CGPointMake(0.5, 0.0)];
[_gradientLayer setMask:self.progressLayer];
[self.layer addSublayer:_gradientLayer];
@ -237,10 +238,10 @@
- (UILabel *)progressLabel {
if (!_progressLabel) {
_progressLabel = [[UILabel alloc]initWithFrame:self.bounds];
_progressLabel.textColor = cycle_green;
_progressLabel.textColor = Cycle_DarkBlue;
_progressLabel.textAlignment = NSTextAlignmentCenter;
_progressLabel.font = FontSize(18);
_progressLabel.font = FontSize(14);
_progressLabel.text = @"设备连接中...";
[self addSubview:_progressLabel];
}
return _progressLabel;