Config

Last Updated on : 2024-11-20 08:51:40download

You can edit the tuya_ble_config.h file to configure items such as pairing mode, adoption of OS, communication capability, and license management to suit different application scenarios.

Before editing, you need to create a new custom_tuya_ble_config.h file to define parameters and reference this file in tuya_ble_config.h.

CUSTOMIZED_TUYA_BLE_CONFIG_FILE

Macro definition CUSTOMIZED_TUYA_BLE_CONFIG_FILE
Dependency None
Description The custom name of the configuration file.
Note The custom name will replace the existing one used in tuya_ble_config.h. The application must create a configuration file with a custom name and assign this name to CUSTOMIZED_TUYA_BLE_CONFIG_FILE. Take Keil as an example,
CUSTOMIZED_TUYA_BLE_CONFIG_FILE = <custom_tuya_ble_config.h>

CUSTOMIZED_TUYA_BLE_APP_PRODUCT_TEST_HEADER_FILE

Macro definition CUSTOMIZED_TUYA_BLE_APP_PRODUCT_TEST_HEADER_FILE
Dependency None
Description The header file of custom code for the production test.
Note For example, #define CUSTOMIZED_TUYA_BLE_APP_PRODUCT_TEST_HEADER_FILE "custom_app_product_test.h". custom_app_product_test.h is the header file of the custom code for the production test. This file implements the custom test items and chip-dependent standard test items.

TUYA_BLE_PORT_PLATFORM_HEADER_FILE

Macro definition CUSTOMIZED_TUYA_BLE_APP_PRODUCT_TEST_HEADER_FILE
Dependency None
Description The header file of code for platform porting.
Note Example:
  1. Port Tuya Bluetooth SDK to the Nordic platform. Create a new source code file tuya_ble_port_nrf.c and tuya_ble_port_nrf.h for implementing interfaces in the port layer.
  2. In your created custom_tuya_ble_config.h, define this macro as #define TUYA_BLE_PORT_PLATFORM_HEADER_FILE "tuya_ble_port_nrf".

CUSTOMIZED_TUYA_BLE_APP_UART_COMMON_HEADER_FILE

Macro definition CUSTOMIZED_TUYA_BLE_APP_UART_COMMON_HEADER_FILE
Dependency None
Description This macro only applies to connection to Tuya’s general modules.
Note You can leave it as is.

TUYA_BLE_USE_OS

Macro definition TUYA_BLE_USE_OS
Dependency None
Description This macro is used to indicate whether a chip runs an OS, such as FreeRTOS.
Running an OS: #define TUYA_BLE_USE_OS 1
Others: #define TUYA_BLE_USE_OS 0

TUYA_BLE_SELF_BUILT_TASK

Macro definition TUYA_BLE_SELF_BUILT_TASK
Dependency #define TUYA_BLE_USE_OS 1
Description If your chip runs an RTOS, specify whether Tuya Bluetooth SDK needs to create TASK to process messages.
Need: #define TUYA_BLE_SELF_BUILT_TASK 1
No need:#define TUYA_BLE_SELF_BUILT_TASK 0
Note If your chip does not run an OS, leave it as is.

TUYA_BLE_TASK_PRIORITY

Macro definition TUYA_BLE_TASK_PRIORITY
Dependency #define TUYA_BLE_USE_OS 1
#define TUYA_BLE_SELF_BUILT_TASK 1
Description If your chip runs an RTOS, specify the priority of TASK created by Tuya Bluetooth SDK. For example, #define TUYA_BLE_TASK_PRIORITY 1.
Note The PRIORITY definition depends on the RTOS used by your chip. If your chip does not run an OS, leave it as is.

TUYA_BLE_TASK_STACK_SIZE

Macro definition TUYA_BLE_TASK_STACK_SIZE
Dependency #define TUYA_BLE_USE_OS 1
#define TUYA_BLE_SELF_BUILT_TASK 1
Description If your chip runs an RTOS, specify the STACK size of TASK created by Tuya Bluetooth SDK.
For example, #define TUYA_BLE_TASK_STACK_SIZE 256*10.
Note If your chip does not run an OS, leave it as is.

