Components Layer

Last Updated on : 2022-11-24 09:20:07download

The components layer contains the core stack components of the Tuya Beacon stack, including ty_xxtea, ty_base64, and ty_beacon.

Components Description
ty_xxtea Used to encrypt data, serving the ty_beacon component.
ty_base64 Used to decode the base64-encoded data, serving the ty_beacon component.
ty_beacon Serves the core Beacon communication protocol.

ty_beacon_init

Function ty_beacon_init
Feature description Used to initialize the Tuya Beacon stack.
Parameter u8 *pmac: the 6-byte MAC address.
u8 *pauthkey: the 17-byte authkey. authkey is 32 bytes actually but only authkey[0] to authkey[16] are the valid values.
u8 *ppid: the 8-byte product ID (PID) of a product created on the Tuya IoT Development Platform.
u8 version: the SDK version number.
u16 kind: the category and type of a product. For example, 0x0103 represents colored light (RGB), where 01 represents the product category of lights and 03 represents the product type of colored light (RGB).
Return value None
Note This function is called where program initialization is performed.

ty_beacon_download

Function ty_beacon_download
Feature description Used to receive and process the data from the cloud.
Parameter u8 *rxbuf: the raw Beacon data, including the 2-byte header, the 6-byte MAC address, and the payload data of up to 31 bytes.
u8 len_pdu: the length of raw Beacon data.
u8 rssi: the received signal strength.
Return value None
Note This function is called where the Beacon receives a callback.

ty_beacon_send

Function ty_beacon_send
Feature description Used to send data in packets on a schedule.
Parameter u32 cycle: the packet interval, in microseconds.
u8 send_times: the number of times that packets are sent.
u8 cmd: the command included in the packet.
u8* params: the parameter included in the packet.
u8 params_len: the length of the included parameter.
u8 tp: 0
Return value None
Note This function is called where DP data is reported.

ty_beacon_start_pairing

Function ty_beacon_start_pairing
Feature description Used to enable the device to enter the pairing mode that lasts for three minutes.
Parameter None
Return value None
Note This function is called for triggering device pairing.

ty_beacon_get_state

Function ty_beacon_get_state
Feature description Used to get the pairing status.
Parameter None
Return value DEVICE_STATE_PAIRING
DEVICE_STATE_PAIRED
DEVICE_STATE_NOT_PAIRED
DEVICE_STATE_REP_GET_BEACONKEY
DEVICE_STATE_REP_GET_PAIRING_OK
Note This function is called to request the current pairing status.

ty_beacon_run

Function ty_beacon_run
Feature description The Beacon stack driver.
Parameter None
Return value None
Note This function is called periodically with high frequency.