Physical Remote

Last Updated on : 2024-05-17 03:12:05download

This topic describes how to implement control of beacon mesh devices, such as lights, sockets, and switches, using a physical remote.

Overview

Concepts

Concepts Description
Remote A device, usually low power, sends control commands to a device.
Controlled device A device, usually mains powered, receives control commands, for example, lights, fans, and switches.
Bind Bind a remote with a controlled device.
Unbind Unbind a remote from a controlled device.
Time window for binding During this time window, a controlled device can receive codes from a remote to bind with it. A time window is specified with a timeout and trigger event. Example:
  • A light device is open for binding for 30 seconds each time it is powered on.
  • Activate the binding mode for a wall socket using a key combination.
Reset remote Reset the remote to factory settings, removing all binding relationships.
Reset controlled device A remote sends a reset command to a controlled device for a factory reset.
Remote control A remote sends a control command to a device.
Group A remote supports up to six groups and one overall control. Users can group devices for bulk control.

Features

Beacon remotes can control paired or unpaired Bluetooth beacon mesh devices after binding. There is no need to add the remote to the Tuya-based mobile app. Due to its weak security, this feature typically applies to lights, fans, and radio-controlled cars.

  • A beacon mesh device can be bound with three remote controls simultaneously.
  • A remote supports up to six groups and one overall control.
  • When another remote attempts to bind with a beacon mesh device that already has three remotes bound, the device will automatically unbind from the earliest remote.
  • The remote is authenticated using the sampling proxy authentication strategy.

This feature is provided as a library libtal_beacon2.lib. Initialize it after ty_beacon2_node_init. During initialization, specify the time window, which determines how long the device remains open for binding with a remote.

The remote controls the beacon mesh device through DP commands. Therefore, whether the controller is a remote or an app, the control command will be sent to app_dps_download. When the beacon mesh device is bound with or unbound from a remote, the callback ty_beacon2_event_cb will be invoked.

Data structure

No external data structure.

API description

Function void ty_beacon_remoter_init(u8 pair_window_s) -
Purpose Initialize the remote feature. -
Request parameter pair_window_s The time window for binding, in seconds.

Example:

Check the demo tuyaos_demo_beaconmesh_peripheral.

VOID_T tal_framework_init_last(VOID_T){

#if (DEVELOP_DEBUG == 0)
    get_pid(beacon_dev.pid);
    get_anthkey(beacon_dev.authkey);
    tkl_beacon_get_mac(beacon_dev.mac);
#endif

    app_led_init();

    ty_beacon2_node_init(&beacon_dev);
    ty_beacon_remoter_init(30);
    if(beacon_dev.state == STATE_NOT_PAIRED){
        ty_beacon2_node_pair_start(180000000);
        app_led_blink(720);
    }else{
        u8 payload[16];
        memset(payload,0,16);
        payload[0] = 0x01;
        frame_send(0x08, 0x8000, 0x02, payload, beacon_dev.beaconkey, 0);//Report heartbeat upon power on, with no forwarding.
    }
}

Functional testing

Prerequisites

  • A beacon remote compatible with the beacon mesh protocol.
  • A device that can be controlled with a beacon remote.

Procedure

  1. Activate the binding time window for the controlled device. For example, a light device is open for binding for 30 seconds each time it is powered on.
  2. During the time window, press the specified button on the remote to bind with the controlled device. ty_beacon2_event_cb returns the binding result.
  3. After binding, pressing the on/off button on the remote will send a control command to app_dps_download.

Support and help

If you have any problems with TuyaOS development, you can post your questions in the Tuya Developer Forum.