TUYA_BLE_DEVICE_COMMUNICATION_ABILITY

Macro definition TUYA_BLE_DEVICE_COMMUNICATION_ABILITY
Dependency None
Description Define the device’s capability. Parameter description:
  • TUYA_BLE_DEVICE_COMMUNICATION_ABILITY_BLE
    Bluetooth support.
  • TUYA_BLE_DEVICE_COMMUNICATION_ABILITY_REGISTER_FROM_BLE
    Registration through Bluetooth connection.
  • TUYA_BLE_DEVICE_COMMUNICATION_ABILITY_MESH
    Bluetooth mesh support.
  • TUYA_BLE_DEVICE_COMMUNICATION_ABILITY_WIFI_24G
    2.4 GHz Wi-Fi support.
  • TUYA_BLE_DEVICE_COMMUNICATION_ABILITY_WIFI_5G
    5 GHz Wi-Fi support.
  • TUYA_BLE_DEVICE_COMMUNICATION_ABILITY_ZIGBEE
    Zigbee support.
  • TUYA_BLE_DEVICE_COMMUNICATION_ABILITY_NB
    NB-IoT support.
Note If you use a Bluetooth module, define the macro as follows.
#define TUYA_BLE_DEVICE_COMMUNICATION_ABILITY (TUYA_BLE_DEVICE_COMMUNICATION_ABILITY_BLE | TUYA_BLE_DEVICE_COMMUNICATION_ABILITY_REGISTER_FROM_BLE)

TUYA_BLE_DEVICE_SHARED

Macro definition TUYA_BLE_DEVICE_SHARED
Dependency None
Description Specify whether device sharing is supported.
Note This macro applies to devices that can be shared, such as the body fat scale. If your device does not support sharing, define this macro as #define TUYA_BLE_DEVICE_SHARED 0.

TUYA_BLE_DEVICE_UNBIND_MODE

Macro definition TUYA_BLE_DEVICE_UNBIND_MODE
Dependency None.
Description If you set this macro to 1, the SDK will delete the binding information after a device is unbound.
If you set this macro to 0, the SDK will not delete the binding information.
Note This macro applies to devices that can be shared, such as the body fat scale. If your device does not support sharing, define this macro as #define TUYA_BLE_DEVICE_UNBIND_MODE 1.

TUYA_BLE_WIFI_DEVICE_REGISTER_MODE

Macro definition TUYA_BLE_WIFI_DEVICE_REGISTER_MODE
Dependency The device must support a Wi-Fi connection.
Description Specify whether to query network status before device pairing over Bluetooth connection.
Query required: #define TUYA_BLE_WIFI_DEVICE_REGISTER_MODE 1
Query not required: #define TUYA_BLE_WIFI_DEVICE_REGISTER_MODE 0
Note This macro is not available now.

TUYA_BLE_DEVICE_AUTH_SELF_MANAGEMENT

Macro definition TUYA_BLE_DEVICE_AUTH_SELF_MANAGEMENT
Dependency None
Description Specify whether Tuya Bluetooth SDK manages the authorization information.
Management required: #define TUYA_BLE_DEVICE_AUTH_SELF_MANAGEMENT 1
Management not required: #define TUYA_BLE_DEVICE_AUTH_SELF_MANAGEMENT 0
Note If your device does not support a Wi-Fi connection, you must define this macro as 1.

TUYA_BLE_SECURE_CONNECTION_TYPE

Macro definition TUYA_BLE_SECURE_CONNECTION_TYPE
Dependency None
Description The method to encrypt Tuya Bluetooth SDK communication.
  • TUYA_BLE_SECURE_CONNECTION_WITH_AUTH_KEY
    Use an authentication key for encryption.
  • TUYA_BLE_SECURE_CONNECTION_WITH_ECC
    Use Elliptic Curve Diffie-Hellman (ECDH) for encryption.
  • TUYA_BLE_SECURE_CONNECTION_WTIH_PASSTHROUGH
    Not encrypted.
  • TUYA_BLE_SECURE_CONNECTION_WITH_AUTH_KEY_ADVANCED_ENCRYPTION
    Use advanced encryption of authentication key with secure cryptoprocessor.
