Bluetooth and Wi-Fi Combo Pairing

Last Updated on : 2024-05-28 06:27:10download

Initialize IActivator

Parameters

Parameter Type Required Description
mode ActivatorMode Yes The pairing mode.

Example

self.pair = ActivatorService.shared.activator(.BLEWIFI)

Initialize device scanning IDiscoveryService

Parameters

Parameter Type Required Description
mode DiscoveryMode Yes The scanning mode.

Example

self.discovery = DiscoveryService.shared.discovery(.BLEWIFI)

Register IDiscoveryListener to listen for scanning result

Parameters

Parameter Type Required Description
device AnyObject Yes The discovered device object. If the device is Bluetooth Low Energy (LE), the object is ThingBLEAdvModel.

Example

private func start() {
    discovery.listener = self
}

extension BluetoothModeViewController: IDiscoveryListener {
    func didDiscover(device: AnyObject) {
        guard let model = device as? ThingBLEAdvModel, let uuid = model.uuid else {return}
        self.deviceInfos[uuid] = model
        self.tableView.reloadData()
    }
}

Register IActivatorListener to listen for pairing result

Parameters

Parameter Type Required Description
deviceModel IActivatedDevice? Yes If the operation is successful, it indicates the information about the activated device. Otherwise, it is nil.
params ActivatorParams? Yes The parameters of actions.

Callbacks

Function name Parameter Description
onSuccess deviceModel: IActivatedDevice? , params: ActivatorParams? The success callback, returning the information about the activated device.
onError error: Error, params: ActivatorParams? The failure callback, returning an error message.

Example

private func start() {
    pair.listener = self
}

extension TableViewController: IActivatorListener {
    func onSuccess(deviceModel: IActivatedDevice?, params: ActivatorParams?) {
        SVProgressHUD.dismiss()
        self.navigationController?.popToRootViewController(animated: true)
    }

    func onError(error: Error, params: ActivatorParams?) {
        SVProgressHUD.dismiss()
        SVProgressHUD.showInfo(withStatus: error.localizedDescription)
    }
}

Start scanning

This method initiates device scanning.

Parameters

This method has no parameters.

Example

self.discovery.startDiscovery()

Stop scanning

Example

// Stop scanning for devices. discovery is generated during initialization.
// self.discovery = DiscoveryService.shared.discovery(.BLEWIFI)
discovery.stopDiscovery()

Start pairing

This method starts device pairing.

Parameters

Parameter Type Required Description
params ActivatorParams Yes The parameters of the pairing action. See the example.
deviceInfo ThingBLEAdvModel Yes The device information.
assetId String Yes The asset ID.
ssid String Yes The SSID of the Wi-Fi access point.
password String Yes The password of the Wi-Fi access point.

Example

// Create BLEWIFIActivatorParams instance.
let params = BLEWIFIActivatorParams(deviceInfo: devInfo, assetId: assetID)

// Start pairing. pair is generated during initialization.
// self.pair = ActivatorService.shared.activator(.BLEWIFI)
self.pair.startPair(BLEWIFIActivatorParams(deviceInfo: devInfo, assetId: assetID, ssid: self.ssid, password: self.password))

Stop pairing

Example

// Stop pairing. pair is generated during initialization.
// self.pair = ActivatorService.shared.activator(.BLEWIFI)
pair.stopPair()