Wi-Fi EZ Mode

Last Updated on : 2024-05-27 05:40:17download

This topic describes pairing a device using the Wi-Fi EZ mode, also known as Wi-Fi Easy Connect or SmartConfig. In the pairing process, a mobile phone connects to the router and broadcasts the Wi-Fi credentials and pairing token to enable the smart device to get this information for connection and pairing. It is easy-to-use, but has compatibility requirements for mobile phones and routers. The success rate is lower than that of AP mode.

Initialize IActivator

Parameters

Parameter Type Required Description
mode ActivatorMode Yes The pairing mode.

Example

EZActivator ezActivator = (EZActivator) ActivatorService.activator(ActivatorMode.EZ);

Get a pairing token

Parameters

Parameter Type Required Description
assetId String Yes The ID of the specified asset or space.
callback IndustryDataCallBack Yes The callback.

Example

// Get the asset activation token.
ActivatorService.activatorToken("assetId", new IndustryDataCallBack<String>() {
            @Override
            public void onSuccess(String s) {
                Log.d(TAG, "onSuccess: " + s);
            }

            @Override
            public void onFailure(@NonNull String s, @NonNull String s1) {
                Log.d(TAG, "onFailure: " + s);
            }
        });

Initialize pairing parameters

Parameters

Parameter Type Description
ssid String The SSID of the Wi-Fi network.
password String The password of the Wi-Fi network.
token String The token.

Example

WiFiActivatorParams params = new WiFiActivatorParams.Builder()
                .setWifi("your_ssid", "your_password")
                .setToken("your_token")
                .build();

Register IActivatorListener to listen for pairing result

IDevice object

Method Description
getDeviceId(): String The device ID.
getUUID(): String The UUID of the device.
getName(): String The name of the device.
getIcon(): String The device icon.
getProductId(): String The product ID.
getCategory(): String The abbreviation of the product category. For example, kg for a switch and cz for a socket. For more information, see Standard Instruction Set.
getCapability(): Int The networking capability. Valid values:
  • 0: Wi-Fi
  • 1: Wired
  • 2: GPRS
  • 3: NB-IoT
  • 10: Bluetooth
  • 11: Bluetooth mesh
  • 12: Zigbee
  • 13: Infrared
  • 14: Zigbee
getProtocolAttribute(): Long The protocol support.
getTimezoneId(): String The time zone of the device.
isCloudOnline(): Boolean The connection status of the device on the internet.
isLocalOnline(): Boolean The connection status of the device on the LAN.
isOnline(): Boolean Indicates whether the device is online on the LAN or internet.
getLatitude(): String The latitude of the device.
getLongitude(): String The longitude of the device.
getDps(): Map<String, Any> Get the data point (DP) of the device.
publishDps(dps: DpCommand, callback: IndustryCallBack) Control a DP.
getSchemas(): Map<String, DpSchema> Get the DP schema.
addDeviceListener(listener: IDeviceListener) Set a device listener.
removeDeviceListener(listener: IDeviceListener) Remove a device listener.
getWifiSignalStrength(callback: IndustryValueCallBack) Get the Wi-Fi signal strength.
getDevAttribute(): Long Device capability flags:
  • Bit0: Pairing-free
  • Bit1: DP 31 protocol query
  • Bit2: Local linkage
  • Bit3: Wi-Fi network scan
  • Bit4: Google Local Home
  • Bit5: Pegasus pairing
  • Bit6: Device control over Bluetooth
  • Bit7: Security alarm
  • Bit8: Shared device
  • Bit9: Sunrise/sunset-based schedule
  • Bit10: Failover
  • Bit11: OTA capability
  • Bit12: Alternative Wi-Fi network
  • Bit14: Tuya standard protocol
  • Bit15: Custom protocol
  • Bit16: Industry capability
  • Bit17: OCPP protocol
  • Bit18: EV charging industry protocol
  • Bit19: Things data model
newOtaManager(): IDeviceOtaManager Get the device OTA management instance.
newBackupManager(): IDeviceWifiBackupManager The alternative Wi-Fi network. To check if this feature is supported, review the bit12 value returned by getDevAttribute().

Example

ezActivator.setListener(new IActivatorListener() {
            @Override
            public void onSuccess(@Nullable IDevice iDevice) {
                Log.d(TAG, "onSuccess: ");

            }

            @Override
            public void onError(@NonNull String s, @NonNull String s1) {
                Log.d(TAG, "onError: ");

            }
        });

Start pairing

Example

ezActivator.start();

Stop pairing

Example

ezActivator.stop();