Note TUYA_BLE_SECURE_CONNECTION_WITH_AUTH_KEY and TUYA_BLE_SECURE_CONNECTION_WITH_AUTH_KEY_ADVANCED_ENCRYPTION are supported currently. Generally, you can define this macro as
#define TUYA_BLE_DEVICE_AUTH_SELF_MANAGEMENT TUYA_BLE_SECURE_CONNECTION_WITH_AUTH_KEY

TUYA_BLE_ADVANCED_ENCRYPTION_AUTH_ON_CONNECT

Macro definition TUYA_BLE_ADVANCED_ENCRYPTION_AUTH_ON_CONNECT
Dependency #define TUYA_BLE_SECURE_CONNECTION_TYPE TUYA_BLE_SECURE_CONNECTION_WITH_AUTH_KEY_ADVANCED_ENCRYPTION
Description If you define this macro as 1, it indicates that certificate authentication is required every time a Bluetooth connection is initiated in advanced encryption.
If you define this macro as 0, it indicates that certificate authentication is not required every time a Bluetooth connection is initiated in advanced encryption.

TUYA_BLE_INCLUDE_CJSON_COMPONENTS

Macro definition TUYA_BLE_INCLUDE_CJSON_COMPONENTS
Dependency #define TUYA_BLE_SECURE_CONNECTION_TYPE TUYA_BLE_SECURE_CONNECTION_WITH_AUTH_KEY_ADVANCED_ENCRYPTION
Description Specify whether to include the cJSON library.
Note cJSON library is used for advanced encryption.

TUYA_BLE_DEVICE_MAC_UPDATE

Macro definition TUYA_BLE_DEVICE_MAC_UPDATE
Dependency None
Description Specify whether to use the MAC address in Tuya’s authorization information as the MAC address of the device.

TUYA_BLE_DEVICE_MAC_UPDATE_RESET

Macro definition TUYA_BLE_DEVICE_MAC_UPDATE_RESET
Dependency #define TUYA_BLE_DEVICE_MAC_UPDATE 1
Description Specify whether to reboot the device to make the updated MAC address take effect.
Reboot: #define TUYA_BLE_DEVICE_MAC_UPDATE_RESET 1
Not reboot: #define TUYA_BLE_DEVICE_MAC_UPDATE_RESET 0

TUYA_BLE_USE_PLATFORM_MEMORY_HEAP

Macro definition TUYA_BLE_USE_PLATFORM_MEMORY_HEAP
Dependency None
Description Specify whether Tuya Bluetooth SDK uses its memory heap.
Use: #define TUYA_BLE_USE_PLATFORM_MEMORY_HEAP 0
Not use: #define TUYA_BLE_USE_PLATFORM_MEMORY_HEAP 1
Note If you define this macro as 1, you need to implement the memory allocation function in the port layer.

TUYA_BLE_DATA_MTU_MAX

Macro definition TUYA_BLE_DATA_MTU_MAX
Dependency None
Description Define the size of the Generic Attribute (GATT) maximum transmission unit (MTU).
#define TUYA_BLE_DATA_MTU_MAX 20
Note Currently, 20-byte GATT MTU is supported.

TUYA_BLE_LOG_ENABLE

Macro definition TUYA_BLE_LOG_ENABLE
Dependency None
Description Specify whether to enable the log printing of Tuya Bluetooth SDK.
Enable: #define TUYA_BLE_LOG_ENABLE 1
Not enable: #define TUYA_BLE_LOG_ENABLE 0
Note Enabling log printing will increase code space. We recommend that you enable log printing during debugging and disable it in your release version.

TUYA_BLE_LOG_COLORS_ENABLE

