Cloud-Based Activation of Wi-Fi and Bluetooth Combo Devices

Last Updated on : 2024-09-14 06:40:52download

This topic describes how to activate Wi-Fi and Bluetooth combo devices in the cloud.

Preparation

  • SDK version 2.3.0-indy or later supports this feature.
  • To enable cloud-based activation, a Bluetooth connection to the device must be created. This way, cloud-based activation data can be transmitted to the device over Bluetooth.
  • To check whether a device is activated in the cloud, call IDevice().meta?["wifiEnable"] to get the Wi-Fi connection status. A value of true indicates that the cloud-based activation is successful.
  • Bluetooth permission check: It is performed before each Bluetooth scanning and connection. Otherwise, the app cannot use Bluetooth as expected.
    • Before scanning and connection, check if the app is allowed to access location services.
    • Check if the phone’s Bluetooth is turned on.

      Smart Industry App SDK does not provide the logic for precheck. You can implement it on your own.

Initialize IActivator

Parameters

Parameter Type Required Description
mode ActivatorMode Yes The pairing mode.

Sample code

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

Initialize pairing parameters

Get the parameters from the result of the scanning listener.

Parameters

Parameter Type Required Description
devId String Yes The ID of the device.
ssid String Yes The SSID of the Wi-Fi network.
pwd String Yes The password of the Wi-Fi network.
timeout Long No The timeout for device activation in the cloud, in milliseconds. Default value: 100.
let params = BLEWIFICloudActivatorParams(devId: deviceId, ssid: "", password: "")

Register IActivatorListener to listen for pairing result

Parameters

Parameter Type Required Description
deviceModel IActivatedDevice? Yes The information of the activated device for success and nil for failure.
params ActivatorParams? Yes The parameter information of the operation.

Callback functions

Function Parameter Description
onSuccess deviceModel: IActivatedDevice?, params: ActivatorParams? The callback function used when the operation succeeds. It returns the information of the activated device.
onError error: Error, params: ActivatorParams? The callback function used when the operation fails. It returns an error message.

Sample code

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

extension TableViewController: IActivatorListener {
    func onSuccess(deviceModel: IActivatedDevice?, params: ActivatorParams?) {
        SVProgressHUD.dismiss()
    }

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

Start device pairing

This method starts the device pairing.

Parameters

Parameter Type Required Description
params ActivatorParams Yes The information of the pairing parameters. For more information, see the following sample code.
deviceInfo ThingBLEAdvModel Yes The information of the device.
assetId String Yes The ID of the asset.
pairToken String Yes The token for pairing.
ssid String Yes The SSID of the Wi-Fi network.
password String Yes The password of the Wi-Fi network.
onlyConnectBle Boolean No Specifies whether the device can only be activated through a Bluetooth connection. Default value: false.

Sample code

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

Start activation in the cloud

This method starts the device activation in the cloud.

Sample code

let iDevice = IndustryDevice(deviceId: device?.deviceId ?? "")
iDevice.connectBLE {
    // let params = BLEWIFICloudActivatorParams(devId: deviceId, ssid: "", password: "")
     self.pair.startPair(params)
} failure: {

}