Local Log

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

This topic describes local logs of different types and how to read them. This can help you understand error messages for quick troubleshooting. Error codes ship with this topic enable you to have a quick search on issues.

Log level setting

Log level

The SDK provides the following log levels:

  • ERROR
  • WARNING
  • INFO
  • DEBUG

The log level determines how much granularity to display in the log. For example, if you set the level to TUYA_BLE_LOG_LEVEL_ERROR, WARNING, INFO, and DEBUG information will not be displayed.

Macro definition

Open the config file to check if macro definitions related to log printing are enabled.

  • TUYA_BLE_LOG_ENABLE: used to define whether to enable the log printing of Tuya Bluetooth SDK.
  • TUYA_BLE_LOG_COLORS_ENABLE: used to define whether to enable colored text for log printing of Tuya Bluetooth SDK.
  • TUYA_BLE_LOG_LEVEL: used to define logging levels for Tuya Bluetooth SDK.
  • TUYA_APP_LOG_ENABLE: used to define whether to enable application log.
  • TUYA_APP_LOG_COLORS_ENABLE: used to define whether to enable colored text for application log.
  • TUYA_APP_LOG_LEVEL: used to define levels for application log.

Port log printing functions

Open the port file to check if log printing functions are ported.

  • TUYA_BLE_PRINTF (const char *format,…): Print strings.
  • TUYA_BLE_HEXDUMP(uint8_t *p_data , uint16_t len): Print data in hexadecimal format.

Log description

The performance of some functions in the SDK is monitored so you can get complete insights into the health of your SDK during debugging. We use Nordic's nRF52832 chip and J-Link RTT Viewer to illustrate the typical log types.

Initial logs

When the chip that is flashed with firmware is powered on, if tuya_ble_sdk_init works properly, logs will be printed. The log can help you determine whether Tuya Bluetooth SDK is started properly and whether the correct license is written to the chip. If the relevant log is not printed, check the porting steps.

tuya_ble_status_t tuya_ble_sdk_init(tuya_ble_device_param_t * param_data)
{
    ....
    TUYA_BLE_LOG_HEXDUMP_INFO("auth settings mac", tuya_ble_current_para.auth_settings.mac, MAC_LEN);  // Print the MAC address.
    TUYA_BLE_LOG_HEXDUMP_INFO("product_id", tuya_ble_current_para.pid, tuya_ble_current_para.pid_len);  // Print the PID.
    TUYA_BLE_LOG_HEXDUMP_DEBUG("device_uuid", tuya_ble_current_para.auth_settings.device_id, DEVICE_ID_LEN); // Print the device UUID.
    TUYA_BLE_LOG_HEXDUMP_DEBUG("device_authkey", tuya_ble_current_para.auth_settings.auth_key, AUTH_KEY_LEN); // Print the device authkey.
    TUYA_BLE_LOG_INFO("bond_flag = %d", tuya_ble_current_para.sys_settings.bound_flag);  // Print the binding flag.
    TUYA_BLE_LOG_INFO("tuya ble sdk version : "TUYA_BLE_SDK_VERSION_STR);   // Print the version of Tuya Bluetooth SDK.

    return TUYA_BLE_SUCCE
}

Local Log

bond_flag=0 indicates the Bluetooth device is not paired.

Pairing logs

Open the Tuya Smart app, search for the unpaired device, and bind it. Then, the log printed looks like this. Local Log

bond_flag=1 indicates the Bluetooth device is bound.

Data reporting logs

The device reports DP data to the cloud. The log printed looks like this.

Local Log

0x8006 is the command for data reporting. You can add additional log printing code in tuya_ble_dp_data_send().

Data receiving logs

After the SDK receives DP data from the mobile app, it will send the parsed data as an event to the application. The log printed looks like this.

Local Log

The above code shows the SDK receives dp_id=27, dp_type=enum, and dp_data=0.

Disconnection logs

When the Bluetooth device is disconnected from the mobile app. The log printed looks like this.

Local Log

Unbinding logs

Removing a device from the mobile app means unbinding this device from the app account. The log printed looks like this.

Local Log

Others

For more information about the log information, see the source code of Tuya Bluetooth SDK.