FAQs

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

How to port Tuya Bluetooth SDK?

See Port SDK.

How to authorize a device?

  • In debugging, you can use the license list to authorize your module. For more information, see Initialize Tuya Bluetooth SDK.

    static tuya_ble_device_param_t tuya_ble_device_param = {
    	.use_ext_license_key = 1, // Define this function as `1` for debugging purpose and the license information that the application passes in will be used. In the release version, define this function as `0` and the license information will be written by Tuya's production tool.
    	.device_id_len       = 16, // If `use_ext_license_key` is `0`, the license is obtained from Tuya's production test tool. Passing in the license is not needed. Assign `0` to `device_id_len`.  
    	.p_type              = TUYA_BLE_PRODUCT_ID_TYPE_PID,
    	.product_id_len      = 8,
    	.adv_local_name_len  = 4,
    	.firmware_version    = 0x00000201,  // The firmware version is 2.1.
    	.hardware_version    = 0x00000100,  // The hardware version is 1.0.
    	.device_id           = "tuyaf3752699xxxx"  // The parameter in the license.
    	.auth_key            = "4gBM3DK6SRmRn9LTLbyOUAz3bHMGxxxx" //// The parameter in the license.
    	.mac_addr_string     = "DC234D12XXXX"  //// The parameter in the license.
    	.product_id          = "suq5jmo5" // Set it to the PID of the product created on the Tuya IoT Platform.
    	.adv_local_name      = "demo"  // The custom name of Bluetooth advertisement.
    };
    
    void tuya_ble_sdk_demo_init(void)  // The initialization function, which must be called by the application.
    {
    	if(device_param.use_ext_license_key==1)
    	{
    		device_param.device_id_len = 16;  // Set `device_id_len` to 16 if you want to pass in the license information for debugging purpose. Otherwise, set it to `0`.
    	}
    	tuya_ble_sdk_init(&tuya_ble_device_param); // Tuya Bluetooth SDK initialization function. It must be called. Otherwise, the SDK cannot run.
    	TUYA_APP_LOG_HEXDUMP_INFO("auth key", tuya_ble_current_para.auth_settings.auth_key, AUTH_KEY_LEN);   // Print the `auth_key`.
    	TUYA_APP_LOG_HEXDUMP_INFO("device id", tuya_ble_current_para.auth_settings.device_id, DEVICE_ID_LEN);  // Print the `device_id`.
    
    	tuya_ble_callback_queue_register(tuya_ble_sdk_callback);// Registration callback.
    
    }
    
  • In production, you need to write the license to the module by using the Authorization Software. For more information, see Bluetooth LE Series Authorization.

    1. Purchase licenses and install Tuya’s host for production test.

    2. Connect your device to the host through the UART port.

    3. Run the host and write the license to the module.

    4. The version and name of the firmware written to the module must be the same as that of the firmware you upload to the Tuya IoT Platform.

      When you use Cloud Module Burning Authorization Platform to authorize modules, make sure to set both use_ext_license_key and device_id_len to 0.

Should I write the MAC address in the license to the module?

Yes. Currently, the module written with a custom MAC address can also work properly, but in the future, Tuya will use the MAC address it issued to manage the connected Bluetooth device.

What is the h_id in Tuya Bluetooth SDK?

h_id is used for device management in the SDK. You can leave it as is.

How does data reporting and sending work?

For more information, see Application Development.

How to specify advertising and connection intervals?

Tuya Bluetooth SDK does not provide interval configuration. You should specify interval parameters for your application based on product features and performance.

For connection to iOS devices, there are certain rules and formulae that the parameters must follow. If the parameters do not comply with all of these rules, the parameter request may be rejected, or the stability and the performance of the connection may be compromised. Make sure the advertising intervals do not exceed one second. Otherwise, the Bluetooth device might not be discovered by iOS devices.

  • Interval Min ≥ 15 ms (multiples of 15 ms)
  • Interval Min + 15 ms ≤ Interval Max (Interval Max == 15 ms is allowed)
  • Interval Max * (Slave Latency + 1) ≤ 2 seconds
  • Interval Max * (Slave Latency + 1) * 3 < connSupervisionTimeout
  • Slave Latency ≤ 30
  • 2 seconds ≤ connSupervisionTimeout ≤ 6 seconds

Does Tuya provide bootloader?

  • If your Bluetooth chip model is supported by Tuya’s SDK, then corresponding bootloader examples will be included in the development materials.
  • Otherwise, you need to port Tuya Bluetooth SDK and write a bootloader and code for the OTA firmware update. Make sure to consider firmware verification to prevent writing unrecognized firmware.
    • The baseline SDK is included in the folder tuya_ble_sdk. It implements the communication between Tuya IoT devices and the Tuya Smart app and task scheduling, with a cross-platform feature.
    • The chip platform SDK is included in the folder tuya-ble-sdk-demo-project-xxxx (xxxx refers to platforms). The platform SDKs are built on top of the baseline SDK, and have implemented functions such as OTA updates, power saving, and authorization, and provide a complete set of proven programs to test serial communication as well as common application routines for your reference.

Why can’t my device be found by the mobile app?

  1. Make sure you have ported the SDK and check if Tuya Bluetooth SDK works properly. For more information, see Port SDK.
  2. Make sure you have entered the correct authorization information and PID. For more information, see Initialize Tuya Bluetooth SDK.
  3. Make sure the Bluetooth advertisement works properly and the device is not bound. For more information, see Bluetooth pairing.

How does Tuya Bluetooth SDK affect power consumption?

Tuya Bluetooth SDK does not affect the power consumption pattern of the Bluetooth chip. Make sure you have correctly port the SDK according to Port SDK and check the power consumption related code.

Factors that affect power consumption can be:

  • The status of low power mode
  • The status of peripherals in low power mode
  • Bluetooth advertising intervals
  • Bluetooth connection intervals

View the chip datasheet to find out what might cause power consumption to be high.