iOS
首先需要找到 ThingSDKConfig SDK配置类,在ThingSmartUtil库中
然后将 supportPlugplay 和 autoPlugPlay 的开关打开
Code: Select all
#import <ThingSmartUtil/ThingSmartUtil.h>
[ThingSDKConfig sharedInstance].supportPlugplay = YES;
[ThingSDKConfig sharedInstance].autoPlugPlay = YES;
然后双模配网API入口更新为
Code: Select all
@interface ThingSmartBLEWifiActivator : NSObject
...
/// Activates the dual-mode device.
///
/// @param UUID The UUID of the device.
/// @param homeId The ID of the current home.
/// @param productId The product ID of the device.
/// @param ssid The name of the router.
/// @param password The password of the device.
/// @param bleActive whether Plugplay activation required
/// @param timeout The timeout value.
/// @param success Called when the task is finished.
/// @param failure Called when the task is interrupted by an error.
- (void)startConfigBLEWifiDeviceWithUUID:(NSString *)UUID
homeId:(long long)homeId
productId:(NSString *)productId
ssid:(NSString *)ssid
password:(NSString *)password
bleActive:(BOOL)bleActive
timeout:(NSTimeInterval)timeout
success:(ThingSuccessHandler)success
failure:(ThingFailureHandler)failure;
...
@end
相比老的API接口,新增了 bleActive 参数,表示可以当前配网支持Plugplay兜底操作。
bleActive 为 true 时,表示可以通过Plugplay进行激活。
当Plugplay兜底激活成功后,此时App与设备的连接是通过蓝牙完成的,当蓝牙连接断开之后就无法与设备进行通信,如果要完成远程设备控制依然需要连接路由器并完成连云激活才行,可通过以下API完成连云激活的操作:
Code: Select all
@interface ThingSmartBLEManager (PlugPlay)
...
/// Activates the Wi-Fi channel of a dual-mode device for which the Bluetooth channel is activated.
///
/// @param devId The device ID.
/// @param ssid The name of the router.
/// @param password The password for the device.
/// @param timeout The timeout value.
/// @param success Called when the task is finished. DeviceModel is returned.
/// @param failure Called when the task is interrupted by an error.
- (void)activeDualDeviceWifiChannel:(NSString *)devId
ssid:(NSString *)ssid
password:(NSString *)password
timeout:(NSTimeInterval)timeout
success:(void(^)(ThingSmartDeviceModel *deviceModel))success
failure:(ThingFailureError)failure;
...
@end
Android
1.首先使用 ThingSmartNetWork 类进行配置设置
Code: Select all
ThingSmartNetWork.setHomeSdkConfig(new IHomeSdkConfig() {
@Override
public String valueString(String key, String defValue) {
return "";
}
@Override
public boolean valueBoolean(String key, boolean defValue) {
if (TextUtils.equals("autoPlugPlay",key)
|| TextUtils.equals("supportPlugplay",key)){
return true;
}
return false;
}
@Override
public int valueInteger(String key, int defValue) {
return 0;
}
});
2.然后双模配网API入口更新为
Code: Select all
// scanDeviceBean 为蓝牙扫描到的设备信息回调
MultiModeActivatorBean multiModeActivatorBean = new MultiModeActivatorBean(scanDeviceBean);
// 设置 Wi-Fi 的 SSID
multiModeActivatorBean.ssid = "SSID_xxx";
// 设置 Wi-Fi 的密码
multiModeActivatorBean.pwd = "pwd_xxx";
// 设置设备 UUID
multiModeActivatorBean.uuid = scanDeviceBean.getUuid();
// 设置设备类型
multiModeActivatorBean.deviceType = scanDeviceBean.getDeviceType();
// 设置设备 MAC 地址
multiModeActivatorBean.mac = scanDeviceBean.getMac();
// 设置设备地址
multiModeActivatorBean.address = scanDeviceBean.getAddress();
// 设置 HomeID
multiModeActivatorBean.homeId = "homeId_xxx";
// 设置获取到的 Token
multiModeActivatorBean.token = "token_xxx";
// 设置配网总超时,单位:ms
multiModeActivatorBean.timeout = 120 * 1000L;
// 设置仅 Wi-Fi 连接的超时,单位:ms
multiModeActivatorBean.phase1Timeout = 60 * 1000L;
// 设置产品flag
multiModeActivatorBean.flag = scanDeviceBean.getFlag();
// 设置支持 ble 激活
multiModeActivatorBean.bleActive = true;
// 配网结果回调
IMultiModeActivatorListener listener = new IMultiModeActivatorListener() {
@Override
public void onSuccess(DeviceBean deviceBean) {
// 配网成功
}
@Override
public void onFailure(int code, String error, Object handle) {
// 配网失败
}
};
// 开始配网
ThingHomeSdk.getActivator().newMultiModeActivator().startActivator(multiModeActivatorBean, listener);
3.PlugPlay 激活之后,如果需要连云
Code: Select all
MultiModeActivatorBean multiModeActivatorBean = new MultiModeActivatorBean(scanDeviceBean);
multiModeActivatorBean.devId = "devId_xxx"; // 设备 devId
multiModeActivatorBean.ssid = "ssid_xxx"; // 需要连接的 Wi-Fi ssid
multiModeActivatorBean.pwd = "pwd_xxx"; // 需要连接的 Wi-Fi 密码
multiModeActivatorBean.timeout = 120 * 1000L; // 超时时长,单位:ms
// Wi-Fi 重新配网结果回调
IMultiModeActivatorListener listener = new IMultiModeActivatorListener() {
@Override
public void onSuccess(DeviceBean deviceBean) {
// 激活 Wi-Fi,连接云端成功
}
@Override
public void onFailure(int code, String msg, Object handle) {
// 激活 Wi-Fi,连接云端失败
}
};
// 开始重新连接 Wi-Fi 并云端激活
ThingHomeSdk.getActivator().newMultiModeActivator().startWifiEnable(multiModeActivatorBean, listener);