Wi-Fi FFC Remotes

Last Updated on : 2024-01-18 07:51:21download

Wi-Fi Flexible Fast Control (FFC) is Tuya’s proprietary technology that enables Wi-Fi devices to communicate with each other without being connected to a wireless router. It is suitable for communication between remotes and controlled devices. This topic describes the features supported by the controlled device.

There are two types of Wi-Fi FFC remotes: local and online.

  • Local: The remote does not require cloud activation. Each button has a fixed function.
  • Online: The remote must be activated with the cloud through the controlled device. Users can customize each button’s function using the mobile app.

Features

  • Bind with up to five remotes.

  • Receive commands from the remote.

  • Synchronize the remote binding information with the cloud.

  • Unbind from an online remote using the mobile app.

How it works

Pairing process

RemoteControlled DeviceCloudEnter pairing modeDetermine the communication channel.Send a message to indicate that it is ready for binding.Listen for the binding request from the controlled device.Enter the binding process on receiving the command.Send a binding request.Return an ACK message.Negotiate a key.Report the remote activation request.Report the remote information as an accessory.alt[Online remote][Local remote]ControlEncrypt the control command.Send the encrypted control command.Decrypt the command.Return an ACK message.RemoteControlled DeviceCloud

Device control process

RemoteControlled DeviceSend a control command.Return an ACK message.Forward the control command after a random delay.Monitor the communication channel.Resend the control command.opt[The remote does not receive an ACKmessage within the timeout period.]RemoteControlled Device

Unbinding process

The unbinding process is one-way, without any synchronization between the remote and the controlled device.

RemoteCloudControlled DeviceApply to local remotes only.Online remotes cannot be unbound locally.Clear binding informationto unbind from all controlled devices.opt[Local unbinding]Unbind from the specified remote.Clear the information about the specified remote.opt[Unbinding via app]RemoteCloudControlled Device

Development guide

Runtime environment

Open tuya_iot_config.h and check if the following macro is defined.

#define ENABLE_WIFI_FFC       1

#define TUYA_WIFI_FFC_SLAVER  1   /*As a controlled device*/

Reference the header

  • ffc_app.h

How to use

  • Initialize the FFC feature and register the command reception callback.
  • To bind a remote, call the binding API.
  • If the framework receives correct command data, it will notify the application for processing through a callback.

API description

Initialize FFC

typedef enum {
    FFC_INIT_STATE = 0,
    FFC_CONTROL_STATE,
    FFC_BINDING_BEGIN_STATE,
    FFC_BINDING_SUCCESS_STATE,
    FFC_BINDING_FINSH_STATE,
} ffc_cb_state_t;

typedef int (*ffc_status_cb)(ffc_cb_state_t state);
typedef int (*ffc_recv_cb)(uint8_t *data_cmd, uint16_t data_len);

/**
 * @brief ffc init function,must called first
 *
 * @param[in] role:      Remote or controlled device
 * @param[in] status_cb: user status callback
 * @param[in] recv_cb:   user received callback
 *
 * @return OPRT_OK on success. Others error, please refer to tuya_error_code.h
 *
 */
int tuya_iot_wifi_ffc_init(uint8_t role, ffc_status_cb *status_cb, ffc_recv_cb *recv_cb);

Pair and bind

There is a window duration for pairing and binding, which can be adjusted by specifying the corresponding parameter. The device will not send any commands or responses related to pairing and binding outside the window duration.

/**
 * @brief ffc bind function
 *
 * @param[in] timeout_s time out
 *
 * @return OPRT_OK on success. Others error, please refer to tuya_error_code.h
 *
 */
int tuya_iot_wifi_ffc_bind(uint16_t timeout_s);

Example

service_ffc_slaver in TuyaOS example collection contains the complete example code.

FAQs

Does this feature affect the power consumption of a low-power device?

  • After FFC is initialized, the device will exit low power mode if there is a remote open for pairing.
  • During the pairing and binding process, low power mode is off.
  • If the device fails to bind with the remote after a pairing timeout, it will turn on low power mode.
  • After unbinding from a remote, the device will enter low power mode if there are no remotes open for pairing.

What happens if a device is bound with more than five remotes?

The logic differs depending on the type of remote.

  • If all five remotes are the online type, overwriting does not apply. The device will fail to bind with the sixth remote.

  • If all five remotes are the local type, overwriting applies. Binding the sixth remote will overwrite the first, and binding the seventh remote will overwrite the second, and so on.

    After the second remote is unbound, binding the sixth remote will overwrite the first one instead of taking the second place.

  • If there is a mix of online and local types among the five remotes, adding a new remote will overwrite the oldest local remote. Binding the sixth remote will overwrite the earliest local remote.