Macro definition TUYA_BLE_LOG_COLORS_ENABLE
Dependency #define TUYA_BLE_LOG_ENABLE 1
Description Specify whether to enable colored text for log printing of Tuya Bluetooth SDK.
Enable: #define TUYA_BLE_LOG_COLORS_ENABLE 1
Not enable: #define TUYA_BLE_LOG_COLORS_ENABLE 0
Note Printing a colored output depends on specific log viewers.

TUYA_BLE_LOG_LEVEL

Macro definition TUYA_BLE_LOG_LEVEL
Dependency #define TUYA_BLE_LOG_ENABLE 1
Description Define logging levels for Tuya Bluetooth SDK. The valid logging levels include:
#defineTUYA_BLE_LOG_LEVEL_ERROR 1U
#defineTUYA_BLE_LOG_LEVEL_WARNING 2U
#defineTUYA_BLE_LOG_LEVEL_INFO 3U
#defineTUYA_BLE_LOG_LEVEL_DEBUG 4U
To only capture the error level logs, define this macro as
#define TUYA_BLE_LOG_LEVEL TUYA_BLE_LOG_LEVEL_ERROR.

TUYA_APP_LOG_ENABLE

Macro definition TUYA_APP_LOG_ENABLE
Dependency None
Description Specify whether to enable application log.
Enable: #define TUYA_APP_LOG_ENABLE 1
Not enable: #define TUYA_APP_LOG_ENABLE 0
Note Enabling the application log will increase code space. We recommend that you enable log printing during debugging and disable it in your release version.

TUYA_APP_LOG_COLORS_ENABLE

Macro definition TUYA_APP_LOG_COLORS_ENABLE
Dependency #define TUYA_APP_LOG_ENABLE 1
Description Specify whether to enable colored text for application log.
Enable: #define TUYA_APP_LOG_COLORS_ENABLE 1
Not enable: #define TUYA_APP_LOG_COLORS_ENABLE 0
Note Printing a colored output depends on specific log viewers.

TUYA_APP_LOG_LEVEL

Macro definition TUYA_APP_LOG_LEVEL
Dependency #define TUYA_APP_LOG_ENABLE 1
Description Define levels for application log. The valid logging levels include:
#defineTUYA_APP_LOG_LEVEL_ERROR 1U
#defineTUYA_APP_LOG_LEVEL_WARNING 2U
#defineTUYA_APP_LOG_LEVEL_INFO 3U
#defineTUYA_APP_LOG_LEVEL_DEBUG 4U
To only capture the error level logs, define this macro as
#define TUYA_APP_LOG_LEVEL TUYA_APP_LOG_LEVEL_ERROR.

TUYA_BLE_BEACON_KEY_ENABLE

Macro definition TUYA_BLE_BEACON_KEY_ENABLE
Dependency None
Description Specify whether to enable the beacon key. If the application sends Tuya’s DP data by using a beacon, you need to define this macro as 1.

TUYA_BLE_FEATURE_WEATHER_ENABLE

Macro definition TUYA_BLE_FEATURE_WEATHER_ENABLE
Dependency None
Description Specify whether to enable the weather service.
Note To use the weather service, additional configuration is required. You need to contact your project manager to take care of the additional configuration. Otherwise, the weather service will not work.

TUYA_BLE_LINK_LAYER_ENCRYPTION_SUPPORT_ENABLE

Macro definition TUYA_BLE_LINK_LAYER_ENCRYPTION_SUPPORT_ENABLE
Dependency None
Description Specify whether to enable the pairing encryption mechanism in the Bluetooth link layer. To enable this feature, you need to implement tuya_ble_device_info_characteristic_value_update() in the port layer and specify the read characteristic UUID.
Note If you do not use it, leave it as is.

TUYA_BLE_AUTO_REQUEST_TIME_CONFIGURE

Macro definition TUYA_BLE_AUTO_REQUEST_TIME_CONFIGURE
Dependency None
Description Specify whether to initiate a request for time data each time after Tuya Bluetooth SDK establishes a connection with the mobile app.
0: not request.
1: request cloud time once.
2: request the system time of the mobile phone once.
Note If you do not use it, leave it as is.

TUYA_NV_ERASE_MIN_SIZE

