Last Updated on : 2024-11-20 08:51:43download
This topic describes how to port the Tuya Beacon SDK to your project.
IDE
Install the required IDE as per the chip manufacturer.
Hardware environment
You can choose the development board from the chip manufacturer or use your custom board. ty_iot_beacon_sdk
is developed and verified based on the board from the chip manufacturer.
The components layer contains the core stack components of the Tuya Beacon stack, including ty_xxtea
, ty_base64
, and ty_beacon
. Add all static libraries and header files in the components folder to your project.
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. |
Add all files and header files in the bal
folder to your project and implement bal_beacon_txrx
functions based on the SDK you use. The Tuya standard chip based SDK has implemented the bal_beacon_txrx
.
To store anti-replay sequence numbers and encryption keys and provide the timer function, you need to implement a 256-byte nonvolatile random-access memory (NVRAM) driver and a microseconds system tick driver. For more information about the required function, see Board Layer.
If you use the Tuya standard chip based SDK, you can add the following implemented files to your project.
Files | Description |
---|---|
hal_storage_256.h |
Declares the function used to read from and write to nonvolatile memory. |
hal_storage_256.c |
Implements the function used to read from and write to nonvolatile memory. |
hal_clock.h |
Declares the function used to get the current tick value and the set time interval. |
hal_clock.c |
Implements the function used to get the current tick value and the set time interval. |
hal_sys.h |
The system header file. |
hal_types.h |
Definition of data types. |
board.h |
The header file of the hardware abstraction layer. |
The Beacon SDK has implemented the necessary functions on the application layer. You can directly port app_main.c
, app_dps.c
, and app_dps.h
to your project.
For debugging purposes, you can use the license list to authorize your chips. For more information about the license, see FAQs. Take the AC6329C2
chip as an example. You must comment out the interface for reading the authorization information from the flash memory. Populate authkey[17]
, mac[6]
, and pid[9]
with the key[0] to key[15], MAC address, and product ID (PID) respectively. You can find the key and MAC address from the license list. The PID is the code assigned to your product created on the Tuya Developer Platform.
u8 mac[6] = {0xdc,0x23,0x4d,0x7e,0x35,0xe5};
u8 authkey[17] = "************";
u8 pid[9] = "*******";
u8 version = 0x10;//1.0
u16 kind = 0x0103;
// get_anthkey(authkey);
printf("authkey:\r\n");
put_buf(authkey,16);
// get_mac(mac);
ty_beacon_init(mac,authkey,pid,version,kind);
if(ty_beacon_get_state() == DEVICE_STATE_NOT_PAIRED)
ty_beacon_start_pairing();
Find the app_multi_conn.c
file. Shield syscfg_read(NV_USER_MAC_ADDR, ty_ble_addr, 6)
and update the value of ty_ble_addr[6]
to the MAC address from the license list.
//u8 tmp_ble_addr[6];
#if 1
// u8 ty_ble_addr[6] = {0xe5,0x35,0x7e,0x4d,0x23,0x23};
u8 ty_ble_addr[6] = {0xdc,0x23,0x4d,0x7e,0x35,0xe5};
#endif
#if 0
u8 ty_ble_addr[6] = {0x18,0x42,0x72,0x4d,0x23,0xdc};
#endif
#if 0
u8 ty_ble_addr[6] = {0x1d,0x42,0x72,0x4d,0x23,0xdc};
#endif
/* le_controller_set_mac((void*)"012345"); */
//lib_make_ble_address(tmp_ble_addr, (void *)bt_get_mac_addr());
//syscfg_read(NV_USER_MAC_ADDR, ty_ble_addr, 6);
//hal_flash_read_page(0x3000,6,ty_ble_addr);
le_controller_set_mac((void *)ty_ble_addr);
printf("\n-----edr + ble 's address-----");
printf_buf((void *)bt_get_mac_addr(), 6);
printf_buf((void *)ty_ble_addr, 6);
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback