FeasyWiFi SDK iOS接入文档
一、接入方式
参考 FeasyBlue_SDK iOS接入文档 【接入方式】章节
二、搜索
参考 FeasyBlue_SDK iOS接入文档 【搜索】章节
三、连接(FEBluetoothSDK)
1、介绍:
连接设备
2、方法
/// 连接设备进入普通通讯模式
/// @param peripheral 设备
/// @param isConnectedBlock 是否连接成功回调,断开连接也从这里回调
- (void)connectToModify:(FEPeripheral *)peripheral connectState:(void(^)(FEPeripheral *peripheral, CONNECTSTATE connectState))connectStateBlock;
3、例子
[[FEBluetoothSDK sharedFEBluetoothSDK] connectToModify:self.peripheral connectState:^(FEPeripheral * _Nonnull peripheral, CONNECTSTATE connectState) {
// 根据 connectState 判断连接结果
}];
4、断开连接
[[FEBluetoothSDK sharedFEBluetoothSDK] disconnect:peripheral complete:^(FEPeripheral * _Nonnull peripheral) {
// 断开完成
}];
四、配网(FEPeripheral)
1、创建FEWiFi对象,参数传设备对象(FEPeripheral)
wifi = [[FEWiFi alloc] initWithPeripheral:peripheral];
2、配网
说明:支持 动态IP配网 和 静态IP配网 两种方式。 其中,动态配网需要的参数有:网络名称SSID(必填)、网络密码(选填,如果网络不需要密码); 其中,静态配网需要的参数有:网络名称SSID(必填)、网络密码(选填,如果网络不需要密码)、静态IP地址(必填)、GW(选填)、子网掩码MASK(选填)、DNS(选填); 值得注意的是,使用哪种配网方式(动态和静态二选一)需要明确通知蓝牙模组。
因此,蓝牙配网步骤如下:
步骤一:查询目前模块选择的配网方式
[wifi checkConfigDynamicOrStaticNetworkCompleteBlock:^(BOOL isSwitchedDynamic, NSError * _Nullable error) {
if (!error) {
if (isSwitchedDynamic) {
// 动态配网
} else {
// 静态配网
}
}
}];
步骤二:切换配网方式
(如符合目标方式则直接到第三步)
[wifi switchConfigDynamicOrStaticNetwork:YES completeBlock:^(BOOL isSwitchedDynamic, NSError * _Nullable error) {
// 如果切换成功则可以开始填写相关配网参数
}];
步骤三:调用相应的配网方法(静态配网、动态配网),传入正确的参数
动态配网:
[wifi btConfigDynamicNetwork:networkName password:password reconnect:YES completeBlock:^(NSString * _Nullable IPAddress, NSError * _Nullable error) {
__strong __typeof(weakSelf) strongSelf = weakSelf;
if (error) {
[strongSelf showAlertControllerWithTitle:LS(@"配网失败")];
} else {
if (IPAddress) {
[strongSelf showAlertControllerWithTitle:LS(@"配网已成功") message:[NSString stringWithFormat:@"IP地址为:%@", IPAddress]];
} else {
[strongSelf showAlertControllerWithTitle:LS(@"配网失败")];
}
}
}];
静态配网:
[wifi btConfigStaticNetwork:networkName password:password staticIp:configer_StaticIP GW:configer_GW MASK:configer_MASL DNS:configer_DNS reconnect:YES completeBlock:^(NSString * _Nullable IPAddress, NSError * _Nullable error) {
__strong __typeof(weakSelf) strongSelf = weakSelf;
if (error) {
[strongSelf showAlertControllerWithTitle:LS(@"配网失败")];
} else {
if (IPAddress) {
[strongSelf showAlertControllerWithTitle:LS(@"配网已成功") message:[NSString stringWithFormat:@"IP地址为:%@", IPAddress]];
} else {
[strongSelf showAlertControllerWithTitle:LS(@"配网失败")];
}
}
}];
五、升级
// @param name 固件名
[wifi otaWithName:name progress:^(NSNumber * _Nonnull percent) {
// 获取升级进度1~100,部分蓝牙模组支持
} complete:^(BOOL isSuccess, NSError *error) {
// 优先处理error,error为nil的情况下,再判断时候升级成功
}];
六、恢复出厂设置
[wifi restore:^(BOOL isOK) {
// isOK值为是否恢复出厂设置成功
}];
七、查询版本
[wifi checkVersionComplete:^(NSString * _Nullable version) {
// version 是版本号,空为查询失败
}];
八、查询IP
[wifi checkIPWithHandler:^(NSString * _Nullable IPAddress, NSError * _Nullable error) {
// IPAddress 是 ip 地址,空为查询失败
}];
附录
FeasyWiFi SDK iOS 接入文档 (PDF)