Macro definition TUYA_NV_ERASE_MIN_SIZE
Dependency None
Description Specify the smallest erasable unit of the non-volatile (NV) memory assigned to the Tuya Bluetooth SDK.
For example, #define TUYA_NV_ERASE_MIN_SIZE 4096
Note Define this macro based on the specific implementation of the NV interface in the port layer.

TUYA_NV_WRITE_GRAN

Macro definition TUYA_NV_WRITE_GRAN
Dependency None
Description Specify the granularity of data written to the NV flash memory.
For example, #define TUYA_NV_WRITE_GRAN 4 indicates that the data is written in a 4-byte unit.
Note Define this macro based on the specific implementation of the NV interface in the port layer.

TUYA_NV_START_ADDR

Macro definition TUYA_NV_START_ADDR
Dependency None
Description Specify the start address of the non-volatile (NV) memory assigned to the Tuya Bluetooth SDK.
For example, #define TUYA_NV_START_ADDR 0x1000

TUYA_NV_AREA_SIZE

Macro definition TUYA_NV_AREA_SIZE
Dependency None
Description Specify the size of the non-volatile (NV) memory assigned to the Tuya Bluetooth SDK.
For example, the size of #define TUYA_NV_AREA_SIZE (4*TUYA_NV_ERASE_MIN_SIZE)
must be an integer multiple of TUYA_NV_ERASE_MIN_SIZE.

TUYA_BLE_APP_BUILD_FIRMNAME_STRING

Macro definition TUYA_BLE_APP_BUILD_FIRMNAME_STRING
Dependency None
Description Specify the name of the application firmware.
For example, #define TUYA_BLE_APP_BUILD_FIRMNAME_STRING "tuya_ble_sdk_app_demo_xxx"
Note The name is used to verify the firmware name during Tuya’s production test.

TUYA_BLE_APP_VERSION_STRING

Macro definition TUYA_BLE_APP_VERSION_STRING
Dependency None
Description Specify the version number of the application firmware that is built on top of Tuya Bluetooth SDK. Only a 2-digit number is supported, in string format.
For example, #define TUYA_BLE_APP_VERSION_STRING "1.0"
Note If you specify the version number as #define TY_APP_VER_NUM 0x0101
#define TY_APP_VER_STR "1.1", use a definition such as
#define TUYA_BLE_APP_VERSION_STRING TY_APP_VER_STR in custom_tuya_ble_config.h.

TUYA_BLE_APP_FIRMWARE_KEY

Macro definition TUYA_BLE_APP_FIRMWARE_KEY
Dependency None
Description Specify the key of the application firmware that is built on top of Tuya Bluetooth SDK, in string format.
Note Define this macro in the same way as TUYA_BLE_APP_VERSION_STRING.

TUYA_BLE_FEATURE_IOT_CHANNEL_ENABLE

Macro definition TUYA_BLE_FEATURE_IOT_CHANNEL_ENABLE
Dependency None
Description Specify whether to enable IoT channel capability.
Enable: #define TUYA_BLE_FEATURE_IOT_CHANNEL_ENABLE (1)
Not enable: #define TUYA_BLE_FEATURE_IOT_CHANNEL_ENABLE (0)
Note The IoT channel is used for the implementation of IoT-enabled features. It only supports the scene capability currently.

TUYA_BLE_FEATURE_SCENE_ENABLE

Macro definition TUYA_BLE_FEATURE_SCENE_ENABLE
Dependency #define TUYA_BLE_FEATURE_IOT_CHANNEL_ENABLE (1)
Description Specify whether to enable the scene capability.
Enable: #define TUYA_BLE_FEATURE_SCENE_ENABLE (1)
Not enable: #define TUYA_BLE_FEATURE_SCENE_ENABLE (0)
Note The scene capability applies to products with screen displays, such as smartwatches and wrist-worn trackers. It enables products to get smart scenes from the mobile app and control scenes accordingly.
With a Bluetooth connection, when users trigger a scene on a device, a command will be sent to the mobile app for scene execution.